Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [rs.q] sQ # clear depth and return numButtons
- [F++q] sX # return a big number (15 + depth + numButtons)
- [r] sr # reverse top of stack
- # XOR button into current array: buttonArray ->
- [
- Fr x # conx1 conx2 ... 15 (sentinel)
- [
- d;c 1r- r:c # curr[conx1] = !curr[conx1]
- dF>I
- ] dsIx s.
- ] s^
- # Recurse binary: numButtons depth -> minimum button presses
- [
- 0d # i=0 sum=0 numButtons depth
- [
- d;c 3R A*+ # sum = sum*10 + curr[i]
- r1+ dll>C
- ] dsCx s. # current numButtons depth
- lp=Q # return (numButtons) if (pattern == curr)
- rd ln<X # if (depth > numButtons) return (result F^F)
- # depth numButtons
- d;b dl^x # xor current with button[depth] to press
- _3R 1+ d3R d3R # depth++ numButtons numButtons depth [butt]
- r1+ lRx # recurse( numButtons+1, depth+1 )
- # result numButons depth [butt]
- 4R l^x # xor current with button[depth] to unpress
- _3R lRx # recurse( numButtons, depth+1 )
- d3R d3R # ret1 ret2 ret2 ret1
- >r s. # put max on top and delete it
- ] sR
- ?
- [
- 0 # i [jolts] [butt1] [butt2] ... [buttn] [input]
- [
- 1+ # i++
- d4R r:b # button[i] = [butt1]; i jolts butt2 ... input
- z3<L
- ] dsLx
- sn # n = number of buttons
- rx sp # p = light pattern
- xz sl # l = number of lights (from jolt elements)
- c # clear jolt elements
- 1 0 lRx # recurse( numButtons=0, depth=1 )
- ls+ss # sum += result
- ? z0<M
- ] dsMx
- [Part 1: ]nlsp
Advertisement
Add Comment
Please, Sign In to add comment