Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Command: tr -cs '[0-9\n]' ' ' <input | dc -fdc-p1.dc
- [ lp ln2/1+;l+ sp ] sP
- # Read in rules section
- ?
- [
- rA0*+ 1 r:r
- ? z0<L
- ] dsLx
- # Process
- ?
- [
- # Load list
- z dsn # n = size of list, stack: i=0 ln ln-1 ... l1
- [
- d_3R :l # set list(i)
- 1- d0<I
- ] dsIx # end: 0 on stack
- # Check list
- ln # i = n, stack: i sum=0
- [
- d1- # j = n-1, stack: j i sum
- [
- d3Rd # i i j j sum
- ;l3R;l # list(j) list(i) i j sum
- A0*+;r # rule(j|i) i j sum
- 4R+_3R # add rule to sum
- r1- d0<J # j--
- ] dsJx + # end: stack: i+0 sum
- 1- d1<I # i--
- ] dsIx * # end: stack: sum*1
- ln d1-*2/ # triangle( n-1 )
- =P # P if triangle == sum
- ? z0<L
- ] dsLx
- [Part 1: ]n lpp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement