Paste: AOC Day 1
Author: | Kacarott |
Mode: | factor |
Date: | Fri, 2 Dec 2022 16:52:50 |
Plain Text |
USING: kernel AOC splitting math math.parser sequences heaps io accessors ;
IN: AOC.2022.1
: calories ( input -- seq )
"\n\n" split-subseq [ "\n" split harvest [ dec> ] map-sum ] map ;
: part-1 ( input -- result ) calories supremum ;
: part-2 ( input -- result ) calories V{ } like <min-heap> swap
3 [ [ pop f spin heap-push ] 2keep ] times
[ dupd f spin heap-push dup heap-pop* ] each
0 swap [ nip + ] slurp-heap ;
MAIN: [ 1 read-day-input [ part-1 print ] [ part-2 print ] bi ]
New Annotation