-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsim6.py
More file actions
33 lines (28 loc) · 800 Bytes
/
Copy pathsim6.py
File metadata and controls
33 lines (28 loc) · 800 Bytes
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
def get_poly(s):
c1, c0 = 0, 1
for _ in range(s):
c1, c0 = c0 - c1, -2*c1
return c1, c0
# Find all lonely subsets of {0, 1, ..., 13}
def get_lonely(k):
res = []
def dfs(i, current):
if i >= k:
res.append(current)
return
# Option 1: don't include i
dfs(i+1, current)
# Option 2: include i
if not current or i - current[-1] >= 3:
dfs(i+1, current + [i])
dfs(0, [])
return res
lonely_sets = get_lonely(14)
sad_integers = set()
for S in lonely_sets:
if not S: continue
c1_sum = sum(get_poly(s)[0] for s in S)
c0_sum = sum(get_poly(s)[1] for s in S)
if c1_sum == 0 and c0_sum > 0:
sad_integers.add((c0_sum, tuple(S)))
print(sorted(list(sad_integers)))