0
\$\begingroup\$

This question already has an answer here:

I took inspiration from a challenge I did some years ago in a programming competition.

Your goal is to write a function that generates a random integer number between 0 and 150 (included), and then prints it in actual words. For example, 139 would be printed as onehundredthirtynine.

Rules:

  • You cannot use any external resource, nor any library that will perform the conversion.

  • The shortest answer will win.

Good luck!

\$\endgroup\$

marked as duplicate by manatwork, John Dvorak, ProgramFOX, Doorknob, Darren Stone Jan 2 '14 at 19:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ With or without spaces? \$\endgroup\$ – ProgramFOX Jan 2 '14 at 18:53
  • \$\begingroup\$ Without spaces, as you can see in the example! :) \$\endgroup\$ – Vereos Jan 2 '14 at 18:54
  • \$\begingroup\$ ... Damn, I actually searched for it. Didn't use proper keywords :/ \$\endgroup\$ – Vereos Jan 2 '14 at 18:57
  • 1
    \$\begingroup\$ Don't worry, neither I found it easily. (I knew another question which links to that one.) \$\endgroup\$ – manatwork Jan 2 '14 at 19:00
0
\$\begingroup\$

Lua

print"four"

Highly optimized and golfed xkcd's random number generator

An actual solution, 380

x=math.random(0,150)m=math.floor print(x==0 and"zero"or((x>99 and"onehundred"or"")..(({"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"})[x%100-9]or({[0]="",nil,"twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety"})[m(x/10)%10]..({[0]="","one","two","three","four","five","six","seven","eight","nine"})[x%10])))
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.