mirror of
https://github.com/Xevion/advent-of-code.git
synced 2025-12-07 22:06:20 -06:00
day 4 2019 part 1 & part 2
This commit is contained in:
1
2019/day-4/input
Normal file
1
2019/day-4/input
Normal file
@@ -0,0 +1 @@
|
|||||||
|
359282-820401
|
||||||
27
2019/day-4/python/main.py
Normal file
27
2019/day-4/python/main.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
|
||||||
|
PATH = os.path.join(sys.path[0], '..', 'input')
|
||||||
|
DATA = list(map(int, open(PATH, 'r').read().split('-')))
|
||||||
|
|
||||||
|
def criteria(n):
|
||||||
|
digits = list(map(int, list(str(n))))
|
||||||
|
repeats = False
|
||||||
|
prev = digits[0]
|
||||||
|
|
||||||
|
for digit in digits[1:]:
|
||||||
|
if prev == digit:
|
||||||
|
repeats = True
|
||||||
|
if prev > digit:
|
||||||
|
return False
|
||||||
|
prev = digit
|
||||||
|
return repeats
|
||||||
|
|
||||||
|
def rerepeats(n):
|
||||||
|
return 2 in [len(m[0]) for m in re.finditer(r'(\d)\1+', str(n))]
|
||||||
|
|
||||||
|
passwords = [x for x in range(DATA[0], DATA[1]) if criteria(x)]
|
||||||
|
print(len(passwords))
|
||||||
|
passwords = [x for x in passwords if rerepeats(x)]
|
||||||
|
print(len(passwords))
|
||||||
Reference in New Issue
Block a user