This commit is contained in:
Deni 2020-12-05 10:59:40 +01:00
parent 84559867ff
commit 6cb71da6e5
5 changed files with 1234 additions and 0 deletions

Binary file not shown.

46
2020/04/04.py Executable file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env python3
# Advent Of Code 2020 - Day 4
"""
ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
byr:1937 iyr:2017 cid:147 hgt:183cm
iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
hcl:#cfa07d byr:1929
hcl:#ae17e1 iyr:2013
eyr:2024
ecl:brn pid:760753108 byr:1931
hgt:179cm
hcl:#cfa07d eyr:2025 pid:166559648
iyr:2011 ecl:brn hgt:59in
"""
filename = "input.txt"
import re
def parsePassport(passport):
passportDict = dict()
for item in re.split(' |\n', passport):
passportDict[item.split(':')[0]] = item.split(':')[1]
return passportDict
def validatePassport(passport):
return all(key in passport for key in ["byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"])
with open(filename) as f:
data = [(x.strip()) for x in f.read().split("\n\n")]
count = 0
for passport in data:
if validatePassport(parsePassport(passport)):
count = count + 1
print (count)

46
2020/04/04b.py Executable file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env python3
# Advent Of Code 2020 - Day 4
"""
ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
byr:1937 iyr:2017 cid:147 hgt:183cm
iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
hcl:#cfa07d byr:1929
hcl:#ae17e1 iyr:2013
eyr:2024
ecl:brn pid:760753108 byr:1931
hgt:179cm
hcl:#cfa07d eyr:2025 pid:166559648
iyr:2011 ecl:brn hgt:59in
"""
filename = "input.txt"
import re
def parsePassport(passport):
passportDict = dict()
for item in re.split(' |\n', passport):
passportDict[item.split(':')[0]] = item.split(':')[1]
return passportDict
def validatePassport(passport):
return all(key in passport for key in ["byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"])
with open(filename) as f:
data = [(x.strip()) for x in f.read().split("\n\n")]
count = 0
for passport in data:
if validatePassport(parsePassport(passport)):
count = count + 1
print (count)

1129
2020/04/input.txt Normal file

File diff suppressed because it is too large Load Diff

13
2020/04/inputShort.txt Normal file
View File

@ -0,0 +1,13 @@
ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
byr:1937 iyr:2017 cid:147 hgt:183cm
iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
hcl:#cfa07d byr:1929
hcl:#ae17e1 iyr:2013
eyr:2024
ecl:brn pid:760753108 byr:1931
hgt:179cm
hcl:#cfa07d eyr:2025 pid:166559648
iyr:2011 ecl:brn hgt:59in