2020 day 1 and 2 (:
This commit is contained in:
parent
cbc02f04d5
commit
de2fa19311
6 changed files with 1276 additions and 0 deletions
1000
2020/02/input.txt
Normal file
1000
2020/02/input.txt
Normal file
File diff suppressed because it is too large
Load diff
17
2020/02/part1.js
Normal file
17
2020/02/part1.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
const fs = require('fs');
|
||||
let data = fs.readFileSync('input.txt', 'utf-8');
|
||||
let lines = data.split('\n').map(x => x.split(" "));
|
||||
let count = 0
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
let line = lines[i]
|
||||
let lim = line[0].split("-")
|
||||
let char = line[1].substring(0, 1)
|
||||
let pass = line[2]
|
||||
let match = pass.match(new RegExp(char, 'g'))
|
||||
if (!match) { continue }
|
||||
let matches = match.length
|
||||
if (matches < lim[0] || matches > lim[1]) { continue }
|
||||
console.log(pass)
|
||||
count++
|
||||
}
|
||||
console.log(count)
|
18
2020/02/part2.js
Normal file
18
2020/02/part2.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
const fs = require('fs');
|
||||
|
||||
let data = fs.readFileSync('input.txt', 'utf-8');
|
||||
let lines = data.split('\n').map(x => x.split(" "));
|
||||
let count = 0
|
||||
for ( let i = 0; i < lines.length; i++){
|
||||
let line = lines[i]
|
||||
let lim = line[0].split("-")
|
||||
let char = line[1].substring(0,1)
|
||||
let pass = line[2]
|
||||
let one = (pass.charAt(lim[0]-1) == char)
|
||||
let other = (pass.charAt(lim[1]-1) == char)
|
||||
if (one^other){
|
||||
console.log(pass)
|
||||
count++
|
||||
}
|
||||
}
|
||||
console.log(count)
|
Loading…
Add table
Add a link
Reference in a new issue