Here is my clojure solution
Back to a more typical difficulty today ❄️
Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.
https://gitea.baerentsen.space/FrederikBaerentsen/AdventOfCode/src/branch/master/2023 doing it in python.
Todays puzzle wasn’t too bad. Part 1 was definitely longer than part 2.
Yes, quite the role reversal between the parts from yesterday. 😀
In Factor:
Here it is on GitHub with comments and imports.
: known-color ( color-phrases regexp -- n )
all-matching-subseqs [ 0 ] [
[ split-words first string>number ] map-supremum
] if-empty
;
: line>known-rgb ( str -- game-id known-rgb )
": " split1 [ split-words last string>number ] dip
R/ \d+ red/ R/ \d+ green/ R/ \d+ blue/
[ known-color ] tri-curry@ tri 3array
;
: possible? ( known-rgb test-rgb -- ? )
v<= [ ] all?
;
: part1 ( -- )
"vocab:aoc-2023/day02/input.txt" utf8 file-lines
[ line>known-rgb 2array ]
[ last { 12 13 14 } possible? ] map-filter
[ first ] map-sum .
;
: part2 ( -- )
"vocab:aoc-2023/day02/input.txt" utf8 file-lines
[ line>known-rgb nip product ] map-sum .
;