|
|
@ -8,20 +8,18 @@ inp = get_input(4) |
|
|
|
|
|
|
|
|
|
|
|
newPort = "\n\n" |
|
|
|
newPort = "\n\n" |
|
|
|
|
|
|
|
|
|
|
|
validPara = ["byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid", "cid"] # NOTE excluade cid later |
|
|
|
specialPara = ["byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"] |
|
|
|
|
|
|
|
eyecolors = "amb blu brn gry grn hzl oth".split(" ") |
|
|
|
|
|
|
|
|
|
|
|
ports = inp.split(newPort) |
|
|
|
ports = inp.split(newPort) |
|
|
|
|
|
|
|
|
|
|
|
def getPorts(port): |
|
|
|
def getPortsParam(port): |
|
|
|
port = port.replace("\n", " ") |
|
|
|
port = port.replace("\n", " ") |
|
|
|
|
|
|
|
|
|
|
|
paras = port.split(" ") |
|
|
|
paras = port.split(" ") |
|
|
|
out = [] |
|
|
|
out = [] |
|
|
|
#print("####", paras) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for p in paras: |
|
|
|
for p in paras: |
|
|
|
#print("#",p) |
|
|
|
|
|
|
|
if( p != "" ): |
|
|
|
if( p != "" ): |
|
|
|
para = re.match("(\w+):", p).groups()[0] |
|
|
|
para = re.match("(\w+):", p).groups()[0] |
|
|
|
out.append(para) |
|
|
|
out.append(para) |
|
|
@ -31,7 +29,7 @@ def getPorts(port): |
|
|
|
def checkPorts(ports, valids, ignore:list = ["cid"]): |
|
|
|
def checkPorts(ports, valids, ignore:list = ["cid"]): |
|
|
|
paras = [] |
|
|
|
paras = [] |
|
|
|
for p in ports: |
|
|
|
for p in ports: |
|
|
|
paras.append(getPorts(p)) |
|
|
|
paras.append(getPortsParam(p)) |
|
|
|
|
|
|
|
|
|
|
|
count = 0 |
|
|
|
count = 0 |
|
|
|
|
|
|
|
|
|
|
@ -43,15 +41,7 @@ def checkPorts(ports, valids, ignore:list = ["cid"]): |
|
|
|
|
|
|
|
|
|
|
|
return count |
|
|
|
return count |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getPortsValParam(port): |
|
|
|
|
|
|
|
|
|
|
|
specialPara = ["byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"] |
|
|
|
|
|
|
|
# pcheck = checkPorts(ports, specialPara) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# print(pcheck) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getPortsYes(port): |
|
|
|
|
|
|
|
port = port.replace("\n", " ") |
|
|
|
port = port.replace("\n", " ") |
|
|
|
|
|
|
|
|
|
|
|
paras = port.split(" ") |
|
|
|
paras = port.split(" ") |
|
|
@ -65,9 +55,6 @@ def getPortsYes(port): |
|
|
|
|
|
|
|
|
|
|
|
return out |
|
|
|
return out |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
eyecolors = "amb blu brn gry grn hzl oth".split(" ") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def checkVal(par, val): |
|
|
|
def checkVal(par, val): |
|
|
|
valid = True |
|
|
|
valid = True |
|
|
|
if( par == "byr" ): |
|
|
|
if( par == "byr" ): |
|
|
@ -131,29 +118,21 @@ def checkPortsVALID( ports, paras ): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for port in ports: |
|
|
|
for port in ports: |
|
|
|
ps = getPortsYes(port) |
|
|
|
ps = getPortsValParam(port) |
|
|
|
parasPort = getPorts(port) |
|
|
|
parasPort = getPortsParam(port) |
|
|
|
portsValid = True |
|
|
|
portsValid = True |
|
|
|
portsValid2 = True |
|
|
|
portsValid2 = True |
|
|
|
|
|
|
|
|
|
|
|
#for para in ps2: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
check2 = all(p in parasPort for p in paras) |
|
|
|
check2 = all(p in parasPort for p in paras) |
|
|
|
if( not check2 ): |
|
|
|
if( not check2 ): |
|
|
|
print("FALSE:", parasPort, "####", paras ) |
|
|
|
|
|
|
|
portsValid2 = False |
|
|
|
portsValid2 = False |
|
|
|
|
|
|
|
|
|
|
|
for p in ps: |
|
|
|
for p in ps: |
|
|
|
if(p != ""): |
|
|
|
if(p != ""): |
|
|
|
param = p[0] |
|
|
|
param = p[0] |
|
|
|
val = p[1] |
|
|
|
val = p[1] |
|
|
|
#print("|<", param, val) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
check1 = checkVal(param, val) |
|
|
|
check1 = checkVal(param, val) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#print(check2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(check1 == False): |
|
|
|
if(check1 == False): |
|
|
|
portsValid = False |
|
|
|
portsValid = False |
|
|
|
|
|
|
|
|
|
|
@ -161,11 +140,10 @@ def checkPortsVALID( ports, paras ): |
|
|
|
if( portsValid == True and portsValid2 == True ): |
|
|
|
if( portsValid == True and portsValid2 == True ): |
|
|
|
count += 1 |
|
|
|
count += 1 |
|
|
|
|
|
|
|
|
|
|
|
print("\nnewport") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return count |
|
|
|
return count |
|
|
|
|
|
|
|
|
|
|
|
check1 = checkPorts(ports, specialPara) |
|
|
|
check1 = checkPorts(ports, specialPara) |
|
|
|
pcheck2 = checkPortsVALID( ports, specialPara ) |
|
|
|
pcheck2 = checkPortsVALID( ports, specialPara ) |
|
|
|
|
|
|
|
|
|
|
|
print("Part2:", check1, pcheck2) |
|
|
|
print("Part1:", check1) |
|
|
|
|
|
|
|
print("Part2:", pcheck2) |
|
|
|