Convert number to words

Input: integer number from 1 to 999999999;
Output: spelling this number in English.

IN

13

OUT

thirteen

IN

6

OUT

six

IN

256

OUT

two hundred fifty six

IN

1024

OUT

one thousand twenty four

IN

123456789

OUT

one hundred twenty three million four hundred fifty six thousand seven hundred eighty nine

IN

54321

OUT

fifty four thousand three hundred twenty one
Login to submit solution


850 symbols python3 failed test 1 Code error

File "./code", line 19 elif len(S)==1 and !S: ^ SyntaxError: invalid syntax

Mon Aug 4 17:54:58 2014 vik
X={'1':'one','2':'two','3':'three','4':'four','5':'five','6':'six','7':'seven','8':'eight','9':'nine','10':'ten','11':'eleven','12':'twelve','13':'thirteen','14':'fourteen','15':'fifteen','16':'sixteen','17':'seventeen','18':'eighteen','19':'nineteen','20':'twenty','30':'thirty','40':'forty','50':'fifty','60':'sixty','70':'seventy','80':'eighty','90':'ninety'}
def N(n):
 h='hundred'
 S=str(n)
 if len(S)==3:
  if S[1:]=='00':
   return X[S[0]]+' '+h+' '
  else:
   rst=X[S[0]]+' '+h+' '
   n=int(S[1:])
   return rst+N(n)
 elif len(S)==2:
  if S in X:
   return X[S]
  else:
   j=str(S[0])+'0'
   rst=X[j]+' '
   return rst+N(n%10)
 elif len(S)==1 and !S:
  return X[S]
  return ''
def j(n):
 s=m=t=h=''
 i=1000
 h=N(n%i)
 n/=i
 t=N(n%i)
 n/=i
 if t:t+=' thousand '+h
 else: t=h
 m=N(n%i)
 n/=i
 if m:m+=' million '+t
 else:m=t
 print m
j(input())
24 symbols haskell failed test 1 Wrong answer
"13"
instead of
thirteen
Tue Aug 5 17:31:18 2014 nooodl
main=getContents>>=print
269 symbols perl failed test 1 Wrong answer
three thirteen two
instead of
thirteen
Sun Aug 24 11:20:38 2014 gabrielmad
#!/usr/bin/perl -p0
@x=reverse split//;%a=qw/1 one 2 two 3 three 4 four 5 thousand 6 six 7 seven 8 million 9 nine 13 thirteen 20 twenty 50 fifty 80 eigthy/;$_=join" ",reverse map{($_+1)%3==0&&$x[$_]?'hundred':$a{$_+2}//(),$a{($x[$_]+(!$_?$x[1]==1?10:0:0))*(($_-1)%3==0?10:1)}//()}0..$#x
269 symbols perl failed test 5 Wrong answer
one hundred twenty three million four hundred fifty six thousand seven hundred eigthy nine
instead of
one hundred twenty three million four hundred fifty six thousand seven hundred eighty nine
Sun Aug 24 11:22:06 2014 gabrielmad
#!/usr/bin/perl -p0
@x=reverse split//;$_=join" ",reverse map{($_+1)%3==0&&$x[$_]?'hundred':$_==3?'thousand':$_==6?'million':(),{qw/1 one 2 two 3 three 4 four 6 six 7 seven 9 nine 13 thirteen 20 twenty 50 fifty 80 eigthy/}->{($x[$_]+(!$_?$x[1]==1?10:0:0))*(($_-1)%3==0?10:1)}//()}0..$#x
240 symbols perl failed test 1 Wrong answer
three
instead of
thirteen
Mon Aug 25 00:19:29 2014 gabrielmad
#!/usr/bin/perl -p0
@x=split//;$_=join" ",map{$a=$x[$_];$_=$#x-$_;qw/hundred one two three four thousand six seven million nine thirteen eighty fifty twenty/[($_?$a?$_%3==1?$a>1?$a%4+11:0:$a:0:$x[$_+1]==1?10:$a)||(),(($_+1)%3==0&&$a?0:/3|6/?$_+2:())]}0..$#x
177 symbols perl failed test 1 Wrong answer
six
instead of
thirteen
Tue Oct 18 22:36:57 2016 Sait2000
#!/usr/bin/perl -pl
$s.=(million,thousand,hundred,three,four,six,seven,nine,thirteen,twenty,fifty,eighty,two,one)[hex$&].' 'while(d293042a5162b7,5,8,c2a5,d194,a41329d)[length%9]=~/./g;$_=$s;chop
135 symbols pyth failed test 1 Code error

Traceback (most recent call last): File "/usr/bin/pyth.py", line 676, in <module> py_code_line = general_parse(pyth_code) File "/usr/bin/pyth.py", line 39, in general_parse parsed, code = parse(code) File "/usr/bin/pyth.py", line 215, in parse return function_parse(active_char, rest_code) File "/usr/bin/pyth.py", line 309, in function_parse parsed, rest_code = parse(rest_code) File "/usr/bin/pyth.py", line 213, in parse return lambda_function_parse(active_char, rest_code) File "/usr/bin/pyth.py", line 294, in lambda_function_parse parsed, rest_code = parse(rest_code) File "/usr/bin/pyth.py", line 215, in parse return function_parse(active_char, rest_code) File "/usr/bin/pyth.py", line 309, in function_parse parsed, rest_code = parse(rest_code) File "/usr/bin/pyth.py", line 215, in parse return function_parse(active_char, rest_code) File "/usr/bin/pyth.py", line 309, in function_parse parsed, rest_code = parse(rest_code) File "/usr/bin/pyth.py", lin

Wed Oct 19 11:30:09 2016 Sait2000
jdm@c"hundred
one
million
twenty
four
six
seven
eighty nine
thirteen
three
fifty
two
thousand"bCd@cCMjim-CdC\가"튇뇥쉿콜봻귅몯까꾊쎞"^T4 15C13%lz9
138 symbols pyth failed test 1 Code error

Traceback (most recent call last): File "/usr/bin/pyth.py", line 713, in <module> exec(py_code_line, environment) File "<string>", line 2, in <module> File "/usr/bin/macros.py", line 680, in base_10 return to_base_ten(a, b) File "/usr/bin/macros.py", line 694, in to_base_ten acc += digit TypeError: unsupported operand type(s) for +=: 'int' and 'str'

Wed Oct 19 11:31:28 2016 Sait2000
jdm@c"hundred
one
million
twenty
four
six
seven
eighty nine
thirteen
three
fifty
two
thousand"bCd@cCMjim-CdC44032"튇뇥쉿콜봻귅몯까꾊쎞"^T4 15C13%lz9
137 symbols pyth failed test 1 Code error

Traceback (most recent call last): File "/usr/bin/macros.py", line 596, in Pchr return chr(a) ValueError: chr() arg not in range(0x110000) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/bin/pyth.py", line 713, in <module> exec(py_code_line, environment) File "<string>", line 2, in <module> File "/usr/bin/macros.py", line 753, in Pmap return list(map(a, b)) File "<string>", line 2, in <lambda> File "/usr/bin/macros.py", line 598, in Pchr return ''.join(chr(digit) for digit in from_base_ten(a, 256)) File "/usr/bin/macros.py", line 598, in <genexpr> return ''.join(chr(digit) for digit in from_base_ten(a, 256)) ValueError: chr() arg not in range(0x110000)

Wed Oct 19 11:31:56 2016 Sait2000
jdm@c"hundred
one
million
twenty
four
six
seven
eighty nine
thirteen
three
fifty
two
thousand"bCd@cCMjim-Cd44032"튇뇥쉿콜봻귅몯까꾊쎞"^T4 15C13%lz9
13 symbols pyth failed test 1 Wrong answer
30
instead of
thirteen
Wed Oct 19 11:36:31 2016 Sait2000
l"튇뇥쉿콜봻귅몯까꾊쎞"
20 symbols pyth failed test 1 Wrong answer
튇뇥쉿콜봻귅몯까꾊쎞
instead of
thirteen
Wed Oct 19 12:02:30 2016 Sait2000
v+\u++N"튇뇥쉿콜봻귅몯까꾊쎞"N
21 symbols pyth failed test 1 Wrong answer
30
instead of
thirteen
Wed Oct 19 12:03:02 2016 Sait2000
lv+\u++N"튇뇥쉿콜봻귅몯까꾊쎞"N
21 symbols pyth failed test 1 Wrong answer
'í\x8a\x87ë\x87¥ì\x89¿ì½\x9cë´»ê·\x85몯ê¹\x8cê¾\x8aì\x8e\x9e'
instead of
thirteen
Wed Oct 19 12:03:43 2016 Sait2000
`v+\u++N"튇뇥쉿콜봻귅몯까꾊쎞"N
20 symbols pyth failed test 1 Wrong answer
'u"í\x8a\x87ë\x87¥ì\x89¿ì½\x9cë´»ê·\x85몯ê¹\x8cê¾\x8aì\x8e\x9e"'
instead of
thirteen
Wed Oct 19 12:06:00 2016 Sait2000
`+\u++N"튇뇥쉿콜봻귅몯까꾊쎞"N
34 symbols pyth failed test 1 Code error

Traceback (most recent call last): File "/usr/bin/pyth.py", line 713, in <module> exec(py_code_line, environment) File "<string>", line 1, in <module> File "/usr/bin/macros.py", line 1022, in Punsafe_eval return eval(preprocess_eval(a)) File "<string>", line 1, in <module> AttributeError: 'str' object has no attribute 'decode'

Wed Oct 19 12:08:03 2016 Sait2000
`v+++N"튇뇥쉿콜봻귅몯까꾊쎞"N".decode('u8')"
18 symbols pyth failed test 1 Wrong answer
튇뇥쉿콜봻귅몯까꾊쎞
'í\x8a\x87ë\x87¥ì\x89¿ì½\x9cë´»ê·\x85몯ê¹\x8cê¾\x8aì\x8e\x9e'
30
instead of
thirteen
Wed Oct 19 12:13:47 2016 Sait2000
J"튇뇥쉿콜봻귅몯까꾊쎞"`JlJ
21 symbols pyth failed test 1 Wrong answer
튇뇥쉿콜봻귅몯까꾊쎞
'í\x8a\x87ë\x87¥ì\x89¿ì½\x9cë´»ê·\x85몯ê¹\x8cê¾\x8aì\x8e\x9e'
30
[237, 138, 135, 235, 135, 165, 236, 137, 191, 236, 189, 156, 235, 180, 187, 234, 183, 133, 235, 170, 175, 234, 185, 140, 234, 190, 138, 236, 142, 158]
instead of
thirteen
Wed Oct 19 12:14:41 2016 Sait2000
J"튇뇥쉿콜봻귅몯까꾊쎞"`JlJCMJ
41 symbols pyth failed test 1 Wrong answer
bytes([237, 138, 135, 235, 135, 165, 236, 137, 191, 236, 189, 156, 235, 180, 187, 234, 183, 133, 235, 170, 175, 234, 185, 140, 234, 190, 138, 236, 142, 158]).decode('u8')
instead of
thirteen
Wed Oct 19 12:20:06 2016 Sait2000
++"bytes("`CM"튇뇥쉿콜봻귅몯까꾊쎞"").decode('u8')"
42 symbols pyth failed test 1 Wrong answer
튇뇥쉿콜봻귅몯까꾊쎞
instead of
thirteen
Wed Oct 19 12:20:20 2016 Sait2000
v++"bytes("`CM"튇뇥쉿콜봻귅몯까꾊쎞"").decode('u8')"
46 symbols pyth failed test 1 Code error

Traceback (most recent call last): File "/usr/bin/pyth.py", line 713, in <module> exec(py_code_line, environment) File "<string>", line 1, in <module> File "/usr/bin/macros.py", line 678, in base_10 return int(a, b) ValueError: int() base must be >= 2 and <= 36

Wed Oct 19 12:21:22 2016 Sait2000
iv++"bytes("`CM"튇뇥쉿콜봻귅몯까꾊쎞"").decode('u8')"^T4

View all solutions