Convert a number to Korean
Aheui, 1555 bytes
살밦발따밝따빠따밦발다빠따다빠밞빠따받다빠따밝발따두
수터더떠벋벓떠뻐더벖떠뻐벍뻐터터떠벌벖떠뻐떠벋벎뻐더
방뺘우차빠발발다빠따빠뚜
우노여뗘뻐떠뻐더벌벌썪러
샦우싹어
아삳부
ㅇ아삭뺘우차빠불
ㅇ유어우여려더벌
ㅇ요ㅇ빠받반타탸우처삳뺘우처밝밤뚜
ㅇㅇ우쑨여텨여볋여뗘여뼈여뎌벅떠벓
ㅇ요아삭뺘우차삳빠박탸유처발불
ㅇㅇ우어ㅇ여따뱖볆뚜텨벎떠뻐떠
ㅇ요ㅇ우어쎤여뎌여별여어
ㅇㅇㅇ빠밤탸우처밣빠따밞다뿌
ㅇ요ㅇ우어쎤여뗘벎더떠벋벓떠
ㅇㅇㅇ빠밦탸우처밞밦따빠뚜
ㅇ뇨ㅇ숙어쎤여뗘벎떠벅터벖
ㅇㅇㅇ빠박탸우처밝밤따밣따북
ㅇ됴ㅇ우어썬여텨더벓벓떠뻐더
ㅇㅇㅇ빠받탸우처밣밝다빠따붇
ㅇ뵬ㅇ우어썬여뎌떠벍벓떠뻐터
ㅇㅇㅇ빠밤탸우처밣밝다빠따붇
ㅇ뵬ㅇ우어썬여뎌떠벌벓떠뻐터
ㅇㅇㅇ빠발탸우처밣밝다빠따뿌
ㅇ묘ㅇ우어썬여뎌떠벎더벌벖떠
ㅇㅇㅇ빠밦탸우처밣밝다빠따빠뚜
ㅇ쇽ㅇ우어썬여뎌떠벓더벓떠뻐벖
ㅇㅇㅇ빠밝탸우처밞밞따빠따붒
ㅇ됴ㅇ우어썬여뗘벓더더벍떠뻐
ㅇㅇㅇ빠밣탸우처발발따발따붒
ㅇ뵥ㅇ우어썬여뗘벎더범떠벓떠
ㅇㅇㅇ빠밟탸우처밝발따빠따붏
ㅇ숃어어어쎤여뎌벓떠벎떠범더
ㅇ마샬우싹샥우파뺘무차파쑨
ㅇㅇ오유여어유여ㅇ며ㅇㅇ우
오ㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇ어
우ㅇㅇ어ㅇㅇ어어
샨희맣어
Try it online! (trailing new line for input is necessary)
Why not?
Hours of coding, and another hours of packing and layouting. I think it can be golfed furthermore, but it already took so much effort. I really wanted to pack it into a rectangle.
Because 10^20 is larger than 2^64, not every implementation of Aheui will not support 경-scale numbers.
Luckily, Python and pyaheui implementation (which is used on TIO) uses much-larger precision numbers, so it can support not only 경, but more than 해, 자, 양, 구, 간, 정, 재, 극.
And my code can be easily extended to use more larger unit suffixes.
This code will not terminate on input 0
, but this spec was not defined in the question (which should output 영
).
Explanation-ish Unpacked Code
ㅣPush unit suffixes (만, 억, 조, 경) to stack ㄹ
ㅣ
술
밦발따밝따빠따밦발다우
우ㅡㅡㅡㅡㅡㅡㅡㅡㅡ어
빠따다빠밞빠따받다빠따밝발따다다우
우ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ어
빠밞받따빠따밦발따타타우
우ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ어
빠밝빠따밦다빠따밣받따다타우
우ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ어
ㅣ
ㅣGet input as number
ㅣ
사방우
우ㅡ어
ㅣ
ㅣSplit input by four digits
ㅣ
ㅣㅣIf input is zero, end the loop
아아뺘우차우
우ㅇㅡ어 ㅣ
ㅣㅣ우ㅡㅡ어
ㅣㅣㅣTake mod 10000 to stack ㄲ
ㅣㅣ빠발발다빠따빠따라싺우
ㅣㅣ우ㅡㅡㅡㅡㅡㅡㅡㅡㅡ어
ㅣㅣㅣDivide by 10000
ㅣㅣ발발다빠따빠따나우
ㅣ오ㅡㅡㅡㅡㅡㅡㅡㅡ어
ㅣ
ㅣReverse stack ㄲ to stack ㄱ
ㅣ
샦우싹어
우어
ㅣ
ㅣProcess four digits
ㅣ
아우ㅣUse ㄷ stack for index (0, 2, 4, 6)
ㅣ아삳바우
ㅣ우ㅡㅡ어
ㅣㅣ
ㅣㅣㅣConvert four digits into korean
ㅣ아아숙
ㅣㅣㅣㅣIf current multiplier is zero, escape
ㅣㅣㅣ뺘우차우
ㅣ우ㅇㅡ어 ㅣ
ㅣㅣㅣ우ㅡㅡ어
ㅣㅣㅣㅣTake mod 10
ㅣㅣㅣ빠발발다라우
ㅣㅣㅣ우ㅡㅡㅡㅡ어
ㅣㅣㅣㅣIf remainder - 1 is 0 (remainder is 1) and index is 0 (ones digit), push 일 on stack ㄴ
ㅣㅣㅣ빠받반타탸우처삳뺘우처밝밤따밣따박다빠따밣타싼우
ㅣㅣㅣ우ㅡㅡㅡㅡ어ㅡㅡㅡ어ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ어
ㅣㅣㅣㅣIf remainder is not 0
ㅣㅣㅣ삭뺘우차우
ㅣㅣㅣ우ㅡ어 ㅣ
ㅣㅣㅣㅣ우ㅡㅡ어
ㅣㅣㅣㅣ숟
ㅣㅣㅣㅣㅣIf index is [2, 4, 6], push [십, 백, 천] on stack ㄴ
ㅣㅣㅣㅣ빠박탸우처발발따빠따밞타밞따밞따발다싼우
ㅣㅣㅣㅣ우ㅡㅡ어ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ어
ㅣㅣㅣㅣ빠밤탸우처밣빠따밞다빠따밣받따다밞따싼우
ㅣㅣㅣㅣ우ㅡㅡ어ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ어
ㅣㅣㅣㅣ빠밦탸우처밞밦따빠따밦타박따밞따싼우
ㅣㅣㅣㅣ우ㅡㅡ어ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ어
ㅣㅣㅣㅣㅣ
ㅣㅣㅣㅣㅣIf remainder is [2 ... 9], push [이 ... 구] on stack ㄴ
ㅣㅣㅣㅣ숙
ㅣㅣㅣㅣ빠박탸우처밝밤따밣따박다빠따밣밣다타싼우
ㅣㅣㅣㅣ우ㅡㅡ어ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ어
ㅣㅣㅣㅣ빠받탸우처밣밝다빠따받타빠따밣밝따다싼우
ㅣㅣㅣㅣ우ㅡㅡ어ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ어
ㅣㅣㅣㅣ빠밤탸우처밣밝다빠따받타빠따밣발따다싼우
ㅣㅣㅣㅣ우ㅡㅡ어ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ어
ㅣㅣㅣㅣ빠발탸우처밣밝다빠따빠따밦발다밞따다싼우
ㅣㅣㅣㅣ우ㅡㅡ어ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ어
ㅣㅣㅣㅣ빠밦탸우처밣밝다빠따빠따밦빠따밣다밣따다싼우
ㅣㅣㅣㅣ우ㅡㅡ어ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ어
ㅣㅣㅣㅣ빠밝탸우처밞밞따빠따밦빠따밝다다밣따싼우
ㅣㅣㅣㅣ우ㅡㅡ어ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ어
ㅣㅣㅣㅣ빠밣탸우처발발따발따밦따밣따밤다밞따싼우
ㅣㅣㅣㅣ우ㅡㅡ어ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ어
ㅣㅣㅣㅣ빠밟탸우처밝발따빠따밣다밤따밞따밣다싼우
ㅣㅣㅣ우ㅡㅡㅡ어ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ어
ㅣㅣㅣㅣ
ㅣㅣㅣㅣIncrease index, move onto next digit
ㅣㅣㅣ삳박다삭마발발다나우
ㅣㅣ오ㅡㅡㅡㅡㅡㅡㅡㅡㅡ어
ㅣㅣ
ㅣㅣㅣPop zero
ㅣ아무
ㅣㅣㅣ
ㅣㅣㅣㅣMove one suffix to stack ㄱ
ㅣㅣㅣㅣIf all suffix has been used, escape
ㅣㅣ아샬우싹삭우
ㅣ우ㅇㅡ어 ㅣ
ㅣㅣㅣ우ㅡㅡㅡ어
ㅣㅣㅣㅣIf next multiplier is zero, discard next multiplier and suffix, then check next
ㅣㅣㅣㅣIf next multipler is not zero, move suffix to stack ㄴ and continue
ㅣㅣㅣㅣIf all multiplier has been processed, escape
ㅣㅣㅣ야우파뺘우차파싼우
오ㅇㅇㅡㅇㅡㅡㅇㅡㅡㅡ어
우어ㅇㅡ어ㅡㅡㅣ
ㅣㅡ오ㅡㅡ머머어
샨희맣어
Retina 0.8.2, 147 bytes
^
0경0조0억0만
\G0?\D?
0천0백0십$&
+`0(\D)(\d+)(\d)
$2$1$3
0(천0백0십0.?|천|백|십)
1(천|백|십)
$1
T`d`_일이삼사오육칠팔구
Try it online! Link includes test cases. Explanation:
^
0경0조0억0만
Insert the symbols for powers of 10,000.
\G0?\D?
0천0백0십$&
Insert the thousands, hundreds and tens symbols.
+`0(\D)(\d+)(\d)
$2$1$3
Replace the zeros between the symbols with the input digits.
0(천0백0십0.?|천|백|십)
Delete zero thousands, hundreds or tens, or a whole power of 10,000.
1(천|백|십)
$1
Delete the 1 of one thousand, one hundred or one ten.
T`d`_일이삼사오육칠팔구
Transliterate the remaining digits, deleting any remaining zeros.
Jelly, 96 95 94 92 bytes
“Ŀ|ĿtĊỴĊḄİ$Ŀ!Ṫ`ạÞḌlĖḣỴ1ṘƈỤṘḢỌṀpḄẒ‘s2ḅ⁹Ọ
bȷ4DUµż“¢½¿€‘ṁ$Ṛœl€1P€0¦ẠÐfFµ€Ṛµ;"“¡ÆÇÐÑ‘ṚL’$ÐfFḟ0ị¢
A monadic link taking a positive integer and returning a list of characters.
Try it online! or see a test-suite (numbers referenced in the OP)
...or see assertion of the pastebin values here
How?
Constructs the parts-characters required as indexes of the list:
[1,2,3,4,5,6,7,8,9,10,100,1000,10000,100000000,1000000000000,10000000000000000]
i.e.: 일이삼사오육칠팔구십백천만억조경
and indexes into the list. Thus 30210
would become [3,13,2,11,10]
and then 삼만이백십
“Ŀ|ĿtĊỴĊḄİ$Ŀ!Ṫ`ạÞḌlĖḣỴ1ṘƈỤṘḢỌṀpḄẒ‘s2ḅ⁹Ọ - Link 1, get part-characters: no arguments
“Ŀ|ĿtĊỴĊḄİ$Ŀ!Ṫ`ạÞḌlĖḣỴ1ṘƈỤṘḢỌṀpḄẒ‘ - code-page indices = [199,124,199,116,192,188,192,172,198,36,199,33,206,96,211,20,173,108,194,237,188,49,204,156,185,204,197,181,200,112,172,189]
s2 - split into twos = [[199,124],[199,116],[192,188],[192,172],[198,36],[199,33],[206,96],[211,20],[173,108],[194,237],[188,49],[204,156],[185,204],[197,181],[200,112],[172,189]]
ḅ⁹ - convert from base 256 = [51068,51060,49340,49324,50724,50977,52832,54036,44396,49901,48177,52380,47564,50613,51312,44221]
Ọ - cast to characters = "일이삼사오육칠팔구십백천만억조경"
bȷ4DUµż“¢½¿€‘ṁ$Ṛœl€1P€0¦ẠÐfFµ€Ṛµ;"“¡ÆÇÐÑ‘ṚL’$ÐfFḟ0ị¢ - Main link: integer, n e.g. 102031
ȷ4 - 10^4 = 10000
b - convert (n) to base (10000) [10,2031]
D - convert (each) to base 10 [[1,0],[2,0,3,1]]
U - reverse each [[0,1],[1,3,0,2]]
µ µ€ - monadic chain for €ach:
$ - last two links as a monad:
“¢½¿€‘ - code-page indices = [1,10,11,12]
ṁ - mould like e.g. [1,10] or [1,10,11,12]
ż - zip [[0,1],[1,10]] or [[1,1],[3,10],[0,11],[2,12]]
Ṛ - reverse [[1,10],[0,1]] or [[2,12],[0,11],[3,10],[1,1]]
œl€1 - left-strip ones [[10],[0,1]] or [[2,12],[0,11],[3,10],[]]
P€0¦ - product @ index 0 [[10],0] or [[2,12],[0,11],[3,10],1] (Note: the empty product is 1)
ẠÐf - filter keep if any [[10]] or [[2,12],[3,10],1]
F - flatten [10] or [2,12,3,10,1]
Ṛ - reverse [[2,12,3,10,1],[10]]
µ - new monadic chain
“¡ÆÇÐÑ‘ - code-page indices = [0,13,14,15,16]
;" - zip with concatenation [[2,12,3,10,1,0],[10,13],14,15,16]
Ṛ - reverse [16,15,14,[10,13],[2,12,3,10,1,0]]
Ðf - filter keep if:
$ - last two links as a monad:
L - length 1 1 1 2 6
’ - decrement 0 0 0 1 5
- i.e. [[10,13],[2,12,3,10,1,0]]
- (This also removes any 0-sized 10K parts e.g. the [13] from 200001234 -> [16,15,[2,14],[13],[12,2,11,3,10,4,0]])
F - flatten [10,13,2,12,3,10,1,0]
ḟ0 - filter discard zeros [10,13,2,12,3,10,1] (Note: not there for multiples of 10000 so cann't simply pop with Ṗ)
¢ - call the last link as a nilad "일이삼사오육칠팔구십백천만억조경"
ị - index into "십만이천삼십일"