Add 2023/Day2/part1.js

This commit is contained in:
x0x7 2024-11-30 00:05:35 -05:00
parent d8c3df2585
commit b8ca93c943
1 changed files with 12 additions and 0 deletions

12
2023/Day2/part1.js Normal file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env node
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
};
console.log('Result:',games.reduce((acc,game,idx)=>acc+=game.some(sample=>sample.some(([count,color])=>count>maxes[color]))?0:(idx+1),0));