Last active
May 11, 2023 19:23
-
-
Save simonbroggi/9f142c82c6fdfa9586d76a7be8bbf160 to your computer and use it in GitHub Desktop.
Inkles ink script to print a number translated to german.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=== function zahl_schreiben(x) | |
~zahl_schreiben_rec(x, true, true, true) | |
=== function zahl_schreiben_rec(x, start, kurz_einhundert, hundert_und1_bis_12) | |
~ x = INT(x) // cast to an int, since this function can only handle ints! | |
{ | |
- x >= 1000000: | |
~ temp k = x mod 1000000 | |
~ temp millionen = (x - k) / 1000000 | |
{ | |
- start && millionen >= 2: | |
{zahl_schreiben_rec(millionen, start, kurz_einhundert, hundert_und1_bis_12)} Millionen | |
- else: | |
eine Million | |
} | |
{ k > 0:{k < 100:<> und|{x mod 100 != 0:<>,}} {zahl_schreiben_rec(k, false, kurz_einhundert, hundert_und1_bis_12)}} | |
- x >= 1000: | |
~ temp y = x mod 1000 | |
~ temp tausender = (x - y) / 1000 | |
{tausender >= 2:{zahl_schreiben_rec(tausender, start, kurz_einhundert, hundert_und1_bis_12)}}tausend{ y > 0:{zahl_schreiben_rec(y, false, kurz_einhundert, hundert_und1_bis_12)}} | |
- x >= 100: | |
~ temp z = x mod 100 | |
~ temp hunderter = (x - z) / 100 | |
{ | |
- hunderter >= 2: | |
{zahl_schreiben_rec(hunderter, start, kurz_einhundert, hundert_und1_bis_12)}hundert | |
- start: | |
{kurz_einhundert==false:ein}hundert | |
-else: | |
einhundert | |
} | |
{z > 0:<>{z>=1&&z<=12&&hundert_und1_bis_12:und}{zahl_schreiben_rec(z, false, kurz_einhundert, hundert_und1_bis_12)}} | |
- x == 0: | |
null | |
- x < 0: | |
minus {zahl_schreiben_rec(-1 * x, start, kurz_einhundert, hundert_und1_bis_12)} | |
- else: | |
{ x < 10 || x > 20: | |
{ x mod 10: | |
- 1: {x > 1:ein|eins} | |
- 2: zwei | |
- 3: drei | |
- 4: vier | |
- 5: fünf | |
- 6: sechs | |
- 7: sieben | |
- 8: acht | |
- 9: neun | |
} | |
- else: | |
{ x: | |
- 10: zehn | |
- 11: elf | |
- 12: zwölf | |
- 13: dreizehn | |
- 14: vierzehn | |
- 15: fünfzehn | |
- 16: sechzehn | |
- 17: siebzehn | |
- 18: achtzehn | |
- 19: neunzehn | |
} | |
} | |
{ x >= 20: | |
{ x mod 10 > 0: | |
<>und<> | |
} | |
{ x / 10: | |
- 2: zwanzig | |
- 3: dreissig | |
- 4: vierzig | |
- 5: fünfzig | |
- 6: sechzig | |
- 7: siebzig | |
- 8: achzig | |
- 9: neunzig | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INCLUDE zahl_schreiben.ink | |
-> test_zahlen_schreiben(0, 28, 3) -> | |
-> test_zahlen_schreiben(99, 104, 1) -> | |
-> test_zahlen_schreiben(142, 156, 4) -> | |
-> test_zahlen_schreiben(242, 333, 7) -> | |
-> test_zahlen_schreiben(598, 618, 3) -> | |
-> test_zahlen_schreiben(999997, 1000003, 1) -> | |
-> test_zahlen_schreiben(1000108, 1000113, 1) -> | |
=== test_zahlen_schreiben(von, bis, step) | |
~temp zahl = von | |
-(loop) | |
{zahl} : {zahl_schreiben(zahl)} | |
~zahl = zahl + step | |
{zahl < bis: ->loop} | |
->-> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment