- cross-posted to:
- hackernews@derp.foo
- cross-posted to:
- hackernews@derp.foo
You must log in or register to comment.
Here is my clojure solution
Back to a more typical difficulty today ❄️
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 . ;