diff options
author | Marvin Borner | 2024-03-22 23:05:39 +0100 |
---|---|---|
committer | Marvin Borner | 2024-03-22 23:05:39 +0100 |
commit | fd75e9dd97c8fb8672ba609fe4003a3865391c09 (patch) | |
tree | 2aa1daabe0b2f6107b68f5dc56ae9b7be8ef2fa9 /samples/aoc/2023/02/solve.bruijn | |
parent | a9880a191bbb5eeaf0faef9336263c92ef9351b6 (diff) |
More AOC
Diffstat (limited to 'samples/aoc/2023/02/solve.bruijn')
-rw-r--r-- | samples/aoc/2023/02/solve.bruijn | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/samples/aoc/2023/02/solve.bruijn b/samples/aoc/2023/02/solve.bruijn new file mode 100644 index 0000000..2daed35 --- /dev/null +++ b/samples/aoc/2023/02/solve.bruijn @@ -0,0 +1,18 @@ +:import std/Combinator . +:import std/String . +:import std/Math . +:import std/Char C + +valid? &[[\(C.eq? 0 'r' (1 >? (+12)) (C.eq? 0 'g' (1 >? (+13)) (1 >? (+14))))]] + +parse map (game → (map (sets → (map (cubes → (map (tail → cube)))) → concat → maxes)) → head) + game (split-list-by (C.eq? ':')) → tail + sets split-list-by (C.eq? ';') + cubes split-list-by (C.eq? ',') + cube (split-list-by (C.eq? ' ')) → &[[(string→number 1) : ^(^0)]] + maxes [(m 'r') : ((m 'g') : {}(m 'b'))] + m [max-by (compare ⋔ head) (filter [C.eq? (tail 0) 1] 1)] + +main lines → parse → enumerate → (φ cons part1 part2) + part1 (map &[[1 : (all? valid? 0)]]) → (filter tail) → (map (head → inc)) → sum + part2 (map &[(map head) → product]) → sum |