Advertisement
musifter

AoC 2022, day 25 (dc)

Dec 25th, 2022
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | Source Code | 0 0
  1. # Print table
  2. 0d:t
  3. 1d:t
  4. 2d:t
  5. [=] 3:t
  6. [-] 4:t
  7.  
  8. # Convert number to decimal (stack: num pow result... )
  9. [
  10. 10~ # grab last digit: digit rest pow result
  11. 2+ 5% 2- # convert digit to (-2,2) range
  12. 3R d 5* _4R # pull up power, tuck copy 5 * power back
  13. * 4R + _3R # digit * pow, pull up and add to result, tuck back
  14. d 0!=L # loop while not zero
  15. ] sL
  16.  
  17. # Stack at top: sum ...
  18. [
  19. r 0r 1r # Prepare stack to call L (num pow result sum ...)
  20. [Converting: ]np
  21. lLx s. s. # Convert with L, remove temps leaving: result sum ...
  22. [Result: ]np
  23. + # add to sum
  24. z 1<M # loop until only sum left
  25. ] sM
  26. 0 lMx
  27. [Total sum: ]np
  28.  
  29. # Convert to SNAFU. Stack is: sum (result)
  30. [
  31. 5~ # sum -> (sum % 5) (sum / 5)
  32. d;t _3R # dup and tuck table(sum % 5) in result
  33. 1-2/ # top now 0 if digit 0-2, 1 if digit 3 or 4
  34. + # add carry to sum/5 if appropriate
  35. d 0!=C # loop if sum not zero
  36. ] sC
  37. lCx s. # call convert, discard sum remnant
  38.  
  39. # Print stack on one line with n
  40. [
  41. n
  42. z 0<P
  43. ] sP
  44. [Part 1: ]n lPx
  45. []ps.
  46.  
  47. [<END>]ps.
  48. [<stack>]ps. f [<bottom>]ps.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement