Objective
Given apositive integer, spell it out in the conlang I made.
Specification
Let\$n\$ be the inputted integer.\$n\$ shall be spelled out in the following specification.The entire spelling is case sensitive.
With the decimal expansion of\$n\$, letd be the least significant nonzero digit of\$n\$.
First,d shall be spelled out like this:
1 =
Qun2 =
Pis3 =
Tel4 =
Kal5 =
Pan6 =
Soh7 =
Set8 =
Qok9 =
Nof
Second, an appropriate suffix (or a "particle" in linguistic sense?) will immediately follow. This is judged by two boolean conditions: (A) Whetherd has any trailing zeros, and (B) whetherd isnot the only nonzero digit.
If neither holds, the suffix shall be
em.If only (A) holds, the suffix shall be
eh.If only (B) holds, the suffix shall be
at.If both hold, the suffix shall be
om.
Third, if (A) held, the length of the trailing zeros shall be spelled out recursively.
Finally, if (B) held,d and the trailing zeros shall be stripped off, and the remaining digits shall be spelled out recursively.
All words shall be intercalated by a single ASCII 0x20 whitespace.
Examples
1 =
Qunem2 =
Pisem7 =
Setem10 =
Quneh Qunem11 =
Qunat Qunem12 =
Pisat Qunem19 =
Nofat Qunem20 =
Piseh Qunem42 =
Pisat Kalem69 =
Nofat Sohem100 =
Quneh Pisem109 =
Nofat Quneh Qunem440 =
Kalom Qunem Kalem666 =
Sohat Sohat Sohem1945 =
Panat Kalat Nofat Qunem2000 =
Piseh Telem2022 =
Pisat Pisat Piseh Qunem44100 =
Qunom Pisem Kalat Kalem144000 =
Kalom Telem Kalat Qunem\$10^{60}\$ =
Quneh Soheh Qunem\$10^{63}\$ =
Quneh Telat Sohem
Rules
I/O format is flexible. Standard loopholes apply.
As for input, those that are not positive integers fall indon't care situation.
As for output, trailing whitespaces are permitted, but leading whitespaces are not.
Ungolfed solution
Haskell
import Data.Listimport Numeric.NaturalspellNDos :: Natural -> StringspellNDos 0 = ""spellNDos n = go (reverse (show n)) where go "" = "" go str = let (zeros, digit:remaining) = partition ('0'==) str digitSpell = case digit of '1' -> "Qun" '2' -> "Pis" '3' -> "Tel" '4' -> "Kal" '5' -> "Pan" '6' -> "Soh" '7' -> "Set" '8' -> "Qok" _ -> "Nof" suffix = case (null zeros, null remaining) of (False, False) -> "om " (False, _ ) -> "eh " (_ , False) -> "at " _ -> "em " in digitSpell ++ suffix ++ spellNDos (genericLength zeros) ++ go remaining- 1\$\begingroup\$"d is not the only nonzero digit." This is a bit unclear to me, can someone explain what it means?\$\endgroup\$oeuf– oeuf2022-04-25 13:59:26 +00:00CommentedApr 25, 2022 at 13:59
- \$\begingroup\$@oeuf Because zeroes don't have their own word, and so only 1-9 count as "digits" - if a number is
x00orx00000then itis the only nonzero digit (= the last digit), if it'sxyzorx0yz0ory00z,zis the last,x,yare not the last\$\endgroup\$ASCII-only– ASCII-only2022-04-26 02:52:24 +00:00CommentedApr 26, 2022 at 2:52
5 Answers5
Python 3.8 (pre-release), 172 bytes
f=lambda n:(d:=n.strip('0'))and' QPTKPSSQNuieaaoeoonsllnhtkf'[int(l:=d[-1])::9]+'eeaomhtm'[(t:=n!=d)+1%len(d)*2::4]+(' '+f(str(N:=n[::-1].find(l))).strip())*t+' '+f(n[:~N])Straightforward implementation of the specification.
Input a string. Makes use of string indexing and various other tricks to simplify finding the least significant digit and removing digits. This makes the task much easier to accomplish because with numbers, one would have to perform messy tasks such as dividing by powers of 10 or using the% operator to "index into the number", and because of this difficulty it is golfier to convert the number to a string then perform some indexing. Then I thought, "Why not just use a string for the input?" and the code was thus shortened by 25 bytes, maybe more.
Thanks @ovs for -2 bytes.
Charcoal, 86 bytes
⊞υNWυ«≔⊟υι¿ι«≔⌕⮌÷¹⊕↨ιχ⁰θ≧÷Xχθι§⪪”↶0OP⊘ηS℅ê*k⮌⁰nI¿'⊗ξ!»NV”³ι≧÷χι⊞υι⊞υθ¿θ¿ιom¦eh¿ιat¦em→Try it online! Link is to verbose version of code. Explanation:
⊞υNWυ«Start processing with the input value.
≔⊟υι¿ι«If the current value to process is zero then ignore it and continue on to the next value.
≔⌕⮌÷¹⊕↨ιχ⁰θ≧÷XχθιFind the number of trailing zeros in the current value and remove them.
§⪪”↶0OP⊘ηS℅ê*k⮌⁰nI¿'⊗ξ!»NV”³ιOutput the prefix corresponding to the last nonzero digit.
≧÷χιDivide the value by10 again.
⊞υι⊞υθPush the final value and the number of trailing zeros to the list so that they get processed.
¿θ¿ιom¦eh¿ιat¦em→Output the appropriate suffix and allow a space before any other output.
05AB1E, 72bytes
"SDĀÅ¡¦ηRεDg≠UθćsgV.•¿Õ¾¸”mÚÄú±pE”¿м∍•3ôsè™.•DĀ€y‹•2ôYĀX«Cè«Y®.V‚"©.V˜ðýTry it online orverify all test cases.
Explanation:
"..." # Push the recursive string explained below © # Store it in variable `®` (without popping) .V # Execute it as 05AB1E code ˜ # Flatten the resulting list ðý # Join this list with space delimiter) # (after which the result is output implicitly)S # Convert the current value to a list of digits # (which will be the implicit input in the first iteration) D # Duplicate this list of digits Ā # Check for each digit if it's non-0 Å¡ # Split the list of digits at the truthy (non-0) indices ¦ # Remove the leading empty list # (e.g. "20230050" → [[2,0],[2],[3,0,0],[5,0]])η # Get the prefixes of this list R # Reverse it ε # Map over each prefix-list: D # Duplicate the current list of lists g # Pop the copy, and push its length ≠ # Check that this length is NOT 1 U # Pop and store this in variable `X` θ # Pop and push the final digit-list from the current prefix ć # Extract head; pop and push first item and remainder-list # separately s # Swap so the remainder-list of 0s is at the top g # Pop and push its length (to get the amount of 0s) V # Pop and store this in variable `Y` .•¿Õ¾¸”mÚÄú±pE”¿м∍• # Push compressed string "nofqunpistelkalpansohsetqok" 3ô # Split it into parts of size 3 s # Swap so the extracted head is at the top è # (Modular 0-based) index it into the list of triplets ™ # Titlecase it .•DĀ€y‹• # Push compressed string "ematehom" 2ô # Split it into parts of size 2 YĀ # Push `Y` (amount of 0s), and check if it's NOT 0 X« # Append `X` (prefix_length != 1) C # Convert it from binary to an integer # (0 if X=0,Y=0; 1 if X=0,Y=1, 2 if X=1,Y=0, 3 if X=1,Y=1) è # Index that into the list of pairs « # Append the two strings together Y # Push `Y` (amount of 0s) again ®.V # Do a recursive call with this as argument ‚ # Pair the result together with the stringSee this 05AB1E tip of mine (sectionHow to compress strings not part of the dictionary?) to understand why.•¿Õ¾¸”mÚÄú±pE”¿м∍• is"nofqunpistelkalpansohsetqok" and.•DĀ€y‹• is"ematehom".
JavaScript (ES6), 148 145 144 bytes
Expects the input integer as a string.
f=s=>x=s.replace(/[^0]0*/g,q=>s=b[+q[0]+3]+b[!s+2*!f(q.length-1+'')]+' '+x+s,s="",b="omehatemQunPisTelKalPanSohSetQokNof".match(/[A-Z]?../g))&&sHow?
We first extract all suffixes and prefixes from the string"omehatemQunPis...Nof" into the arrayb[], using the regular expression/[A-Z]?../g.
f = // f is a recursive function takings => // a string sx = // the final result is saved in xs.replace( // look for all digit groups consisting of /[^0]0*/g, // a non-zero digit followed by 0 to N zeros q => // for each such group q: s = // update s: b[ // append the prefix according to +q[0] + 3 // the leading non-zero digit ] + // b[ // append the suffix according to !s + // whether this is the leading group 2 * !f( // and whether there's at least one zero, q.length // which is deduced from the result of a - 1 // recursive call with the number of 0's + '' // coerced to a string ) // ] + // append: ' ' + // - a space x + // - the result of the recursive call s, // - the previous value of s s = "" // start with an empty string) // end of replace()&& s // return sJelly, 71 bytes
Dœṗ`ḊĖF€ṚµḢỊ;ȦḄị“ðỌÇƭḌ€h»s2¤ṭḢị“÷mƬ@wƇ75Ẉ⁸f0¦mḃ⁾æÑdṛƁ/.ⱮṾ»s3¤Ɗ,Lß$K⁸¡)KA full program that accepts a positive integer and prints the result
Try it online! Or see thetest-suite.
How?
Dœṗ`ḊĖF€ṚµḢỊ;ȦḄị“...»s2¤ṭḢị“...»s3¤Ɗ,Lß$K⁸¡)K - Main Link: positive integer, ND - decimal digits of N ` - use as both arguments of: œṗ - partition before truthy indices Ḋ - dequeue (remove leading empty list) Ė - enumerate (e.g. [a,b,c]->[[1,a],[2,a],[3,c]]) F€ - flatten each Ṛ - reverse µ ) - for each "Part": Ḣ - head (i.e. the original index) - Note: this removes it too Ị - is insignificant (i.e. are we dealing with the final d? = NOT B) Ȧ - any and all? (0 if any zeros else 1 = NOT A) ; - concatenate -> [NOT B, NOT A] Ḅ - from binary -> 2(NOT B)+(NOT A) ¤ - nilad followed by link(s) as a nilad: “...» - "atehemom" s2 - split into twos -> ["at","eh","em","om"] ị - index into -> appropriate suffix Ɗ - last three links as a monad - f( Ḣ - head -> d - Note: again, this removes it too ¤ - nilad followed by link(s) as a nilad: “...» - "QunPisTelKalPanSohSetQokNof" s3 - split into threes -> ["Qun","Pis","Tel","Kal","Pan","Soh","Set","Qok","Nof"] ị - index into -> appropriate prefix ṭ - tack -> [prefix,suffix] $ - last two links as a monad - f(Part): L - length (number of trailing zeros, since we've removed the index and d) ß - call this Link (the whole Main Link) , - pair -> [current, recursed] ¡ - repeat... ⁸ - ...times: chain's left argument - treated as True if we have zeros K - ...action: join with space characters K - join with space characters - implicit, smashing printExplore related questions
See similar questions with these tags.




