Created
December 4, 2019 05:12
-
-
Save bluepichu/309d47ea6755d28add8ea4bc081d8658 to your computer and use it in GitHub Desktop.
Advent of Code 2019 day 4 solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# input | |
lo = 372037 | |
hi = 905157 | |
ans = 0 | |
def test(s): | |
c = 0 | |
d = 0 | |
for i in range(5): | |
if s[i] > s[i+1]: | |
return False | |
elif s[i] == s[i+1]: | |
d += 1 | |
else: | |
if d == 1: # change to `d > 0` for part 1 | |
c += 1 | |
d = 0 | |
if d == 1: # change to `d > 0` for part 1 | |
c += 1 | |
return c > 0 | |
for i in range(lo, hi+1): | |
s = str(i) | |
if test(s): | |
ans += 1 | |
print(ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment