56 lines
1.3 KiB
Python
56 lines
1.3 KiB
Python
|
#!/bin/python3
|
||
|
|
||
|
import sys
|
||
|
from pprint import pprint
|
||
|
from aocd import get_data
|
||
|
|
||
|
|
||
|
input_f = sys.argv[1]
|
||
|
|
||
|
seeds, *maps = open(input_f).read().split('\n\n')
|
||
|
|
||
|
seeds = seeds.split(':')[1].split()
|
||
|
|
||
|
pprint(seeds)
|
||
|
pprint(maps)
|
||
|
|
||
|
tmp_seeds = []
|
||
|
|
||
|
for i in range(0,len(seeds)-1,2):
|
||
|
#print('Creating range: ' + seeds[i] + ' to ' + str(int(seeds[i+1])+int(seeds[i])-1))
|
||
|
for j in range(int(seeds[i]),int(seeds[i+1])+int(seeds[i])):
|
||
|
tmp_seeds.append(j)
|
||
|
|
||
|
seeds = tmp_seeds
|
||
|
#print(seeds)
|
||
|
|
||
|
for i in maps:
|
||
|
tmp = []
|
||
|
i = i.split()
|
||
|
#print(i)
|
||
|
|
||
|
for ldx,l in enumerate(seeds):
|
||
|
l = int(l)
|
||
|
for x in range(2,len(i)-2,3):
|
||
|
d = int(i[x])
|
||
|
s = int(i[x+1])
|
||
|
r = int(i[x+2])
|
||
|
#print('Looking for ' + str(l) + ' in range ' + str(s) + ' > ' + str((s+r)),end='')
|
||
|
if s <= l and l < s + r:
|
||
|
seeds[ldx] = d + (l - s)
|
||
|
#print('. Found!')
|
||
|
break
|
||
|
#print(seeds)
|
||
|
print(min(seeds))
|
||
|
"""
|
||
|
for i in range(0,7):
|
||
|
tmp = []
|
||
|
for j in range(2,len(nmaps[i]),3):
|
||
|
print("des " + str(nmaps[i][j]))
|
||
|
print("src " + str(nmaps[i][j+1]))
|
||
|
print("rng " + str(nmaps[i][j+2]))
|
||
|
for x in range(int(nmaps[i][j]),int(nmaps[i][j])+int(nmaps[i][j+2])):
|
||
|
print(x)
|
||
|
|
||
|
"""
|