oh dear
This commit is contained in:
		
							
								
								
									
										6
									
								
								04/1.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								04/1.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					sections = open("input", "r").read().split("\n\n")
 | 
				
			||||||
 | 
					sections = [section.replace("\n", " ") for section in sections]
 | 
				
			||||||
 | 
					passports = [dict([s.split(":") for s in section.split(" ") if s]) for section in sections]
 | 
				
			||||||
 | 
					required = {"byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"}
 | 
				
			||||||
 | 
					valid = [p for p in passports if len(required.difference(p.keys())) == 0]
 | 
				
			||||||
 | 
					print(len(valid))
 | 
				
			||||||
							
								
								
									
										15
									
								
								04/2.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								04/2.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					sections = open("input", "r").read().split("\n\n")
 | 
				
			||||||
 | 
					sections = [section.replace("\n", " ") for section in sections]
 | 
				
			||||||
 | 
					passports = [dict([s.split(":") for s in section.split(" ") if s]) for section in sections]
 | 
				
			||||||
 | 
					import re
 | 
				
			||||||
 | 
					validators = {
 | 
				
			||||||
 | 
					        "byr": ("[0-9]{4}$", lambda a: 1920 <= int(a) <= 2002),
 | 
				
			||||||
 | 
					        "iyr": ("[0-9]{4}$", lambda a: 2010 <= int(a) <= 2020),
 | 
				
			||||||
 | 
					        "eyr": ("[0-9]{4}$", lambda a: 2020 <= int(a) <= 2030),
 | 
				
			||||||
 | 
					        "hgt": ("[0-9]+(in|cm)$", lambda a: 150 <= int(a.replace("cm", "")) <= 193 if "cm" in a else 59 <= int(a.replace("in", "")) <= 76),
 | 
				
			||||||
 | 
					        "hcl": ("#[0-9a-f]{6}$", lambda a: True),
 | 
				
			||||||
 | 
					        "ecl": ("(amb|blu|brn|gry|grn|hzl|oth)$", lambda a: True),
 | 
				
			||||||
 | 
					        "pid": ("[0-9]{9}$", lambda a: True),
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					valid = [p for p in passports if all([k in p and re.match(r, p[k]) and v(p[k]) for (k, (r, v)) in validators.items()])]
 | 
				
			||||||
 | 
					print(len(valid))
 | 
				
			||||||
							
								
								
									
										13
									
								
								04/test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								04/test
									
									
									
									
									
										Normal 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
 | 
				
			||||||
		Reference in New Issue
	
	Block a user