From abb014cf52a45266bb9f85f7edbbbb2d4521fd7b Mon Sep 17 00:00:00 2001 From: cato447 Date: Mon, 16 Aug 2021 17:21:54 +0200 Subject: [PATCH] Cleared days 1, 2, 3 and 4 --- .DS_Store | Bin 0 -> 6148 bytes Scripts/.DS_Store | Bin 0 -> 6148 bytes Scripts/Day 1.py | 19 + Scripts/Day 2.py | 26 + Scripts/Day 3.py | 39 ++ Scripts/Day 4.py | 90 ++++ Scripts/Day 5.py | 0 Scripts/res/.DS_Store | Bin 0 -> 6148 bytes Scripts/res/day1.txt | 200 ++++++++ Scripts/res/day2.txt | 1000 +++++++++++++++++++++++++++++++++++++ Scripts/res/day3.txt | 323 ++++++++++++ Scripts/res/day4.txt | 1102 +++++++++++++++++++++++++++++++++++++++++ 12 files changed, 2799 insertions(+) create mode 100644 .DS_Store create mode 100644 Scripts/.DS_Store create mode 100644 Scripts/Day 1.py create mode 100644 Scripts/Day 2.py create mode 100644 Scripts/Day 3.py create mode 100644 Scripts/Day 4.py create mode 100644 Scripts/Day 5.py create mode 100644 Scripts/res/.DS_Store create mode 100644 Scripts/res/day1.txt create mode 100644 Scripts/res/day2.txt create mode 100644 Scripts/res/day3.txt create mode 100644 Scripts/res/day4.txt diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..98910fbf4ede7060cf20ed8e9499165e2148d9e8 GIT binary patch literal 6148 zcmeHK&2G~`5S~p_Y6~H9Kq8k)d*K$Ugz{4kNNz|EIUpg7-~gz#m?%5pCvt_77=++#)gmPH^On&6=_({ zI#B2_p3xp{(GexXY$e+{{znFQ?R> zX+k9x!)!TQZ2mnvu8N5r`y`%ZX;F5&r=qdeT)(#A`S{)N-i3#%3d^XR75!-XhI`MW z@-VjcOQo_iJBnYW<7&Tk>#54iD9y)HU7RLkq`ZBd=83BMYL+L39w#&bp2y#BwdeEg z2ah_kx6@s8zo8dqlXZO%*9n_JInJ7J5r{CQKvOF06+@VE z_@&JYEY=21ISG6D5O!u^Zzw{~j`5{VClMHQtz*D3aGrrR({1tjzxU_+|M?=%eK8lgcM{ygf1%Al}FtAt~ga_h21T+n< KaSZ%Z27Uswv3;cg literal 0 HcmV?d00001 diff --git a/Scripts/.DS_Store b/Scripts/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0c0ee072707cb8ab6f7f6861cf4d11fde36e0131 GIT binary patch literal 6148 zcmeHKF;2rk5S$|^EYYN-yca~u501zb)O-K}bdiEU6zSaY9G(a>y9=^oXerRHv^#fu zvp#zY?;U`$eSO#fD*zo`h&P3~X(BlqARE+9( z`@@cFda+CT`ooMPV1Z{m;zhfRSnnq+qh?42Qh`(;6-WhAffEJTvt`}6W5!e<6-WiX z70~~o(uFN>aI{|sgO2Z7UkYU$+g*ZKW8MM>N3PI{mlD0S#1*4>IrBAmEpTx3aunN{ z&xxH&+)#?`&U`gGN^{JZ3Zw#41r|PCssCTmf4Topi*l9 len(lines[index][0])-3: + column -= len(lines[index][0]) + countTrees.append(trees) + return np.prod(countTrees) + + +print(f"First solution: {first()}") +print(f"Second solution: {second()}") \ No newline at end of file diff --git a/Scripts/Day 4.py b/Scripts/Day 4.py new file mode 100644 index 0000000..ad76a01 --- /dev/null +++ b/Scripts/Day 4.py @@ -0,0 +1,90 @@ +from typing import ValuesView +import numpy as np +import regex as re + +def first(): + with open("/Users/cato447/Code/Cato447/AdventOfCode_2020/Scripts/res/day4.txt") as f: + lines = [line.replace("\n", "").split() for line in f.readlines()] + tempLines = [] + passports = [] + for line in lines: + if len(line) > 0: + tempLines.extend(line) + else: + passports.append(tempLines) + tempLines = [] + passports.append(tempLines) + + validPassports = 0 + for passport in passports: + if len(passport) == 8 or (len(passport) == 7 and not any('cid:' in string for string in passport)): + validPassports += 1 + return validPassports + +def second(): + with open("/Users/cato447/Code/Cato447/AdventOfCode_2020/Scripts/res/day4.txt") as f: + lines = [line.replace("\n", "").split() for line in f.readlines()] + tempLines = [] + passports = [] + for line in lines: + if len(line) > 0: + tempLines.extend(line) + else: + passports.append(dict([map(str.strip, passport.split(':')) for passport in tempLines])) + tempLines = [] + passports.append(dict([map(str.strip, passport.split(':')) for passport in tempLines])) + + validPassports = 0 + for passport in passports: + if len(passport) == 8 or (len(passport.keys()) == 7 and 'cid' not in passport.keys()): + if validatePassport(passport): + validPassports += 1 + else: + print(passport) + + return validPassports + +def validatePassport(passport): + boundaries = { + 'byr' : [1920, 2002], + 'iyr' : [2010, 2020], + 'eyr' : [2020, 2030], + 'hgt' : {'cm' : [150, 193], 'in' : [59, 73]}, + 'hcl' : '^#[a-f0-9]{6}', + 'ecl' : ['amb', 'blu', 'brn', 'gry', 'grn', 'hzl', 'oth'], + 'pid' : '[0-9]{9}' + } + valid = True + for key, value in passport.items(): + if key != 'cid': + if key == 'hgt': + try: + bounds = boundaries[key][value[-2:]] + if not bounds[0] <= int(value[:-2]) <= bounds[1]: + valid = False + break + except: # height has no specified unit + valid = False + break + elif key in ['byr', 'iyr', 'eyr']: + bounds = boundaries[key] + try: + if not bounds[0] <= int(value) <= bounds[1]: + valid = False + break + except: + valid = False + break + elif key == 'ecl': + if not value in boundaries[key]: + valid = False + break + elif key in ['hcl', 'pid']: # match regex + if not re.match(boundaries[key], value): + valid = False + break + return valid + +print(f"First solution: {first()}") +# Real solution is second() +1. Has to do something with parsing the data +print(f"Second solution: {second()}") \ No newline at end of file diff --git a/Scripts/Day 5.py b/Scripts/Day 5.py new file mode 100644 index 0000000..e69de29 diff --git a/Scripts/res/.DS_Store b/Scripts/res/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8be7ed9b9fbdd64d7804c2ec45a17d6cbc498824 GIT binary patch literal 6148 zcmeHKJ5EC}5S)b+L1|t|=@THq39Kj-)LZ~U%1CK~1l_AR7dH#DA0fgE5)BQSmDXdg zcWilzw{HR1@_BO&3;^bIN4)tkHQ#ri*jYu4Naq~AO$`Z@b5#TJNCjcF+Lp} zq6Hw%7!Kn+dI@6l0I?U2iHy)Jsl=pOwHTIk##`m}!Z9)Fu(+A$)Xi2MipA}Ww@8Qe zM2%8F3LGnNp3A}O|1JH8{{NVyl@yQy|4IRyt?pM#KB;Q!