8000 feat(2018 day-15): structure solution for Part 1 · developher-net/advent-of-code@4eb3c14 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4eb3c14

Browse files
feat(2018 day-15): structure solution for Part 1
1 parent 9d9f402 commit 4eb3c14

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

2018/day-15/solution.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { loadInput } = require('./helpers')
2+
const { Cave } = require('./caves')
3+
4+
const init = (data) => {
5+
const cave = new Cave(data)
6+
while (cave.outcome === null) {
7+
cave.advance()
8+
}
9+
// Get total hitpoints of winning army X the number of completed rounds
10+
const answer = cave.rounds * cave.units.filter((unit) => unit.type === cave.outcome).reduce((hp, unit) => hp + unit.hp, 0)
11+
12+
const answer2 = ''
13+
console.log(`-- Part 1 --`)
14+
console.log(`Answer: ${answer}`)
15+
console.log(`-- Part 2 --`)
16+
console.log(`Answer: ${answer2}`)
17+
}
18+
19+
loadInput(init)

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
require('./2018/day-14/solution')
1+
require('./2018/day-15/solution')

0 commit comments

Comments
 (0)
0