Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Command: sed -e'$!s/ /0/g;$s/\(\S\)/[\1]/g' input | dc -fdc-p2.dc
- 0 ? # line i=0
- [
- r d3R r:T # Table(i) = line
- 1+ ? z2=L
- ] dsLx
- zR sn # numLines=i; op1 op2 op3 ...
- z so # numOpts
- [ SO z0<L ] dsLx # store ops on temp O stack
- lo [ LO S* 1- d0<L ] dsLx # reverse stack onto * stack
- # stack: 0
- # Process digit: digit i acc -> 0 i acc
- [
- 3R A*+ # acc*10+digit i
- r0
- ] sP
- [3Q] sQ
- # Get next number: 0 -> acc
- [
- 0d # i=0 acc=0
- [
- d;T # Table(i) i acc
- A~ # lastDigit rest i acc
- 3Rd 4R r:T # Table(i) = rest; i lastDigit i acc
- r d0<P # 0 i acc
- + # clear 0
- 1+ dln>I
- ] dsIx s.
- d0=Q # Force calling loop to quit if 0
- ] sN
- # stack: sum=0 (still)
- [
- lNx # get a number; num1 sum
- [
- lNx # num acc sum
- l*x # acc := acc op num
- lLx
- ] dsLx +
- + # sum += acc
- L*s. # pop op and junk
- lMx
- ] dsMx
- [Part 2: ]n +p
Advertisement
Add Comment
Please, Sign In to add comment