Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/dc -finput
- [q] SX # exit loop macro
- [ lx 1+ sx ] S1 # inc counter for part 1
- [ ly 1+ sy ] S2 # inc counter for part 2
- # Main loop:
- [
- z 0 =X # stop when stack empty
- d li;p >1 # top -> (p(i) > top) top -> top
- d li 1+ 3% d si # top -> (i+1)%3 top top, next i = (i+1)%3
- ;p >2 # -> (p(next i) > top) top -> top
- li:p # p(next i) = pop
- lLx # loop
- ] SL
- # Mainline:
- 0d sx sy # init counters for results
- # Initialize previous array
- # Note that input is pushed, so we're going backwards (first is actually last)
- 0:p d 0;p >1 # compare top two, store first
- 1:p d 1;p >1 # compare next two, store second
- 2:p # store third
- 2 si # init index into previous array
- lLx # start loop
- [Part 1: ]n lxp
- [Part 2: ]n lyp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement