This commit is contained in:
Smaug123
2023-12-02 09:45:00 +00:00
parent 5923d62dbf
commit 01d66b8814

22
mathematica/day_2.m Normal file
View File

@@ -0,0 +1,22 @@
(* ::Package:: *)
parseLine[s_] :=
Block[{a, b},
{a, b} = StringSplit[s, ": "];
{FromDigits @ Last @ StringSplit[a], Rule @@@ (Reverse /@ MapAt[FromDigits,
StringSplit[StringSplit[#, ", "], " "], {All, 1}])& /@ StringSplit[b,
"; "]}
]
With[{games = parseLine /@ StringSplit[s, "\n"]},
First /@ Select[games, AllTrue[#[[2]], And @@ Thread[({"red", "green",
"blue"} /. #) <= {12, 13, 14}] /. {"red" -> 0, "green" -> 0, "blue"
-> 0}&]&]
] // Total
With[{games = parseLine /@ StringSplit[s, "\n"]},
Times @@ Max /@ Transpose[{"red", "green", "blue"} /. #[[2]]] /.
_String -> 0& /@ games
] // Total