We have another challenge from MMMAAANNN on Codewars. Today, you are asked to:
Turn a given number (an integer > 0, < 1000) into the equivalent English words.
For example:wordify(1) == "one"
wordify(12) == "twelve"
wordify(17) == "seventeen"
wordify(56) == "fifty six"
wordify(90) == "ninety"
wordify(326) == "three hundred twenty six"
Good luck, and happy coding!
Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge for a future post? Email yo+challenge@dev.to with your suggestions!
Latest comments (11)
Iβm learning Erlang, and I got to use file I/O and a list comprehension for the unit tests (in the Gist version).
Short version:
In this Gist, thereβs a test file with all values from 1 to 999, and a EUnit test that loads this file and generates a test for each value.
Rust Solution!
Pretty hard coded. Probably could be made much more compact and general. But this satisfies the requirements!
Common Lisp is a good choice for this:
English is fun what with all the exceptions...
Gist: gist.github.com/kerrishotts/ea2bd9...
Try French. Iβll pass you the details of βquatre-vingt-dix-neufβ for 99, but you also have βvingt et unβ (21), βvingt deuxβ (22), βdeux centsβ (200, note the s) but βdeux cent unβ (201).
Here's a JS one that goes into the gazillions π€
In Perl, we have CPAN, where you can find modules for almost any task imaginable. Including Lingua::EN::Numbers.
I tried to not dictionary everything, but the exceptions are real. Lots of amusing output as I got closer, that I'll paste for your enjoyment. I did actually get it working though :P
JavaScript
Live demo on CodePen.
I would cheat and use google translate api xD