! Copyright (C) 2023 Doug Coleman. ! See https://factorcode.org/license.txt for BSD license. 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 ;