Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Command: perl -00 -pe 's/\D*(\d+),?/$1 /g' <input | dc -fdc-p2.dc
- # Ignore registers
- ??c
- # Load code
- ? zsn
- [
- z1-:c
- z0<L
- ] dsLx
- # XOR of top two elements (lowest three bits)
- # Uses (A + B*(-1^A)) % 4 for 2-bits and +2% for the third
- [
- 4~ 3R 4~ # (B-low2) (B-rest) (A-low2) (A-rest)
- 3R
- d_1r^3R*+4d3R+r% # (B^A low2) (B-rest) (A-rest)
- _3R
- +2% # (B^A third) (B^A low2)
- 4*+
- ] s^
- [ s.laq ] sA # replace top with A
- [ s.lbq ] sB # replace top with B
- [ s.lcq ] sC # replace top with C
- # Resolve combo referencing:
- [
- d 4=A
- d 5=B
- d 6=C
- ] sR
- [r] sr
- [ lRx 2r^ lar/ sa ] 0:o # adv
- #[ lRx 2r^ lar/ sb ] 6:o # bdv - unused
- [ lRx 2r^ lar/ sc ] 7:o # cdv
- [ lRx 8% sb ] 2:o # bst
- [ lRx 8% q ] 5:o # out
- #[ 2- la 0!=r s. ] 3:o # jnz - unneed for part 2
- [ lb l^x sb ] 1:o # bxl
- [ s. lblc l^x sb ] 4:o # bxc
- # Try a value for register A: stack: val -> result
- [
- sa # la = arg
- 0 # ip = 1
- [
- dd 1+;c
- r;c ;ox # [block]x arg ip => ip
- 2+ lMx
- ] dsMx
- rs. # clear ip
- ] sT
- # push result: push 2nd, stack untouched
- [ r dSp r ] sP
- _1d Sp ln+ # push _1 on p, stack: i=n-1 (last index in code)
- 0r
- # stack: i (values to process)
- [
- # test possibilities (stack: i val rest)
- [
- d;c # code(i) i val rest
- 3R 7 # j=7 val targ=code(i) i rest
- [
- d 3Rd8* 3R+ dlTx # Try(val*8+j) val*8+j val j targ i rest
- 5R d3R =P # push if (result=targ); stack: targ tryval val j
- rs.r 3R # j val targ
- 1- d0!>J # j--, loop
- ] dsJx ++s. # stack: i rest
- z1<Z
- ] dsZx
- # stack: i
- [
- Lp d_1!=L # fully pop p stack
- ] dsLx
- Sp # push -1 back on p
- zR # move i to top
- 1- d0!>I
- ] dsIx s.
- # Get minimum value on stack:
- [
- d3R d3R # a b b a
- >r s. # rotate top if needed, then scrap
- z1<M
- ] dsMx
- [Part 2: ]np
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement