-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02.py
44 lines (30 loc) · 1007 Bytes
/
02.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from aoc.utilities.fetch import get_input
from aoc.utilities.decorators import solution
from collections import Counter
@solution
def solve_first(input):
print(Counter(map(check, input)).get(True, 0))
@solution
def solve_second(input):
def brute_check(line):
n = len(line)
candidates = [list(line) for _ in range(n)]
for can, i in zip(candidates, range(n)):
can.pop(i)
return any(map(check, candidates))
print(Counter(map(brute_check, input)).get(True, 0))
def check(line):
def f(line):
for i in range(1, len(line)):
if not (1 <= (line[i] - line[i - 1]) <= 3):
return False
return True
def g(line):
for i in range(1, len(line)):
if not (1 <= (line[i - 1] - line[i]) <= 3):
return False
return True
return f(line) or g(line)
data = [list(map(int, line.split())) for line in get_input(2).splitlines()]
solve_first(data)
solve_second(data)