This time I went to bed early and woke up at 4am to do the problem. Oddly, I think that will work better for me! And I found this problem much easier than Day 3.
I had the same issue with the wording of Part Two, so thank you for the interpretive hint.
I have a tendency to write very low-level implementations (without including libs)...partly because I'm not all that familiar with what's available in the Python ecosystem, and partly because I kind of like controlling the nitty gritty!
# Part One: How many passwords meet the required criteria?
defdetermineIfCriteriaMetPartOne(num):digits=[int(x)forxinstr(num)]#print (digits)
iflen(digits)!=6:returnFalsefoundDoubleDigit=FalsepreviousDigit=-1foriindigits:ifi<previousDigit:returnFalseifi==previousDigit:foundDoubleDigit=TruepreviousDigit=i#if foundDoubleDigit:
#print (num)
returnfoundDoubleDigit# Part Two: How many passwords meet the required criteria?
defdetermineIfCriteriaMetPartTwo(num):digits=[int(x)forxinstr(num)]#print (digits)
iflen(digits)!=6:returnFalserepeatedDigitCount=1foundDoubleDigit=FalsepreviousDigit=-1foriindigits:ifi<previousDigit:returnFalseelifi==previousDigit:repeatedDigitCount+=1elifi>previousDigit:# we found an exact sequence of 2. Mark it, then reset
ifrepeatedDigitCount==2:foundDoubleDigit=TruerepeatedDigitCount=1previousDigit=i# In case the double digit is at the end
ifrepeatedDigitCount==2:foundDoubleDigit=TruereturnfoundDoubleDigit# These were unique to the instance of my puzzle
myGivenLowNUmber=128392myGivenHighNumber=643281counter=0foriinrange(128392,643281+1):ifdetermineIfCriteriaMetPartOne(i):counter+=1print("Part One: %i"%counter)counter=0foriinrange(128392,643281+1):ifdetermineIfCriteriaMetPartTwo(i):counter+=1print("Part Two: %i"%counter)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This time I went to bed early and woke up at 4am to do the problem. Oddly, I think that will work better for me! And I found this problem much easier than Day 3.
I had the same issue with the wording of Part Two, so thank you for the interpretive hint.
I have a tendency to write very low-level implementations (without including libs)...partly because I'm not all that familiar with what's available in the Python ecosystem, and partly because I kind of like controlling the nitty gritty!