-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc23_day12_1.py
executable file
·55 lines (41 loc) · 1.16 KB
/
aoc23_day12_1.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
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
def make_pattern(line):
i = 0
cmp = []
while i < len(line):
if line[i] == '.':
i += 1
continue
cnt = 0
while i < len(line) and line[i] == '#':
cnt += 1
i += 1
cmp.append(cnt)
return cmp
def test_make_pattern():
assert make_pattern('#.#.###') == [1, 1, 3]
assert make_pattern('#....######..#####.') == [1, 6, 5]
assert make_pattern('.###.##....#') == [3, 2, 1]
def brute_force(current, left, target):
if left == '':
return int(make_pattern(current) == target)
if left[0] == '?':
res = 0
res += brute_force(current + '.', left[1:], target)
res += brute_force(current + '#', left[1:], target)
return res
else:
return brute_force(current + left[0], left[1:], target)
def main():
res = 0
while True:
try:
line, nums = input().split()
nums = [int(item) for item in nums.split(',')]
count = brute_force('', line, nums)
res += count
except EOFError:
break
print(res)
if __name__ == '__main__':
main()