mirror of
https://github.com/Aviortheking/advent-of-code.git
synced 2025-08-05 01:41:59 +00:00
Added the four first days of 2015
Yes i'm gonna do them all ! Signed-off-by: Avior <github@avior.me>
This commit is contained in:
1
2015/day-1/input.txt
Normal file
1
2015/day-1/input.txt
Normal file
File diff suppressed because one or more lines are too long
8
2015/day-1/part-1.ts
Normal file
8
2015/day-1/part-1.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import fs from 'fs'
|
||||
|
||||
const input = fs.readFileSync(__dirname + '/input.txt').toString()
|
||||
.split('')
|
||||
|
||||
console.log(
|
||||
"Result:", input.reduce((p, c) => p + (c === '(' ? 1 : -1), 0)
|
||||
)
|
19
2015/day-1/part-2.ts
Normal file
19
2015/day-1/part-2.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import fs from 'fs'
|
||||
|
||||
const input = fs.readFileSync(__dirname + '/input.txt').toString()
|
||||
.split('')
|
||||
|
||||
let v = 0
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
const item = input[i];
|
||||
if (item === '(') {
|
||||
v++
|
||||
continue
|
||||
}
|
||||
if (--v < 0) {
|
||||
console.log(
|
||||
"Result:", i + 1
|
||||
)
|
||||
break
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user