From 9ee5ab609d980c41234c384f3e8ef39b1575de73 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 1 Dec 2022 13:34:29 +0300 Subject: feat(day1): initial solution --- day-1/index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 day-1/index.js (limited to 'day-1/index.js') diff --git a/day-1/index.js b/day-1/index.js new file mode 100644 index 0000000..512deea --- /dev/null +++ b/day-1/index.js @@ -0,0 +1,15 @@ +const fs = require('fs'); +const input = fs.readFileSync('./day-1/input.txt').toString(); + +const lines = input.split('\n'); +const result = lines.reduce((acc, line) => { + if (line === '') { + if (acc.current > acc.greatest) acc.greatest = acc.current; + acc.current = 0; + } else acc.current += parseInt(line); + + return acc; +}, { current: 0, greatest: 0 }); + +console.log(result); + -- cgit v1.2.3