AdventOfCodeSolutions/2023/Day2/part2.js

21 lines
616 B
JavaScript
Raw Normal View History

2024-11-30 00:06:12 -05:00
#!/usr/bin/env node
2024-11-30 00:20:21 -05:00
/* For https://goatmatrix.net/c/AdventOfCode/F9VPZJnJR6 */
2024-11-30 00:06:12 -05:00
var fs = require('fs');
var games = fs.readFileSync('input.txt','utf8').split('\n').filter(i=>i).map(i=>i.split(':').pop()).map(i=>i.split(';')).map(i=>i.map(i=>i.split(','))).map(i=>i.map(i=>i.map(i=>i.split(' ').filter(i=>i))));
var maxes = {
red:12,
green:13,
blue:14
};
var allpower = games.reduce((acc,game)=>{
var base={red:0,blue:0,green:0};
game.forEach(sample=>sample.forEach(([count,color])=>base[color]=Math.max(base[color],count)));
return acc+base.red*base.blue*base.green;
},0);
console.log('Result:',allpower);