Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [ q ] sQ
- 0 sn # number of elves
- # Store elf sum
- [
- s. # remove dup sentinel
- ln:e # store in elf(n)
- ln 1+ sn # n++
- 0 # start new sum
- ] sS
- # Main loop
- [
- r # rotate sum under input
- d _1=S # check if next input is _1 (blank line)
- z 1=Q # if only sum left on stack, quit loop
- + # sum += top
- lLx # loop
- ] sL
- 0 # push elf calorie sum
- lLx # do reading loop
- # New max
- [
- d sm
- ] sN
- # Max finding loop
- [
- d;e # get elf(idx)
- 3R # rotate max from bottom to top
- <N # set new max if greater
- lm;e r # put max under idx
- 1+ # idx++
- d ln>M # loop until idx == number of elves
- ] sM
- # Run max finder
- [
- 0 sm
- 0;e 1 lMx # get new max
- ] sR
- lRx
- s. [Part 1: ]np
- 0 lm:e # zero max
- lRx
- s.+
- 0 lm:e # zero max
- lRx
- s.+
- [Part 2: ]np
Advertisement
Comments
-
- The command I use with this for the input (which needs some mangling) is:
- perl -pe 's#^$#_1#; BEGIN {print "_1 "}' input | dc -f- dc-p12.dc
Add Comment
Please, Sign In to add comment
Advertisement