-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsolve.py
More file actions
36 lines (26 loc) · 1.07 KB
/
solve.py
File metadata and controls
36 lines (26 loc) · 1.07 KB
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
#!/usr/bin/env python3
import csv
from collections import defaultdict
from itertools import product
with open('grid.csv') as f_grid, open('out.csv') as f_out:
grid = [row for row in csv.reader(f_grid)]
results = f_out.read().splitlines()
values = defaultdict(list)
for x, row in enumerate(grid):
for y, value in enumerate(row):
values[value].append(x + 1j * y)
for i in range(0, len(results), 6):
val1, d1 = results[i + 0][:1], float(results[i + 0][2:])
val2, d2 = results[i + 1][:1], float(results[i + 1][2:])
val3, d3 = results[i + 2][:1], float(results[i + 2][2:])
d12 = float(results[i + 3][3:])
d23 = float(results[i + 4][3:])
d31 = float(results[i + 5][3:])
for P1, P2, P3 in product(values[val1], values[val2], values[val3]):
if abs(P1 - P2) == d12 and abs(P2 - P3) == d23 and abs(P3 - P1) == d31:
break
for value, points in values.items():
for F in points:
if abs(F - P1) == d1 and abs(F - P2) == d2 and abs(F - P3) == d3:
print(value, end='')
break