Browse Source

last update

master
Paul Walko 9 months ago
parent
commit
4438bc948f
  1. 34
      10/10.py
  2. 0
      10/answer.log
  3. 11
      10/e1.txt
  4. 31
      10/e2.txt
  5. 103
      10/input.txt
  6. 14
      10/q.txt
  7. 40
      9/9.py
  8. 20
      9/e.txt
  9. 1000
      9/input.txt

34
10/10.py

@ -0,0 +1,34 @@
#!/usr/bin/env python3
import networkx as nx
import sys
L = []
with open(sys.argv[1], 'r') as f:
L = f.readlines()
L = [int(x.strip()) for x in L]
L.sort()
# part 1
jdiff = {'1': 0, '2': 0, '3': 0}
for i in range(len(L)):
if i == 0:
jdiff[str(L[i])] += 1
else:
jdiff[str(L[i] - L[i - 1])] += 1
jdiff['3'] += 1
#print(jdiff['1'] * jdiff['3'])
# part 2
G = nx.DiGraph()
L.insert(0, 0)
L.append(L[-1] + 3)
for i in range(len(L)):
if i < len(L) - 1 and L[i + 1] in [L[i] + 1, L[i] + 2, L[i] + 3]:
G.add_edge(L[i], L[i + 1])
if i < len(L) - 2 and L[i + 2] in [L[i] + 1, L[i] + 2, L[i] + 3]:
G.add_edge(L[i], L[i + 2])
if i < len(L) - 3 and L[i + 3] in [L[i] + 1, L[i] + 2, L[i] + 3]:
G.add_edge(L[i], L[i + 3])
print(len(list(nx.all_simple_paths(G, L[0], L[-1]))))

0
10/answer.log

11
10/e1.txt

@ -0,0 +1,11 @@
16
10
15
5
1
11
7
19
6
12
4

31
10/e2.txt

@ -0,0 +1,31 @@
28
33
18
42
31
14
46
20
48
47
24
23
49
45
19
38
39
11
1
32
25
35
8
17
7
9
4
2
34
10
3

103
10/input.txt

@ -0,0 +1,103 @@
149
87
67
45
76
29
107
88
4
11
118
160
20
115
130
91
144
152
33
94
53
148
138
47
104
121
112
116
99
105
34
14
44
137
52
2
65
141
140
86
84
81
124
62
15
68
147
27
106
28
69
163
97
111
162
17
159
122
156
127
46
35
128
123
48
38
129
161
3
24
60
58
155
22
55
75
16
8
78
134
30
61
72
54
41
1
59
101
10
85
139
9
98
21
108
117
131
66
23
77
7
100
51

14
10/q.txt

@ -0,0 +1,14 @@
[0, 1, 4, 5, 6, 7, 10, 11, 12, 15, 16, 19, 22]
[0, 1, 4, 5, 6, 7, 10, 12, 15, 16, 19, 22]
[0, 1, 4, 5, 7, 10, 11, 12, 15, 16, 19, 22]
[0, 1, 4, 5, 7, 10, 12, 15, 16, 19, 22]
[0, 1, 4, 6, 5, 7, 10, 11, 12, 15, 16, 19, 22]
[0, 1, 4, 6, 5, 7, 10, 12, 15, 16, 19, 22]
[0, 1, 4, 6, 7, 10, 11, 12, 15, 16, 19, 22]
[0, 1, 4, 6, 7, 10, 12, 15, 16, 19, 22]
[0, 1, 4, 7, 10, 11, 12, 15, 16, 19, 22]
[0, 1, 4, 7, 10, 12, 15, 16, 19, 22]

40
9/9.py

@ -0,0 +1,40 @@
#!/usr/bin/env python3
from random import randrange
import sys
L = []
with open(sys.argv[1], 'r') as f:
L = f.readlines()
L = [int(x.strip()) for x in L]
def validsum(L, n):
for i in L:
for ii in L:
if i + ii == n:
return True
return False
# part 1
p = 25
ans = 0
for i in range(len(L)):
if i < p:
continue
if not validsum(L[i-p:i], L[i]):
print(L[i])
ans = L[i]
break
# part 2
for i in range(len(L)):
nums = [L[i]]
for ii in L[i+1:]:
nums.append(ii)
if sum(nums) == ans:
nums.sort()
print(nums[0] + nums[-1])
sys.exit(0)
elif sum(nums) > ans:
break

20
9/e.txt

@ -0,0 +1,20 @@
35
20
15
25
47
40
62
55
65
95
102
117
150
182
127
219
299
277
309
576

1000
9/input.txt
File diff suppressed because it is too large
View File

Loading…
Cancel
Save