Skip to content

Commit 90f656e

Browse files
feat(2020-day-07): count the bags in full data
solution for part 2
1 parent 014f9db commit 90f656e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

2020/day-7/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
// eslint-disable-next-line no-unused-vars
2+
const console = require('../helpers')
13
require('./solution')

2020/day-7/solution.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fs = require('fs')
22
const path = require('path')
33
const filePath = path.join(__dirname, 'input.txt')
44
const { linesToArray } = require('../../2018/inputParser')
5-
const { parseRule, findAllowedOuter } = require('./bagRules')
5+
const { parseRule, findAllowedOuter, countInner } = require('./bagRules')
66

77
fs.readFile(filePath, { encoding: 'utf8' }, (err, initData) => {
88
if (err) throw err
@@ -23,10 +23,12 @@ fs.readFile(filePath, { encoding: 'utf8' }, (err, initData) => {
2323
}
2424

2525
const part2 = () => {
26-
const data = resetInput()
27-
console.debug(data)
28-
return 'No answer yet'
26+
const rules = resetInput()
27+
return Object.values(
28+
countInner(rules.map(parseRule), 'shiny gold bag')
29+
).reduce((a, b) => a + b, 0)
2930
}
31+
3032
const answers = []
3133
answers.push(part1())
3234
answers.push(part2())

0 commit comments

Comments
 (0)