Skip to content

Commit

Permalink
πŸ™‚πŸ—ΊοΈ Updated with Glitch: day 2, part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Glitch (branch-three-oviraptor) committed Dec 2, 2023
1 parent 4eb00e3 commit 90e4b56
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion public/funs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 90e4b56

Please sign in to comment.