56 lines
2 KiB
Text
56 lines
2 KiB
Text
# Macro for computing the input number length
|
|
[10 # pushes 10 to stack
|
|
/ # divides input by 10 and stores result on stack
|
|
ll # push length on stack
|
|
1+ # add one to stack (length)
|
|
# p # prints intermediate length (for debugging)
|
|
sl # saves length to register l
|
|
d # duplicates value (number) on top of stack
|
|
0 # pushes 0 to stack
|
|
<Lx # executes length macro (L) if number > 0
|
|
] sL # end of length macro, store it in L
|
|
|
|
# is Disarium macro
|
|
[d # duplicates value (number) on top of stack
|
|
10 # pushes 10 to stack
|
|
% # pushes (number % 10) to stack
|
|
ll # pushes length to stack
|
|
^ # computes (n % 10) ^ len
|
|
ls # pushes sum to stack
|
|
+ss # computes new sum and stores it in s
|
|
10/ # integer division number / 10
|
|
ll # pushes length on stack
|
|
1- # subtract 1 froml length
|
|
sl # stores new length in l
|
|
d # duplicates value (number) on top of stack
|
|
0 # pushes 0 to stack
|
|
<Dx # executes recursively disarium macro (D) if number > 0
|
|
] sD # stores disarium macro in D
|
|
|
|
# Printing and counting macro
|
|
[lc1+sc # increments disarium number counter
|
|
lnp # print number
|
|
]sP # Stores printing macro in P
|
|
|
|
# Iteration macro
|
|
[Oss # stores 0 in register s (sum)
|
|
li sn # Stores iteration variable in number register
|
|
ln # pushes number to stack
|
|
0sl # stores 0 in register l (length)
|
|
lLx # runs the length macro
|
|
0ss # inititialize sum to 0
|
|
cln # clear stack and pushes number onto it
|
|
# llp # print the length
|
|
lDx # runs the Disarium macro once
|
|
lsln # pushes sum and number
|
|
=P # runs the printing macro if numbers are equal
|
|
li # loads iteration variable
|
|
1+si # increments iteration variable
|
|
lc18 # pushes counter and 18 on stack
|
|
>Ix # runs recursively iteration macro if counter < 18
|
|
] sI # end of iteration macro, stores it in I
|
|
|
|
# Main
|
|
0si # Initiate iteration variable
|
|
0sc # Initiate disarium numbers counter
|
|
lIx # running iteration macro the first time
|