mirror of
https://github.com/Aviortheking/advent-of-code.git
synced 2025-07-31 07:50:47 +00:00
2000
2021/day-1/input.txt
Normal file
2000
2021/day-1/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
12
2021/day-1/part-1.ts
Normal file
12
2021/day-1/part-1.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import fs from 'fs'
|
||||
|
||||
const input = fs.readFileSync(__dirname + '/input.txt').toString()
|
||||
|
||||
var previous = Infinity
|
||||
console.log("Result: " +
|
||||
input.split('\n').reduce((p, c) => {
|
||||
const tmp = previous
|
||||
previous = parseInt(c)
|
||||
return tmp < previous ? p + 1 : p
|
||||
}, 0)
|
||||
)
|
19
2021/day-1/part-2.ts
Normal file
19
2021/day-1/part-2.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import fs from 'fs'
|
||||
|
||||
const input = fs.readFileSync(__dirname + '/input.txt').toString()
|
||||
|
||||
const items = input.split('\n')
|
||||
|
||||
var previous = Infinity
|
||||
var count = 0
|
||||
|
||||
for (let i = 0; i < items.length - 3; i++) {
|
||||
const sum = parseInt(items[i]) + parseInt(items[i + 1]) + parseInt(items[i + 2])
|
||||
if (sum > previous) {
|
||||
count++
|
||||
}
|
||||
|
||||
previous = sum
|
||||
}
|
||||
|
||||
console.log(`Result: ${count}`)
|
Reference in New Issue
Block a user