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
- [ lc+sc 0 ] sC # add rule lookup to c, replace with 0
- [ rd;l lp+sp r ] sS # score list(second)
- [
- lnd2/r # stack: i=n n/2
- [
- d3Rd 3R;c=S # if count(i) == n/2 then score
- r1- d0<I
- ] dsIx +s.
- ] 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 total=0
- [
- 0sc
- 0r ln # j=n i sum=0 total
- [
- dd 4Rdd # i i i j j j sum total
- ;l 4R;l # list(j) list(i) i j sum total
- A0*+ ;r # rule(j|i) i j sum total
- r4R >C # keep rule checks with j>i out of sum for now
- 4R + _3R # add rule to sum
- r1- d0<J # j--
- ] dsJx + # end: stack: i+0 sum total
- d3Rd lc+ 3R:c # counts(i) = sum+c; stack: sum i total
- 3R+r # total += sum
- 1- d0<I # i--
- ] dsIx + # end: stack: total+0
- ln d1-*2/ !=P
- ? z0<L
- ] dsLx
- [Part 2: ]n lpp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement