Try it online!
Nice, small, and fast code. Slightly golfed after writing explanation. I'll not change it, because it is just same code.
Aheui is befunge-like language and (almost) every character of Aheui is operator. Part of character looks like
ㅏ, ㅐ, ㅓ, ㅜ, ㅛ, ㅗ, ㅢ determines direction where next operator execute.
ㅏ is left-to-right,
ㅓ is right-to-left,
ㅗ is down-to-up,
ㅜ is up-to-down,
ㅛ is down-to-up, with skipping one character in two characters.
ㅐ is 'nothing' : keep same speed and direction.
ㅂ commend is store given number in current stack,
ㄴ commend is divide upmost two number in current stack. Both
백 store 2, so
박밴내 store 1 in current stack(default
ㅅ commend change current stack.
색 change stack to
ㅂ commend with
방) get a number from STDIN. So
색뱅 get a number and store it in stack
ㅃ commend duplicate upmost value in current stack, and
ㅊ commend pop value from current stack and see if it is 0. If it is, it go to opposite direction from
ㅓ indicate : in here right-to-left. If it is not, it go to direction where
ㅓ indicate. So
뿌(\n)처 see if input is 0 or not, and go right if zero, and go left if not.
If input is zero, here is evaluated. (from
소 commend) First, change current stack to
ㅁ commend is pop, and if used with
ㅇ it print value as number.
희 halts program. So it print 1 and halt.
Look at this image for help. Here is main loop.
ㅌ is subtraction, and
ㄸ is multiply.
ㅆ move value from current stack to selected one.
Put it shortly, it get number from
nothing stack(or get 1), subtract to find if it is zero, and if not zero multiply and restart loop.
And if zero, go to rightmost place of code with popping one number.
Print number, then pointer go to
희 : halt.
In one image :
SEL is select, MOV is move, DUP is duplicate. This image is produced by AheuiChem, Aheui development tool in Korean. Translated with paint tool of windows.