Paste: aoc2023 day 2
Author: | erg |
Mode: | factor |
Date: | Sat, 2 Dec 2023 21:34:09 |
Plain Text |
USING: aoc2023 arrays ascii assocs kernel math.parser
math.vectors sequences sequences.extras splitting ;
IN: aoc2023.day2
: day2-input ( -- string ) 2 ?download-aoc2023-input ;
: day2-input-parsed ( -- assoc )
day2-input split-lines [
"Game " ?head drop ": " split1
[ string>number ]
[
";" split [
"," split [
[ { 0 0 0 } clone ] dip
[ blank? ] trim " " split1
[ string>number ] [ { "red" "green" "blue" } index pick set-nth ] bi*
] map [ v+ ] 1reduce
] map
] bi* 2array
] map ;
: day2-1 ( -- n )
day2-input-parsed
[ { 13 14 15 } '[ _ v< ] map concat vall? ] filter-values keys sum ;
: day2-2 ( -- n )
day2-input-parsed
values [ [ vmax ] 1reduce product ] map-sum ;
New Annotation