Spoken Number to Decimal

arachneng:

I certainly like a code obfuscation and golfing: the recent example includes this and this. The today’s project is more like the former, where very short code takes much time to explain. Without further ado, here it is:

long long u,v;main(a,b,c,d){for(b=c=0;c++||(a=getchar()|32)>46;b
=”ynwtsflrabg”[c]-a?b:b*8+c)c%=11;for(c=b%64-25;b;b/=8)for(d=19;
d;”1+DIY/.K430x9G(kC[“[d]-42&255^b||(v+=d>15?d:d>9?v%u*~-u:c+1?d
+!c*16:d*16,b=0))u=1ll«6177%d—*4;a<0?printf(“%llx”,v):main();}

This little program reads a spoken number from the standard input and writes the corresponding number to the standard output. It supports numbers up to 1015-1 and still weighs only 256 bytes of C. (There is also a shorter version that can handle up to 19,999,999 and does not use long long.) The input should be correct, although it will handle “a” and “and” correctly and ignore some invalid words.

It assumes the ASCII character set and 2’s complement representation, and requires int and long long to be at least 32 and 64 bits long, but that’s all they expect from the compiler. For example, it does not matter whether char is signed or unsigned, EOF does not have to be -1, and so on. (Yes, I did keep in mind while writing this program.)

While I left the explanation of the BF interpreter as a reader’s exercise, in this time I’ll give the detailed explanation of the program. Keep in mind that there are two versions of the program; the explanation is primarily for the longer version.

Read More

I can’t even begin to imagine how he came up with this code. This takes the name of a number and converts it to the number itself in 256 bytes of code. And it works all the way up to the hundred trillions. Amazing.

  1. nhmortgagebroker liked this
  2. mamortgageexpert liked this
  3. ctmortgagebroker liked this
  4. berkus liked this
  5. berkus reblogged this from arachneng
  6. noorim liked this
  7. zem liked this
  8. shibats reblogged this from arachneng
  9. feralstructures liked this
  10. feralstructures reblogged this from arachneng
  11. fraxtil reblogged this from arachneng and added:
    can’t even begin...hundred trillions. Amazing.
  12. arachneng posted this