Day 4 part 2
This commit is contained in:
parent
8ca85d8ea5
commit
a1bd5e5e80
|
@ -13,10 +13,11 @@ def is_valid(value):
|
||||||
|
|
||||||
def has_adjacents(value):
|
def has_adjacents(value):
|
||||||
digits = [get_digit(value, index) for index in range(6)]
|
digits = [get_digit(value, index) for index in range(6)]
|
||||||
|
adjacent_digits = []
|
||||||
for i in range(6 - 1):
|
for i in range(6 - 1):
|
||||||
if digits[i] == digits[i + 1]:
|
if digits[i] == digits[i + 1]:
|
||||||
return True
|
adjacent_digits.append(digits[i])
|
||||||
return False
|
return any(sum(a == d for d in adjacent_digits) == 1 for a in set(adjacent_digits))
|
||||||
|
|
||||||
def is_increasing(value):
|
def is_increasing(value):
|
||||||
digits = [get_digit(value, index) for index in range(6)]
|
digits = [get_digit(value, index) for index in range(6)]
|
||||||
|
@ -28,5 +29,6 @@ def is_increasing(value):
|
||||||
def get_digit(value, index):
|
def get_digit(value, index):
|
||||||
return int(str(value)[index])
|
return int(str(value)[index])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue