Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Command: tr '-' '_' <input | dc -fpart1.dc
- 0 # sum = 0
- ?
- [
- zsn # n = length
- [
- z:a # array(z) = top
- z1<L
- ] dsLx
- ln # stack: sum i=len
- [
- 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<J again, but saves a stroke cleaning up
- ] dsIx
- * # junk i (*1)
- ? z1<M
- ] dsMx
- [Part 1: ]np
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement