Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Command: tr '-' '_' <input | dc -fpart2.dc
- 0 # sum = 0
- ?
- [
- zsn # n = length
- [
- zlnr-:a # array(n-z) = top
- z1<L
- ] dsLx
- ln2- # stack: sum i=len (array is 2 less than n marked)
- [
- dd;a # sum i j=i a(j)
- d5R+ # i j a(j) sum+=a(j)
- _4Rr # sum i a(j) j=i
- [
- 1- # j--
- d;a # sum a(j+1) j a(j)
- d 4Rr- # diff = a(j+1) - a(j)
- 3Rd # sum a(j) diff j j
- _3R:a # a(j)=diff; stack: sum old-a(j) j
- d 0<J # actually need only to 2<J, but this makes clearing junk easy
- ] dsJx
- # stack: sum i junk 0
- *+ # clear junk
- 1- d1<I # only need 2<I again, but saves a stroke cleaning up
- ] dsIx
- * # clear i (*1)
- ? z1<M
- ] dsMx
- [Part 2: ]np
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement