mirror of
https://github.com/Crocmagnon/advent-of-code.git
synced 2024-11-24 15:38:10 +01:00
Solve day 4
This commit is contained in:
parent
88f0223b6d
commit
6df229bfe5
1 changed files with 23 additions and 0 deletions
23
2019/day04-password.py
Normal file
23
2019/day04-password.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
def matches(num):
|
||||
previous = ""
|
||||
two_adjacents = False
|
||||
for digit in str(num):
|
||||
if digit == previous:
|
||||
two_adjacents = True
|
||||
if digit < previous:
|
||||
return 0
|
||||
previous = digit
|
||||
|
||||
return 1 if two_adjacents else 0
|
||||
|
||||
|
||||
def main():
|
||||
count = 0
|
||||
for password in range(271973, 785961 + 1):
|
||||
count += matches(password)
|
||||
|
||||
print(count)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in a new issue