From b8ca93c943a31c8aacd4fdd2bc6d5bdff76b74fd Mon Sep 17 00:00:00 2001 From: x0x7 Date: Sat, 30 Nov 2024 00:05:35 -0500 Subject: [PATCH] Add 2023/Day2/part1.js --- 2023/Day2/part1.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 2023/Day2/part1.js diff --git a/2023/Day2/part1.js b/2023/Day2/part1.js new file mode 100644 index 0000000..e036b88 --- /dev/null +++ b/2023/Day2/part1.js @@ -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)); \ No newline at end of file