-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday_06.js
More file actions
39 lines (32 loc) · 785 Bytes
/
day_06.js
File metadata and controls
39 lines (32 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict'
const input = require('./data/day_06').split('\n\n')
let counts = []
let total = 0
for (const group of input) {
const acc = {}
for (let i = 0, c; (c = group[i]) !== undefined; ++i) {
if (c >= 'a' && c <= 'z') {
acc[c] = acc[c] || 1
}
}
const n = Reflect.ownKeys(acc).length
counts.push(n)
total += n
}
console.log('sum', total, counts)
counts = []
total = 0
for (const group of input) {
const answers = group.split('\n')
const yes = {}
answers[0].split('').forEach(k => yes[k] = 1)
for (let i = 1; i < answers.length; ++i) {
Reflect.ownKeys(yes).forEach(k => {
if (!answers[i].includes(k)) delete yes[k]
})
}
const n = Reflect.ownKeys(yes).length
counts.push(n)
total += n
}
console.log('sum', total, counts)