From 90e4b56735ffd3ec039b984268215480d65109e3 Mon Sep 17 00:00:00 2001 From: "Glitch (branch-three-oviraptor)" Date: Sat, 2 Dec 2023 05:48:42 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=99=82=F0=9F=97=BA=EF=B8=8F=20Updated=20w?= =?UTF-8?q?ith=20Glitch:=20day=202,=20part=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/funs.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/public/funs.js b/public/funs.js index b20ec03..ee1bb67 100644 --- a/public/funs.js +++ b/public/funs.js @@ -72,7 +72,30 @@ return possible; }, part2: (data) => { - return data; + const gn = /^Game (\d+): /; + const gs = /(\d+)\s([rgb])/ + let sum = 0; + data.trim().split('\n').forEach(g => { + const gameNum = +g.match(gn)[1]; + const right = g.split(':')[1].trim(); + const game = { + gameNum, + r: 0, + g: 0, + b: 0, + s: 0 + }; + right.split(';').forEach(s => { + s.split(',').forEach(c => { + const cube = c.match(gs); + game[cube[2]] = Math.max(+cube[1], game[cube[2]]); + }); + }); + game.s = game.r * game.g * game.b; + sum += game.s; + console.log(game); + }); + return sum; } }, day3: {