-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuzzle_10_b.py
47 lines (40 loc) · 939 Bytes
/
puzzle_10_b.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
import sys
from collections import deque
jolts = [0]
def insert_jolt(jolt):
if len(jolts) == 1:
jolts.insert(1,jolt)
return
for i in range(1,len(jolts)):
if jolts[i] > jolt:
jolts.insert(i,jolt)
return
jolts.insert(len(jolts),jolt)
for line in sys.stdin:
line = line.strip()
insert_jolt(int(line))
print jolts
E = {}
for i in range(len(jolts) -1):
for j in range(i+1,i+4):
if j >= len(jolts):
break
if jolts[j] - jolts[i] <=3:
fr = jolts[i]
if fr not in E:
E[fr] = []
to = jolts[j]
E[fr].append(to)
numarrs = {}
def num_arrs(x):
num = 0
if x not in E:
return 1
for item in E.get(x,[]):
if numarrs.has_key(item):
num += numarrs[item]
else:
num += num_arrs(item)
numarrs[x] = num
return num
print num_arrs(0)