1
Fork 0
mirror of https://github.com/RGBCube/AdventOfCode synced 2025-07-29 04:57:43 +00:00

Add day 1 part 2

This commit is contained in:
RGBCube 2023-12-02 17:37:12 +03:00
parent cd153bf92a
commit 5a36db3a99
No known key found for this signature in database
4 changed files with 131 additions and 7 deletions

22
2023/2-2.nix Normal file
View file

@ -0,0 +1,22 @@
{ lib, ... } @ args:
with builtins; with lib; rec {
games = (import ./2-1.nix args).games;
getMaxRGB = { maxRGB ? { red = 0; green = 0; blue = 0; }, rgbs }: if length rgbs == 0 then
maxRGB
else getMaxRGB {
maxRGB = mapAttrs (name: max (head rgbs).${name} or 0) maxRGB;
rgbs = sublist 1 (length rgbs - 1) rgbs;
};
makeOneIfZero = number: if number == 0 then 1 else number;
getPower = rgb: foldl' (accum: next: accum * makeOneIfZero next) 1 (attrValues rgb);
gamesMaxRGBs = map (game: getMaxRGB { rgbs = game.snd; }) games;
gamesPowers = map getPower gamesMaxRGBs;
result = foldl' add 0 gamesPowers;
}