Skip to content

Instantly share code, notes, and snippets.

@lifthrasiir
Created July 10, 2011 19:04
Show Gist options
  • Save lifthrasiir/1074852 to your computer and use it in GitHub Desktop.
Save lifthrasiir/1074852 to your computer and use it in GitHub Desktop.
A little program that converts "a hundred" to "100". (Updated!)
These little programs read a spelt (EDIT: it is not "spoken") number from the
standard input and write the corresponding number to the standard output. Weigh
just 243 bytes and 227 bytes of C. (EDIT: was originally 256 and 240 bytes.)
The longer version handles numbers up to 999,999,999,999,999, that is, just
shy of 1,000 trillions. The shorter version handles numbers up to 19,999,999,
or 999,999,999 if your "int" is 64 bits 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.
These programs are written by Kang Seonghoon <[email protected]>, and put
in the public domain. The detailed explanation of them can be found at:
http://j.mearie.org/post/7462182919/spelt-number-to-decimal
long long n,u,m,b;main(e,r){for(;n++||(e=getchar()|32)>=0;b=
"ynwtsflrabg"[n%=11]-e?b:b*8+n)for(r=b%64-25;e<47&&b;b/=8)fo\
r(n=19;n;"1+DIY/.K430x9G(kC["[n]-42&255^b||(m+=n>15?n:n>9?m%
u*~-u:~r?n+!r*16:n*16,b=0))u=1ll<<6177%n--*4;printf("%llx",m
);}
n,u,m,b;main(e,r){for(;n++||(e=getchar()|32)>=0;b="yntfgwslr\
a"[n%=10]-e?b:b*9+n)for(r=b%81-19;e<47&&b;b/=9)for(n=17;n;"2\
+ADM-0a.4|1C;=j"[n]-42&255^b||(m+=n>13?n+2:n>9?m%u*~-u:~r?n+
!r*16:n*16,b=0))u=1<<198%n--*4;printf("%x",m);}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment