Introduction:
When saying numbers out loud, the order is slightly different in Dutch than in English. For a number like \$1234\$:
- in English you'd say: one thousand, two hundred and thirty-four
- in Dutch you'd say: duizend-tweehonderdenvierendertig, or more readable with spaces: duizend twee honderd en vier en dertig [literally translated to: thousand two hundred and four and thirty]
Note two things in this example:
- How in English we have 'thirty-four', yet the order in Dutch is 'four and thirty'.
- How in English we have 'one thousand', yet in Dutch the 'one' is omitted for 'one hundred', 'one thousand', 'one million', etc.
Challenge:
Given a positive integer, convert its digits and digit order to the correct Dutch one and return it (as string/digit-list/etc., due to a potential leading \$0\$).
So with the example in the introduction above, with an input of 1234, you'd return "0243" (where the leading 0 is for the omitted 1 of 'one thousand' to simply 'duizend').
General formula:
- First split on the thousands from the back - if applicable (e.g.
1234567890to \$1\text{,}234\text{,}567\text{,}890\$, but inputs1,12,123, etc. are already a single group). - Then for every group of two or three digits, swap the last two, except for:
- If the last two digits as number are in the range \$[00,19]\$
- If the last digit is a \$0\$, aka the last two digits are one of: \$[20,30,40,50,60,70,80,90]\$
- If the very first digit of a group is a \$1\$, it'll sometimes becomes a \$0\$. This depends on whether it's:
- The only one in a group after splitting on the thousands (e.g.
1234, which is \$1\text{,}234\$ with thousand separators, becomes"0243", but12345, which is \$12\text{,}345\$ with thousand separators becomes12354). - In the Dutch language, and therefore in extension this challenge,
100is also a separated group (e.g.100becomes000;123456(\$123\text{,}456\$) becomes"032465", etc.) - (Note that
1and10won't change, despite having a1as first digit in their own 'group'. This in extension also means101maps to"001", not"000"(also applies within groups - e.g.101010with thousand groups \$101\text{,}010\$ becomes"001010".)
- The only one in a group after splitting on the thousands (e.g.
(Optional 4. Note that leading 0s within a group are ignored for this sub-rule - with the exception of 'één'. E.g. 1001001 split on the thousands is \$1\text{,}001\text{,}001\$, which would result in "0000001". Again, this is optional, since I forgot about this edge case and it would break almost all existing answers.. So outputting "0001001" instead is ok.)
Challenge rules:
- We only care about the digits/numbers, so the differences in
and(e.g.205being 'two hundred and five' in English versus 'tweehonderdvijf' [two hundred five] in Dutch) is irrelevant for this challenge. - The numbers in the range \$[13,19]\$ (thirteen-nineteen in English or dertien-negentien in Dutch) are already incorrect in English (e.g. 19 = ninete(e)n instead of te(e)nnine), so those are kept as is when converting to the Dutch order as well. Keeping the order unchanged applies to range \$[1,12]\$ (one-twelve in English or één-twaalf in Dutch) as well.
- I/O is flexible, so may be a string, digit-array/list/stream, etc. If you take the input as string, you may not take it formatted with thousand separators already in place.
- There can be overlap in outputs for multiple inputs. E.g.
19(negentien - nineteen) and91(éénennegentig - one and ninety) will both result in the output19. - The input will always be positive, so no need to work for negative values as well (or
0).
General Rules:
- This is code-golf, so the shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language. - Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code (e.g. TIO or ATO).
- Also, adding an explanation for your answer is highly recommended.
Test Cases:
Input: Output:
1 1 [één]
10 10 [tien]
19 19 [negentien]
91 19 [éénennegentig]
100 000 [honderd]
123 032 [honderdtweeëndertig]
1101 0001 [duizend-honderdéén]
1234 0243 [duizend-tweehonderdenvierendertig]
10101 10001 [tienduizend-honderdéén]
12678 12687 [twaalfduizend-zeshonderdzevenentachtig]
21876 12867 [éénentwintigduizend-achthonderdzesenzeventig]
101010 001010 [honderdéénduizend-tien]
123456 032465 [honderddrieëntwintig-vierhonderdzesenvijftig]
223344 232344 [tweehonderddrieëntwintigduizend-driehonderdvierenveertig]
1234567890 0243576890 [miljard-tweehonderddrieënveertigmiljoen-vijfhonderdenzevenenzestigduizend-achthonderdnegentig]
Here the first 100 values:
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
12,22,32,42,52,62,72,82,92,30,13,23,33,43,53,63,73,83,93,40,
14,24,34,44,54,64,74,84,94,50,15,25,35,45,55,65,75,85,95,60,
16,26,36,46,56,66,76,86,96,70,17,27,37,47,57,67,77,87,97,80,
18,28,38,48,58,68,78,88,98,90,19,29,39,49,59,69,79,89,99,000]
Optional test case:
1001001 0000001 [miljoen-duizend-één]
(Outputting 0001001 is fine as well, since it's an edge case I forgot about when I made the challenge, and apparently almost every existing answer breaks for it..)

101010and1001001? \$\endgroup\$001010? \$\endgroup\$001010(honderéénduizend-tien : hundred one thousand - ten). And the second one is0000001(miljoen-duizend-één : million - thousand - one). \$\endgroup\$1001001wasn't covered by my general formula and breaks all existing answers (except for Arnauld's apparently), I've added it as an optional test case instead. Outputting0001001, even though it's technically not correct, is fine for the challenge.. \$\endgroup\$101010instead, thus the question ;-) \$\endgroup\$