Skip to content

Instantly share code, notes, and snippets.

@bluepichu
Created December 4, 2019 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bluepichu/309d47ea6755d28add8ea4bc081d8658 to your computer and use it in GitHub Desktop.
Save bluepichu/309d47ea6755d28add8ea4bc081d8658 to your computer and use it in GitHub Desktop.
Advent of Code 2019 day 4 solution
# 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