Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- d Zsd
- sp
- 0k
- # State machine, lAx to init, lNx to move to next state
- [ 1 sm [lBx]sN ] sA
- [ 0 sm [lCx]sN ] sB
- [ _1 sm [lDx]sN ] sC
- [ 0 sm [lAx]sN ] sD
- lAx
- [ q ] sQ # generic quit for breaking loops
- [ _1 * ] s| # multiply by -1 making positive (for doing abs)
- #
- # Copy number in p onto stack s, one digit at a time (most significant on top)
- #
- [
- [ LLs. s. ] SR
- ld si
- lp
- [
- d 10% Ss 10/
- li 1- d 0 =Q
- si
- lLx
- ] SL
- lLx s.
- LRx
- ] sS
- #
- # Calculate ith digit of next phase
- #
- [
- sn # digit number (passed in)
- [ LLs. LTs. LMs. rs. ] SR
- # Loop through stack s: iter i, mult m, state N, acc w
- lSx # copy phase onto stack s
- lAx # init state
- 0 Sw # init working sum
- ld si # i = number of digits
- ln sc
- [
- lc 1- d 0 =Q
- sc
- Ls s.
- li 1- si
- lTx
- ] ST
- lTx s.
- ln sc
- [ s. ln lNx ] SM
- [
- lm Ls * Lw + Sw
- li 1- d 0 =Q
- si
- lc 1- d 0 =M
- sc
- lLx
- ] SL
- lLx
- Lw d 0 >|
- 10%
- LRx
- ] sI
- [
- [
- 0 sq
- [
- d lIx
- lq 10* + sq
- 1+ d ld <Q
- lLx
- ] SL
- 1 lLx s.
- lq sp
- 1- [count: ]np d 0 =Q
- lJx
- ] sJ
- 100 lJx s.
- lp
- ] sP
- lPx
- [output phase: ]np
- Z ld r-
- [leading zeroes needed: ]np
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement