24
5
There was a challenge to convert a number to its numeral in English, but that was too straightforward. Given a number 0–100, your task is to output the corresponding numeral in French. The French numeral system has a more complex logic behind it compared to the English one:
Number Numeral --------------- 0 zéro (note the accent) 1 un 2 deux 3 trois 4 quatre 5 cinq 6 six 7 sept 8 huit 9 neuf 10 dix 11 onze 12 douze 13 treize 14 quatorze 15 quinze 16 seize 17 dix-sept (literally ten seven) 18 dix-huit 19 dix-neuf 20 vingt 21 vingt et un (no hyphens) 22 vingt-deux ... 30 trente ... 40 quarante ... 50 cinquante ... 60 soixante ... 70 soixante-dix (literally sixty ten) 71 soixante et onze ... 80 quatre-vingts (note the s; literally four twenties) 81 quatre-vingt-un (note the hyphens) ... 90 quatre-vingt-dix 91 quatre-vingt-onze ... 99 quatre-vingt-dix-neuf (4*20+10+9) 100 cent
For a complete list, follow http://quizlet.com/996950/ (http://www.webcitation.org/6RNppaJx0).
Further rules/explanations
- There will always be a hyphen between words EXCEPT when the number ends in 1.
- When the number ends in 1, the word et (meaning and) is added before the un or onze. (31 = trente et un)
- However, 81 and 91 are formatted the same as the other numbers. (81 = quatre-vingt-un)
- At 60, the system switches from base 10 to base 20.
- There are some minor discrepancies across the web about this; refer to the list linked above for questions.
- Loopholes that are forbidden by default are not allowed.
- Using an external source such as a website, as well as any libraries, APIs, functions, or the like that convert numbers to numerals or translate to French are not allowed.
- This is code-golf, so the answer with the fewest bytes wins.
- If available, please link to an online compiler to allow for easy testing of your code.
Input
- Input shall be taken from however your language takes input. (STDIN, command line, etc.)
- Input will be a single string, consisting of a whole number between 0 and 100 inclusive (leading zeroes optional).
- You can assume the input will always be well-formed.
Output
- The result shall be output to the most convenient method for your language. (STDOUT, dialog box, etc.)
- Case does not matter in the output.
Examples
Test your code against these:
Input Output ------------- 0 zéro 18 dix-huit 51 cinquante et un 80 quatre-vingts 91 quatre-vingt-onze 99 quatre-vingt-dix-neuf
1@Mig It's base 20. Very logical. – Conor O'Brien – 2015-12-14T22:06:23.313
3Note that french speaking Belgians use "septante", "octante" and "nonante" instead of soixante-dix, quatre-vingts, quatre-vingt-dix. It should be used to in the ancient Belgian colony. – Emmanuel – 2014-07-31T09:16:03.280
8+1 for the genius of doing this in French. As a German colleague of mine said: "Germans say the numbers backwards. But to understand the French, you need a calculator." – Level River St – 2014-07-31T12:28:48.190
1It looks like zéro is the only accented number in the range 0-100. This is not a standard ASCII character. I assume any format (code page 437, UTF-8, etc) that can output this character is acceptable. – Level River St – 2014-07-31T12:36:08.817
1@Martin The rules state "You can assume the input will always be well-formed," so input > 100 can result in any behavior. – NinjaBearMonkey – 2014-07-31T14:39:05.913
3There is absolutely no logic behind the french system. I'm sure there is a mistake in 99% of the french checks, this is even more complicated after 100. The conjugaison is also a nightmare. Trust me, I'm french. – Michael M. – 2014-07-31T18:05:51.410