2020 day 5 and 6
This commit is contained in:
parent
70f1c47d12
commit
f3e12ea387
6 changed files with 2215 additions and 0 deletions
2093
2020/06/input.txt
Normal file
2093
2020/06/input.txt
Normal file
File diff suppressed because it is too large
Load diff
21
2020/06/part1.js
Normal file
21
2020/06/part1.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
const fs = require('fs');
|
||||
|
||||
const data = fs.readFileSync('test.txt', 'utf-8');
|
||||
const groups = data.split('\n\n');
|
||||
|
||||
let sum = 0
|
||||
for (let g = 0; g<groups.length; g++){
|
||||
let group = groups[g]
|
||||
// ignore spaces and new lines; we don't care about that
|
||||
group = group.replace(/[ \n]/gm, "")
|
||||
|
||||
// list of seen chars
|
||||
let chars = []
|
||||
for (let i = 0; i < group.length; i++) {
|
||||
// if not already seen, add to list of seen chars
|
||||
if (!chars.find(char => char == group[i])) { chars.push(group[i]) }
|
||||
}
|
||||
// keep a sum for our puzzle answer
|
||||
sum += chars.length
|
||||
}
|
||||
console.log(sum)
|
21
2020/06/part2.js
Normal file
21
2020/06/part2.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
const fs = require('fs');
|
||||
|
||||
const data = fs.readFileSync('input.txt', 'utf-8');
|
||||
const groups = data.split('\n\n');
|
||||
|
||||
let sum = 0
|
||||
for (let g = 0; g<groups.length; g++){
|
||||
// list of people in group
|
||||
let group = groups[g].split('\n')
|
||||
// first person
|
||||
let first = group[0]
|
||||
|
||||
// for each of the first person's answers
|
||||
for (let answer = 0; answer < first.length; answer++) {
|
||||
// if the total amount of that answer in the group is equal to the amount of people in the group, then everyone in the group answered that question
|
||||
if (group.length == [...groups[g].matchAll(first[answer])].length) {
|
||||
sum++
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(sum)
|
Loading…
Add table
Add a link
Reference in a new issue