Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

tinychallenge of /prague/: the UNIX way of sending SMS

Name: Anonymous 2017-11-15 16:32

so, instead of being all talk and no action, let's ram some progs.

Background:

at work, I once had to create an ancient 7-bit packed PDU from an ASCII string. in doing that, I've noticed that my solution is fairly verbose and inelegant despite the fact that the task itself is quite simple. this might be because I'm an idiot.

I've also noticed that creating PDUs and passing them to a function is not the way of UNIX (or the way of a mental midget, depending on whomst'd've you ask): my function operated on binary data! who needs that when you have stdin and stdout?

Your task:

ASCII might be a 7-bit encoding but GSM-7 is 7-bitter!

you have to create a complete program in your language of choice (it has to have a free as in beer implementation available, and it should preferably not be a meme language that stack overflow golfers like to invent to game the rules) that takes ASCII (no need to handle EASCII, UTF-8 etc.; actually being hillariously incompatible with them would be a plus) string as input and converts it to the GSM 7-bit packed alphabet, as defined here: http://holman.id.au/apps/ipsms/default_alphabet.html

you can use 'USSD Entry/Display' on this site for testing: http://smstools3.kekekasvi.com/topic.php?id=288

Additional rules:

1. input must be taken from stdin and output must be printed to stdout.
2. the actual format of your output doesn't matter much as long as it's unambigous: for HAX MY ANUS on stdin, C82016D4CC8282CEEA3404 is accepted but so is 0xc8 0x20 0x16 0xd4 0xcc 0x82 0x82 0xce 0xea 0x34 0x04, yCAW1MyCgs7qNAQ= and just fucking printing the raw bytes (if your output format is not obvious, clarify it).
3. don't create PDUs or anything like that, just convert between alphabets; imagine it as just one part of a UNIXy SMS pipeline
4. if the language your using is not obvious (due to either obscurity or similarity to other languages), make sure to mention which one it is: you don't want your Hy submission to be rejected because it looked like Clojure but didn't work like Clojure. feel free to brag about your program being a polyglot.
5. shortest code in bytes of either source code or machine code (whichever is better - so feel free to use assembly) wins
6. all submissions until 2017-11-22 16:30 UTC will be counted. good submissions past that deadline but before results are announced might get an honorable mention.

Name: Cudder !cXCudderUE 2017-11-21 10:07

>>39
Right here.
#include <stdio.h>
#include <string.h>
int a,i=0;char x[]="$\x2@\x1[\xac<\xaf]\xbe^\x94_\x11{\xa8|\xc0}\xa9~\xbd",c;
e(int c){if(i){putchar(a|=c<<i--);a>>=8;}else{a=c;i=7;}}
main(){while((c=getchar())!=EOF){char*p;if(p=strchr(x,c)){if(*++p&128)e(27);
e(*p&127);}else{e(c);}}if(i==1)a|=26;putchar(a);if(!i&&a/2==13)putchar(13);}

Name: Anonymous 2017-11-21 10:31

>>41
looks good

Name: Anonymous 2017-11-21 22:02

>>41
main()
ya ain't read da standard

Name: Anonymous 2017-11-22 7:11

>>43
code golf challenges aren't about da standard, they often exploit implementation-specific shit, undefined behavior and my dubs

Name: Anonymous 2017-11-22 7:16

>>43
That's C89.

Name: Anonymous 2017-11-22 10:14

py3, significantly longer than >>11 (and slightly shorter than >>41, but it's a given with py vs C) but it should handle all ASCII. might be possible to reduce size further but I'm out of ideas. output is binary digits, divided by newlines into octets

a=0x1b;b={'@':0,'$':2,'\n':10,'_':17};c={'\f':[a,10],'^':[a,20],'{':[a,40],'}':[a,41],'\\':[a,47],'[':[a,60],'~':[a,61],']':[a,62],'|':[a,64]};d="";e=[y for x in input() for y in (c[x] if x in c else [b[x]] if x in b else [ord(x)])]
for x in e:d+=format(x,'07b')[::-1]
for i in range(0,len(d),8):print(d[i:i+8][::-1])

Name: Cudder !cXCudderUE 2017-11-22 12:05

>>46
output is binary digits, divided by newlines into octets
That follows the rules, but still lame because the output isn't actually directly usable.

but it's a given with py vs C

...but I beat it anyway. Yours is 317 bytes, mine is 247 bytes:

int a,i;char x[]="$[¼\¯]¾^”_{¨|À}©~½`{@",c;e(int c){if(i)putchar(a|=c<<i--),a>>=8;else a=c,i=7;}main(){while((c=getchar())>0){char*p;if(p=strchr(x,c)){if(*++p&128)e(27);e(*p&127);}else e(c);}if(i==1)a|=26;putchar(a);if(!i&&a/2==13)putchar(13);}

Name: Anonymous 2017-11-22 12:17

>>47
as for the solution you posted goes, I'm not sure it really works:

$ gcc cudder_sms.c
cudder_sms.c:1:18: warning: unknown escape sequence: '\302' [enabled by default]
int a,i;char x[]="$[¼\¯]¾^”_{¨|À}©~½`{@",c;e(int c){if(i)putchar(a|=c<<i--),a>>=8;else a=c,i=7;}main(){while((c=getchar())>0){char*p;if(p=strchr(x,c)){if(*++p&128)e(27);e(*p&127);}else e(c);}if(i==1)a|=26;putchar(a);if(!i&&a/2==13)putchar(13);}
^
cudder_sms.c: In function ‘main’:
cudder_sms.c:1:149: warning: incompatible implicit declaration of built-in function ‘strchr’ [enabled by default]
int a,i;char x[]="$[¼\¯]¾^”_{¨|À}©~½`{@",c;e(int c){if(i)putchar(a|=c<<i--),a>>=8;else a=c,i=7;}main(){while((c=getchar())>0){char*p;if(p=strchr(x,c)){if(*++p&128)e(27);e(*p&127);}else e(c);}if(i==1)a|=26;putchar(a);if(!i&&a/2==13)putchar(13);}

$ ./a.out > lel
[$ xxd lel
0000000: 1b21 .!

correct me if I'm wrong but shouldn't the output for a single open bracket be 1b1e instead of 1b21?

Name: Cudder !cXCudderUE 2017-11-22 12:24

>>48
The encoding should be CP1252, which got fucked up somewhere along the way from the file to that post. The characters of the string constant in the source should be

24 02 5B BC 5C 5C AF 5D BE 5E 94 5F 11 7B A8 7C C0 7D A9 7E BD 60 7B 40

Name: Anonymous 2017-11-22 12:34

>>49
$ gcc cudder_sms.c
cudder_sms.c: In function ‘main’:
cudder_sms.c:1:214: warning: incompatible implicit declaration of built-in function ‘strchr’ [enabled by default]
int a,i;char x[]="\x24\x02\x5b\xbc\x5c\x5c\xaf\x5d\xbe\x5e\x94\x5f\x11\x7b\xa8\x7c\xc0\x7d\xa9\x7e\xbd\x60\x7b\x40",c;e(int c){if(i)putchar(a|=c<<i--),a>>=8;else a=c,i=7;}main(){while((c=getchar())>0){char*p;if(p=strchr(x,c)){if(*++p&128)e(27);e(*p&127);}else e(c);}if(i==1)a|=26;putchar(a);if(!i&&a/2==13)putchar(13);}
^
$ ./a.out > lel
[$ xxd lel
0000000: 1b1e ..

looks good now

Name: Anonymous 2017-11-22 16:40

OFFICIAL RESULTS:

the winner is... Cudder! >>47

Congratulations on not being all talk an no action!

second place: >>46

third place: nobody because only Cudder and >>46-kun posted something that fits the requirements

Name: Anonymous 2017-11-22 19:45

I printed mine but the stupid paper doesn't want to weld together properly, so I couldn't send it.

Name: Anonymous 2017-11-22 22:12

Good job Cudder-kun!

Name: Anonymous 2017-11-23 7:43

it was fun. if anyone (Cudder? >>46-kun? >>9-kun? >>7-kun?) is interested, I'm going to make a new tinychallenge soon (maybe during the weekend?). this time the task would be a bit more complex so I'd give a bit longer submission period - but still nothing you won't be able to write in an hour or two.

Name: Anonymous 2017-11-23 14:20

>>54
it was fun
No it wasn't
This was a project euler tier problem that has no real life use

Name: Anonymous 2017-11-23 14:43

>>55
watch out, we have an ENTERPRISE programmer here!

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List