Skip to content

Commit 9b8a2e4

Browse files
feat(2020-day-11): solve part 2
1 parent 6bf5071 commit 9b8a2e4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

2020/day-11/solution.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,16 @@ fs.readFile(filePath, { encoding: 'utf8' }, (err, initData) => {
2727
}
2828

2929
const part2 = () => {
30-
const data = resetInput()
31-
console.debug(data)
32-
return 'No answer yet'
30+
let data = resetInput()
31+
let last = 0
32+
let curr = 1
33+
while (curr !== last) {
34+
last = curr
35+
data = format(advance(parse(data), 'visibility'))
36+
// count the current occupied seats
37+
curr = (data.match(/#/g) || []).length
38+
}
39+
return curr
3340
}
3441
const answers = []
3542
answers.push(part1())

0 commit comments

Comments
 (0)