DEV Community

Discussion on: Advent of Code: 2020 Day 04

Collapse
 
cnille profile image
Christopher Nilsson

Thanks for the tip on highlighting! :D

An else wouldn't let the flow through to validate the Validate strings/enums, so would have to reorder the code then. Could you share what the case is in your input that I don't catch? :)

Collapse
 
gubesch profile image
Christian Gubesch

Hello Christopher,
I can only tell that your solution is off by 1 compared to mine at my input file.

I use this code right here:

def isValidPuzzle2(self):
        attributes = vars(self)
        if len(attributes) == 8 or (len(attributes) == 7 and "cid" not in attributes):
            if not (1920 <= int(self.byr) <= 2002):
                return False
            if not (2010 <= int(self.iyr) <= 2020):
                return False
            if not (2020 <= int(self.eyr) <= 2030):
                return False
            if "cm" in self.hgt:
                if not 150 <= int(self.hgt[:-2]) <= 193:
                    return False
            elif "in" in self.hgt:
                if not 59 <= int(self.hgt[0:-2]) <= 76:
                    return False
            else:
                return False
            patternHairColor = re.compile("^#[a-f0-9]{6}$")
            if not patternHairColor.match(self.hcl):
                return False
            eyeColors = ["amb","blu","brn","gry","grn","hzl","oth"]
            if self.ecl not in eyeColors:
                return False
            patternPid = re.compile("^\d{9}$")
            if not patternPid.match(self.pid):
                return False
            return True
        else:
            return False
Enter fullscreen mode Exit fullscreen mode

My console output:

PS C:\Users\christian.gubesch\Documents\DEV\AdventOfCode\Python\Day4> python.exe .\day4_devto.py
Solution part 1: 241
Solution part 2: 185
PS C:\Users\christian.gubesch\Documents\DEV\AdventOfCode\Python\Day4> python.exe .\day4.py      
Puzzle 1: 242
Puzzle 2: 186
Enter fullscreen mode Exit fullscreen mode

Maybe I have time tomorrow to find the specific case for you.

Cheers ;)