Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/dc -finput
- [q] sX
- [3Q] sQ
- [1+] s+ # inc
- [
- 10~ # top -> top%10 top/10
- li1+ d si :g # (g(i++) = top%10) top/10
- d 0!=I # (top/10 != 0, loop) top/10
- ] sI
- [
- lIx s. # process number into g(), junk remnants
- li1+ si # i++ (for side borders)
- z 0<L # loop until stack empty
- ] sL
- 0 si lLx
- ###############################################################################
- [li] sP # push i on stack to mark flashed
- # Charge grid by 1 (set i=1 and leave copy on stack, leaves i remnant)
- [
- d d;g 1+ r:g ;g # i -> (g(i)=g(i)+1) i -> new-g(i)
- 10=P # flash on 10, P pushes i back on stack
- li1+ d11% 0=+ dsi # i++, i++ again if 0 mod 11
- d 110>C # i -> (i < 110, loop) i
- ] sC
- ################################################################################
- # Flash
- #
- [
- la r
- ] sB
- # Validator
- [
- d 1>Q d 109<Q d11% 0=Q # idx, if bad exit back to F (idx still on stack)
- ] sV
- [
- lVx # validate
- dsa # store idx in a
- d d;g 1+ r:g ;g # i -> (g(i)=g(i)+1) i -> new-g(i)
- 10=B # flash on 10, B pushed a back and rotates
- 0 # put remnant on stack to junk
- ] sA
- [
- d 1 r:f # top -> (f(top) = 1) top
- d 12- lAx s. # top -> top-12 top, call A, toss remnant
- d 11- lAx s. # ditto
- d 10- lAx s.
- d 1- lAx s.
- d 1+ lAx s.
- d 10+ lAx s.
- d 11+ lAx s.
- d 12+ lAx s. s.
- ] sF
- ################################################################################
- # Zero stack and count flashes
- [
- d 0 r:g # i -> (g(i) = 0) i
- ln1+ sn # num flashes ++
- ] sN
- [
- d d;f 1=N # i -> (f(i) = 1, count flash) i i
- 0 r:f # i i -> (f(i) = 0) i
- 1- d 0<Z # i--, loop if > 0
- ] sZ
- ################################################################################
- [ [Part 1: ]n lfp ] s1
- # Process flashers from stack
- [
- z 0=X # stop if stack empty
- d;f 0=F # top -> (f(top) = 0 flash) top
- lSx # loop
- ] sS
- # Main loop
- [
- 1 d si lCx s. # charge grid, stack now flashers
- lSx # process stack
- 0sn 109 lZx s. # zero flash array, counting flashes
- ln lf+ sf # add number to flash total
- ln 100=X # exit if 100 flashed this turn
- lt1+ d st 100=1 # t++, print part 1 on t = 100
- lTx # loop
- ] sT
- 0 sf # flashes = 0
- 1 st lTx # time = 1, start loop
- [Part 2: ]n ltp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement