diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-12-01 13:34:29 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-12-01 13:34:43 +0300 |
commit | 9ee5ab609d980c41234c384f3e8ef39b1575de73 (patch) | |
tree | a0a9e06366f966314a458ded938fa672fe8dd2d4 /day-1/index.js | |
download | aoc-2022-9ee5ab609d980c41234c384f3e8ef39b1575de73.tar.gz |
feat(day1): initial solution
Diffstat (limited to 'day-1/index.js')
-rw-r--r-- | day-1/index.js | 15 |
1 files changed, 15 insertions, 0 deletions
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); + |