Advertisement
musifter

Untitled

Dec 16th, 2019
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. d Zsd
  2. sp
  3.  
  4. 0k
  5.  
  6. # State machine, lAx to init, lNx to move to next state
  7. [ 1 sm [lBx]sN ] sA
  8. [ 0 sm [lCx]sN ] sB
  9. [ _1 sm [lDx]sN ] sC
  10. [ 0 sm [lAx]sN ] sD
  11. lAx
  12.  
  13. [ q ] sQ # generic quit for breaking loops
  14. [ _1 * ] s| # multiply by -1 making positive (for doing abs)
  15.  
  16. #
  17. # Copy number in p onto stack s, one digit at a time (most significant on top)
  18. #
  19. [
  20. [ LLs. s. ] SR
  21.  
  22. ld si
  23.  
  24. lp
  25. [
  26. d 10% Ss 10/
  27. li 1- d 0 =Q
  28. si
  29. lLx
  30. ] SL
  31. lLx s.
  32.  
  33. LRx
  34. ] sS
  35.  
  36. #
  37. # Calculate ith digit of next phase
  38. #
  39. [
  40. sn # digit number (passed in)
  41.  
  42. [ LLs. LTs. LMs. rs. ] SR
  43.  
  44. # Loop through stack s: iter i, mult m, state N, acc w
  45. lSx # copy phase onto stack s
  46. lAx # init state
  47. 0 Sw # init working sum
  48. ld si # i = number of digits
  49.  
  50. ln sc
  51. [
  52. lc 1- d 0 =Q
  53. sc
  54. Ls s.
  55. li 1- si
  56. lTx
  57. ] ST
  58. lTx s.
  59.  
  60. ln sc
  61.  
  62. [ s. ln lNx ] SM
  63.  
  64. [
  65. lm Ls * Lw + Sw
  66. li 1- d 0 =Q
  67. si
  68.  
  69. lc 1- d 0 =M
  70. sc
  71. lLx
  72. ] SL
  73. lLx
  74.  
  75. Lw d 0 >|
  76. 10%
  77. LRx
  78. ] sI
  79.  
  80. [
  81. [
  82. 0 sq
  83. [
  84. d lIx
  85. lq 10* + sq
  86. 1+ d ld <Q
  87. lLx
  88. ] SL
  89. 1 lLx s.
  90.  
  91. lq sp
  92. 1- [count: ]np d 0 =Q
  93. lJx
  94. ] sJ
  95. 100 lJx s.
  96.  
  97. lp
  98. ] sP
  99.  
  100. lPx
  101. [output phase: ]np
  102. Z ld r-
  103. [leading zeroes needed: ]np
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement