2020 day 5 and 6
This commit is contained in:
parent
70f1c47d12
commit
f3e12ea387
6 changed files with 2215 additions and 0 deletions
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)
|
Loading…
Add table
Add a link
Reference in a new issue