12 lines
438 B
JavaScript
12 lines
438 B
JavaScript
|
#!/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));
|