Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Print table
- 0d:t
- 1d:t
- 2d:t
- [=] 3:t
- [-] 4:t
- # Convert number to decimal (stack: num pow result... )
- [
- 10~ # grab last digit: digit rest pow result
- 2+ 5% 2- # convert digit to (-2,2) range
- 3R d 5* _4R # pull up power, tuck copy 5 * power back
- * 4R + _3R # digit * pow, pull up and add to result, tuck back
- d 0!=L # loop while not zero
- ] sL
- # Stack at top: sum ...
- [
- r 0r 1r # Prepare stack to call L (num pow result sum ...)
- [Converting: ]np
- lLx s. s. # Convert with L, remove temps leaving: result sum ...
- [Result: ]np
- + # add to sum
- z 1<M # loop until only sum left
- ] sM
- 0 lMx
- [Total sum: ]np
- # Convert to SNAFU. Stack is: sum (result)
- [
- 5~ # sum -> (sum % 5) (sum / 5)
- d;t _3R # dup and tuck table(sum % 5) in result
- 1-2/ # top now 0 if digit 0-2, 1 if digit 3 or 4
- + # add carry to sum/5 if appropriate
- d 0!=C # loop if sum not zero
- ] sC
- lCx s. # call convert, discard sum remnant
- # Print stack on one line with n
- [
- n
- z 0<P
- ] sP
- [Part 1: ]n lPx
- []ps.
- [<END>]ps.
- [<stack>]ps. f [<bottom>]ps.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement