2020 day 4
This commit is contained in:
parent
77b47a86e5
commit
70f1c47d12
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
build
|
build
|
||||||
frames
|
frames
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.vscode
|
.vscode
|
||||||
|
.replit
|
1146
2020/04/input.txt
Normal file
1146
2020/04/input.txt
Normal file
File diff suppressed because it is too large
Load diff
18
2020/04/part1.js
Normal file
18
2020/04/part1.js
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const data = fs.readFileSync('input.txt', 'utf-8');
|
||||||
|
const passports = data.split('\n\n').map(p=>p.split(/[\n\s]/g).map(e=>e.split(":")));
|
||||||
|
// requried fields
|
||||||
|
const req = ['ecl', 'eyr', 'hcl', 'byr', 'iyr', 'pid', 'hgt'];
|
||||||
|
|
||||||
|
let validamt = 0
|
||||||
|
passports.forEach(passport=>{
|
||||||
|
for(let i = 0; i < req.length; i++){
|
||||||
|
if(!passport.find(entry => entry[0] == req[i])){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
validamt++
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(validamt)
|
41
2020/04/part2.js
Normal file
41
2020/04/part2.js
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const data = fs.readFileSync('input.txt', 'utf-8');
|
||||||
|
const passports = data.split('\n\n').map(p=>p.split(/[\n\s]/g).map(e=>e.split(":")));
|
||||||
|
|
||||||
|
// requried fields
|
||||||
|
const req = [
|
||||||
|
["byr", (v => !(v.length != 4 || v<1920 || v>2002))],
|
||||||
|
["iyr", (v => !(v.length != 4 || v<2010 || v>2020))],
|
||||||
|
["eyr", (v => !(v.length != 4 || v<2020 || v>2030))],
|
||||||
|
["hgt", (v => {
|
||||||
|
n = parseInt(v)
|
||||||
|
if (v.endsWith('cm')){
|
||||||
|
if (n<150 || n>193) {return false}
|
||||||
|
} else if ( v.endsWith('in')) {
|
||||||
|
if (n<59 || n>76) {return false}
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})],
|
||||||
|
["hcl", (v => !!v.match(/^#[0-9a-f]{6}/))],
|
||||||
|
["ecl", (v => !!['amb','blu','brn','gry','grn','hzl','oth'].find(e => e==v))],
|
||||||
|
["pid", (v => !!v.match(/^[0-9]{9}$/))]
|
||||||
|
];
|
||||||
|
|
||||||
|
let validamt = 0
|
||||||
|
passports.forEach(passport=>{
|
||||||
|
for(let i = 0; i < req.length; i++){
|
||||||
|
result = passport.find(entry => entry[0] == req[i][0])
|
||||||
|
if(!result) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if(!req[i][1](result[1])){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
validamt++
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(validamt)
|
|
@ -44,6 +44,7 @@ if (advent) {
|
||||||
1. [:star: :star:](https://adventofcode.com/2020/day/1 "see puzzle")
|
1. [:star: :star:](https://adventofcode.com/2020/day/1 "see puzzle")
|
||||||
2. [:star: :star:](https://adventofcode.com/2020/day/2 "see puzzle")
|
2. [:star: :star:](https://adventofcode.com/2020/day/2 "see puzzle")
|
||||||
3. [:star: :star:](https://adventofcode.com/2020/day/3 "see puzzle")
|
3. [:star: :star:](https://adventofcode.com/2020/day/3 "see puzzle")
|
||||||
|
4. [:star: :star:](https://adventofcode.com/2020/day/4 "see puzzle")
|
||||||
|
|
||||||
## Languages Used
|
## Languages Used
|
||||||
* Python
|
* Python
|
||||||
|
|
Loading…
Reference in a new issue