Skip to content

Commit 6ddf5eb

Browse files
author
Mustafa Hanif
committed
2023 day 1
0 parents  commit 6ddf5eb

File tree

5 files changed

+2325
-0
lines changed

5 files changed

+2325
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

2022-1.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
var fs = require('fs');
2+
3+
const file = fs.readFileSync('input.txt', 'utf8');
4+
let lines = file.split('\n');
5+
6+
let count = 0;
7+
let maxCount = [0, 0, 0];
8+
9+
for (let i = 0; i < lines.length; i++) {
10+
if (lines[i].split('').length > 0) {
11+
const line = parseInt(lines[i], 10);
12+
count += line;
13+
} else {
14+
for (let j = 0; j < maxCount.length; j++) {
15+
if (count > maxCount[j]) {
16+
maxCount[j] = count;
17+
break;
18+
}
19+
}
20+
count = 0;
21+
maxCount.sort((a, b) => a - b);
22+
console.log(maxCount)
23+
}
24+
}
25+
26+
// part 1
27+
console.log(maxCount[maxCount.length - 1]);
28+
29+
// part 2
30+
console.log(maxCount.reduce((a, b) => a + b, 0));

0 commit comments

Comments
 (0)