# Generate Aheui Number

Make a Number Expression is related : actually, it is also about Aheui. But it just made number expression, but this made real Aheui code.

Aheui is esolang written in only Korean character. Because of its nature, Aheui can't use Arabic numbers.

But, of course, there is way to generate number.

## Brief introduction to Aheui

Reading the link above is best, but put it shortly : Aheui is befunge-like esolang : have cursor, every character is instructor, and using stack.

One instructor, looks like 박, have three part : Initial consonantㅂ, vowelㅏ, final consonantㄱ.

First part, initial consonant, determine what to do.

Here is table of initial consonant that can be useful here:

• ㅇ : no operation.
• ㅎ : terminate.
• ㄷ : pop two number from current stack, than add them, and push to current stack.
• ㄸ : same as ㄷ, but multiply instead of add.
• ㄴ : pop two number from current stack, push second // first to current stack.
• ㅌ : same as ㄴ, but subtract instead of divide.
• ㄹ : same as ㄴ, but modulo instead of divide.
• ㅂ : push number to current stack. Number is given by final consonant.
• ㅃ : duplicate top of current stack.
• ㅍ : swap top two value of current stack.

Second part, vowel, determine momentum. Maybe you just need ㅏ, go to next.

Last part, final consonant, determine number to used in ㅂ commend.

Here is list of final consonant and number.

1. Nothing
2. ㄱ, ㄴ, ㅅ
3. ㄷ, ㅈ, ㅋ
4. ㅁ, ㅂ, ㅊ, ㅌ, ㅋ, ㄲ, ㄳ, ㅆ
5. ㄹ, ㄵ, ㄶ
6. ㅄ
7. ㄺ, ㄽ
8. ㅀ
9. ㄻ, ㄼ

Finally, 망 is printing operator. Your code have to print 망희 or 망하 or whatever after calculation, to print and terminate the program.

## Korean Character

Every Aheui instructor is Korean character.

As I mentioned above, Korean character has three part : Initial consonant(choseong or 초성), Vowel(jungseong or 중성), Final consonant(jongseong or 종성).

Every character has initial consonant and vowel, but final consonant is option.

Korean character in Unicode is from AC00(가) to D7A3(힣).

For composing Korean character, look at this webpage for help.

## Question

Input is an positive integer. Generate aheui code that prints given integer, without hardcode every possibility.

You can test your Aheui code at try it online.

## Examples

Input | Output | Discription
1 | 반밧나망희 | Put two 2s in stack, divide, print, and halt.
1 | 반반나망희 | Same as above.
1 | 밪반타망희 | Put 3 then 2 in stack, subtract, print, and halt.
3 | 받망희 | Put 3 in stack, print, halt.
3 | 반밧나빠빠다다망희 | Put two 2s in stack, divide, duplicate two times, add two times, print, halt. This is OK, but won't get good point.
72 | 밢밣따망희 | Put 8 and 9 in stack, multiply, print, and halt.
10 | 박밙따망희 | Put 2 and 5 in stack, multiply, print, and halt.


## Scoring

Average length of 101 Aheui codes that prints 100 to 200. If score is same, shorter code wins.

• Should probably test on multiple (ideally randomly selected) integers to avoid having people hardcode the n = 100 case.
– bb94
Jun 10, 2019 at 8:56
• @bb94 I thought that, but if people hardcode it, code length would be longer. So maybe it would be OK. And I though complicated scoring is not good. But maybe just adding one more case would be fine. Jun 10, 2019 at 8:59
• Which range of integers are we supposed to support? Jun 10, 2019 at 9:00
• @bb94 Too big, I think. Maybe 100 to 200 can be better, but nice idea. Thank you for your advice/ Jun 10, 2019 at 9:11
• @EriktheOutgolfer I actually posted at sandbox for about 2 days ago, but no one had gave me feedback. Jun 10, 2019 at 9:20

# Jelly, Score 849/101 = 8.406; 126 bytes of Jelly code

9,€µŒċZ€ṪḢ,0Ɗ¹E?ṭƊ€ż,ƭ€Ɱ€⁾+×ẎF€€ḢV;Ɗ€;@1ị<ɗƇ201FL$Þµ1ịⱮŒQTịµ$3¡Ṣṫ100Ṫ€F€⁵;‘,@⁾+×¤yⱮị⁽ıaD×588+“Ḥþ’Ḣ;+¥“ƲG~ọ’b21¤;ƲƲ¤;€“ẒP“ṃƓ’Ọ


Try it online!

A niladic link that returns a list of Jelly strings, one for each Aheui number from 100 to 200. The footer on TIO prepends the total length and the mean length.

Note this is equal in score to attinat’s Mathematica answer, but shorter in code length to generate the Aheui numbers. Full explanation to follow. Uses ㅂ (push), ㄷ (add), ㄸ (multiply) and ㅃ (duplicate) for initial consonants.

Output:

8.405940594059405
849
100 - 밖밙빠따따망희
101 - 밖밙따밟빠따다망희
102 - 밨밤밟다따망희
103 - 밙밤따밞밟따다망희
104 - 밤밖밟다따망희
105 - 받밙밞따따망희
106 - 밙빠따밟빠따다망희
107 - 밙밞따밤밟따다망희
108 - 박밨밟따따망희
109 - 밖밞따밟빠따다망희
110 - 바밟다박밟다따망희
111 - 밙밨따밟빠따다망희
112 - 박밞밤따따망희
113 - 밖밤따밟빠따다망희
114 - 밨밞따밤밟따다망희
115 - 받박밞밤따따다망희
116 - 밙밞따밟빠따다망희
117 - 밟밖밟다따망희
118 - 밨밟따밤빠따다망희
119 - 밞밤밟다따망희
120 - 받밙밤따따망희
121 - 박밟다빠따망희
122 - 바박밟다빠따다망희
123 - 밨밞따밟빠따다망희
124 - 박밨밞밤따다따망희
125 - 밙밙빠따따망희
126 - 박밞밟따따망희
127 - 밞밟따밤빠따다망희
128 - 박밤빠따따망희
129 - 밨밤따밟빠따다망희
130 - 바밟다밖밟다따망희
131 - 받박밤빠따따다망희
132 - 박밨따박밟다따망희
133 - 밙박밤빠따따다망희
134 - 박받밤빠따다따망희
135 - 받밙밟따따망희
136 - 밤밤밟다따망희
137 - 밞밤따밟빠따다망희
138 - 박밙밤빠따다따망희
139 - 받밤밤밟다따다망희
140 - 밖밙밞따따망희
141 - 바밖밙밞따따다망희
142 - 박밖밙밞따따다망희
143 - 박밟다밖밟다따망희
144 - 박밤밟따따망희
145 - 밤빠따밟빠따다망희
146 - 박바밤밟따다따망희
147 - 받밞빠따따망희
148 - 바받밞빠따따다망희
149 - 박받밞빠따따다망희
150 - 밙밙밨따따망희
151 - 바밙밙밨따따다망희
152 - 박밖밤밟따다따망희
153 - 밟밤밟다따망희
154 - 박밞따박밟다따망희
155 - 박밟밤밟다따다망희
156 - 박밨따밖밟다따망희
157 - 밖밟밤밟다따다망희
158 - 박밞밤밟따다따망희
159 - 받밖밞빠따다따망희
160 - 밖밙밤따따망희
161 - 바밖밙밤따따다망희
162 - 박밟빠따따망희
163 - 바박밟빠따따다망희
164 - 박바밟빠따다따망희
165 - 박밟다받밙따따망희
166 - 박박밟빠따다따망희
167 - 밙박밟빠따따다망희
168 - 받밞밤따따망희
169 - 밖밟다빠따망희
170 - 바밟다밤밟다따망희
171 - 박밖밟다빠따다망희
172 - 박밙밟빠따다따망희
173 - 밖밖밟다빠따다망희
174 - 박밨밟빠따다따망희
175 - 밙밙밞따따망희
176 - 박밤따박밟다따망희
177 - 박밙밙밞따따다망희
178 - 박밤밟빠따다따망희
179 - 밖밙밙밞따따다망희
180 - 밖밙밟따따망희
181 - 바밖밙밟따따다망희
182 - 박밞따밖밟다따망희
183 - 받밖밙밟따따다망희
184 - 밖바밙밟따다따망희
185 - 밙바밖밟따다따망희
186 - 받밨밞밤따다따망희
187 - 박밟다밤밟다따망희
188 - 밖박밙밟따다따망희
189 - 받밞밟따따망희
190 - 바받밞밟따따다망희
191 - 박받밞밟따따다망희
192 - 받밤빠따따망희
193 - 바받밤빠따따다망희
194 - 박받밤빠따따다망희
195 - 받밙따밖밟다따망희
196 - 밖밞빠따따망희
197 - 바밖밞빠따따다망희
198 - 박밟다박밟따따망희
199 - 받밖밞빠따따다망희
200 - 밙밙밤따따망희


# Wolfram Language (Mathematica), score 849/101 = 8.406

g@n_:=f@n<>"망히"
f@n_:=f@n=Switch[n,-1,"밯",1,"반반나",9,"밞",8,"밣",7,"밝",6,"밦",5,"발",4,"밗",3,"받",2,"박",
_,mn@{m@n,a@n,s@n}]
m@n_:=m@n=f@#<>If[# #==n,"빠",f[n/#]]<>"따"&/@Select[Divisors@n,1<# #<=n&]//mn
a@n_:=a@n=f@#<>f[n-#]<>"다"&/@Range[⌈n/2⌉-1]//mn
s@n_:=s@n=m[n+#]<>f@#<>"타"&/@Range[n-1]//mn
mn=First@*MinimalBy[StringLength[""<>#]&]


Try it online!

Builds numbers with 다 (+) 따 (*) 타 (-), and 빠 (duplicate), in addition to literals for 2..9. Doesn't actually make use of 밯=-1.

Paste the tio output (Unicode character codes) into Mathematica to see the result:

100 -> 밗발빠따따망히
101 -> 박밞박밞다따다망히
102 -> 밦밣밞다따망히
103 -> 받밗발빠따따다망히
104 -> 밣밗밞다따망히
105 -> 받발밝따따망히
106 -> 박밗밝빠따다따망히
107 -> 박받발밝따따다망히
108 -> 박밦밞따따망히
109 -> 밗받발밝따따다망히
110 -> 박발박밞다따따망히
111 -> 받박발밝따다따망히
112 -> 박밝밣따따망히
113 -> 발박밦밞따따다망히
114 -> 박받밦밞따다따망히
115 -> 발박받밝따다따망히
116 -> 박박밝밣따다따망히
117 -> 밞밗밞다따망히
118 -> 박받밝밣따다따망히
119 -> 밝밣밞다따망히
120 -> 받발밣따따망히
121 -> 박밞다빠따망히
122 -> 박발밝밣따다따망히
123 -> 받발밗밞따다따망히
124 -> 박밦밝밣따다따망히
125 -> 발발빠따따망히
126 -> 박밝밞따따망히
127 -> 박발발빠따따다망히
128 -> 박밣빠따따망히
129 -> 받받발밣따다따망히
130 -> 박발밗밞다따따망히
131 -> 받박밣빠따따다망히
132 -> 박밦박밞다따따망히
133 -> 밝박밣밞다다따망히
134 -> 박받밣빠따다따망히
135 -> 받발밞따따망히
136 -> 밣밣밞다따망히
137 -> 박받발밞따따다망히
138 -> 박발밣빠따다따망히
139 -> 받밣밣밞다따다망히
140 -> 밗발밝따따망히
141 -> 받박발밞따다따망히
142 -> 박밝밣빠따다따망히
143 -> 박밞다밗밞다따망히
144 -> 박밣밞따따망히
145 -> 발박받밞따다따망히
146 -> 박밞밣빠따다따망히
147 -> 받밝빠따따망히
148 -> 박박밣밞따다따망히
149 -> 박받밝빠따따다망히
150 -> 발발밦따따망히
151 -> 밗받밝빠따따다망히
152 -> 박밗밣밞따다따망히
153 -> 밞밣밞다따망히
154 -> 박밝박밞다따따망히
155 -> 발받밗밝따다따망히
156 -> 박밦밗밞다따따망히
157 -> 밗밞밣밞다따다망히
158 -> 박밝밣밞따다따망히
159 -> 받밗밝빠따다따망히
160 -> 밗발밣따따망히
161 -> 밝박받밝따다따망히
162 -> 박밞빠따따망히
163 -> 받밗발밣따따다망히
164 -> 밗발밗밞따다따망히
165 -> 받발박밞다따따망히
166 -> 박박밞빠따다따망히
167 -> 발박밞빠따따다망히
168 -> 받밝밣따따망히
169 -> 밗밞다빠따망히
170 -> 박발밣밞다따따망히
171 -> 받받밦밞따다따망히
172 -> 박발밞빠따다따망히
173 -> 밗밗밞다빠따다망히
174 -> 박밦밞빠따다따망히
175 -> 발발밝따따망히
176 -> 박밣박밞다따따망히
177 -> 받받밝밣따다따망히
178 -> 박밣밞빠따다따망히
179 -> 밗발발밝따따다망히
180 -> 밗발밞따따망히
181 -> 밦발발밝따따다망히
182 -> 박밝밗밞다따따망히
183 -> 받발밝밣따다따망히
184 -> 밗밗밦밝따다따망히
185 -> 발박발밝따다따망히
186 -> 받밦밝밣따다따망히
187 -> 박밞다밣밞다따망히
188 -> 밗박발밞따다따망히
189 -> 받밝밞따따망히
190 -> 발박밗밞따다따망히
191 -> 박받밝밞따따다망히
192 -> 받밣빠따따망히
193 -> 밗받밝밞따따다망히
194 -> 박받밣빠따따다망히
195 -> 받발밗밞다따따망히
196 -> 밗밝빠따따망히
197 -> 발받밣빠따따다망히
198 -> 박밞박밞다따따망히
199 -> 받밗밝빠따따다망히
200 -> 발발밣따따망히


The lowest number that improves with 타 is 211, with 받밣밞따따발타 (3*8*9-5) beating out 발밠밝따따반반나다 (5*6*7+2/2).

The next lowest, 239 (받밞빠따따밗타=3*9*9-4), didn't require 반반나 in its 다/따-only construction (받밣밞따밝다따박다=3*(8*9+7)+2).

An earlier version of this program generated 다/따-only constructions.

## With 밯=-1 (score unchanged)

g@n_:=f@n<>"망히"
f@n_:=f@n=Switch[n,1,"밯",9,"밞",8,"밣",7,"밝",6,"밦",5,"발",4,"밗",3,"받",2,"박",
_,mn@{m@n,a@n,s@n}]
m@n_:=m@n=f@#<>If[# #==n,"빠",f[n/#]]<>"따"&/@Select[Divisors@n,1<# #<=n&]//mn
a@n_:=a@n=f@#<>f[n-#]<>If[#==1,"타","다"]&/@Range[⌈n/2⌉-1]//mn
s@n_:=s@n=m[n+#]<>f@#<>If[#==1,"다","타"]&/@Range[n-1]//mn
mn=First@*MinimalBy[StringLength[""<>#]&]


Try it online!

If the program is given no input, 밯 (read a character from input) returns -1, which allows for a one-character 1 literal.

The lowest number that benefits from this is 269, which improves to 발밦밞따따밯다 (5*6*9+(-1)) from 박받밣밞빠따다따다 (2+3*(8+9*9)).

• Whow... I actually never expected someone answer to this, because linked question has only one answer, and answer from asker himself/herself. Great one! But, 밯 is actually 'get one character from input', not -1. Jun 11, 2019 at 13:17
• I found bug : 밗밗밠밝따다따망히(output for 184) actually prints 212. It is 4 4 7 7 * + * or (7 * 7 + 4) * 4. ㄽ is 7, not 6. ㅄ is 6. Jun 11, 2019 at 13:28
• @LegenDUST Oops. Should be fixed. Given no input, 밯 should be functionally identical to -1, though.
– att
Jun 11, 2019 at 19:37
• You also use ㅃ (duplicate). Jun 11, 2019 at 23:08
• I know 밯` give -1, but not every implement gives it. clever, though. Jun 12, 2019 at 10:20