this post was submitted on 02 Dec 2023
5 points (100.0% liked)

Advent of Code

283 readers
1 users here now

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://adventofcode.com

founded 1 year ago
MODERATORS
top 4 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 11 months ago

Here is my clojure solution

Back to a more typical difficulty today ❄️

[–] [email protected] 1 points 11 months ago (1 children)

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.

[–] [email protected] 1 points 11 months ago

Yes, quite the role reversal between the parts from yesterday. 😀

[–] [email protected] 1 points 11 months ago* (last edited 10 months ago)

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 .
;