Paste: AoC day 1
Author: | Garklein |
Mode: | factor |
Date: | Thu, 1 Dec 2022 21:00:39 |
Plain Text |
USING: io.encodings.utf8 io.files math math.order math.parser
sequences sorting splitting ;
IN: aoc.1
: input ( -- file ) "~/factor/aoc/1/1.in" utf8 file-lines ;
: get-sorted-sums ( -- sums )
input { "" } split
[ [ string>number ] map sum ] map
natural-sort reverse ;
: part1 ( -- x ) get-sorted-sums first ;
: part2 ( -- x ) get-sorted-sums first3 + + ;
Author: | Garklein |
Mode: | factor |
Date: | Thu, 1 Dec 2022 21:13:00 |
Plain Text |
USING: io.encodings.utf8 io.files math math.order math.parser
sequences sorting splitting ;
IN: aoc.1
: input ( -- file ) "~/factor/aoc/1/1.in" utf8 file-lines ;
: get-sorted-sums ( -- sums )
input { "" } split
[ [ dec> ] map sum ] map
natural-sort ;
: part1 ( -- x ) get-sorted-sums last ;
: part2 ( -- x ) get-sorted-sums 3 tail* sum ;
New Annotation