From 32aa4dc1089e8c51f36c3e4e8aeeda6d6d19391c Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Wed, 6 Dec 2023 17:38:30 +0100 Subject: [PATCH] updated data for day 6 --- 2023/day5/part2.py | 31 ++++++++++++---------- 2023/day5/part2_1.py | 61 ++++++++++++++++++++++++++++++++++++++++++++ 2023/day6/part1.py | 29 +++++++++++++++++++++ 2023/day6/test | 2 ++ 4 files changed, 109 insertions(+), 14 deletions(-) create mode 100644 2023/day5/part2_1.py create mode 100644 2023/day6/part1.py create mode 100644 2023/day6/test diff --git a/2023/day5/part2.py b/2023/day5/part2.py index 3f57d4a..bcbeecf 100644 --- a/2023/day5/part2.py +++ b/2023/day5/part2.py @@ -2,8 +2,6 @@ import sys from pprint import pprint -from aocd import get_data - input_f = sys.argv[1] @@ -23,28 +21,33 @@ for i in range(0,len(seeds)-1,2): seeds = tmp_seeds -total=len(seeds)*7 +#count = 1000000 count = 0 +#for i in range(1000000,2000000): -for i in maps: - tmp = [] - i = i.split() +#maps.reverse() +for seed in range(0,50): + print("seed: " + str(seed),end="") + + for i in maps: + tmp = [] + i = i.split() #print(i) - for ldx,l in enumerate(seeds): - l = int(l) - count += 1 + #for ldx,l in enumerate(seeds): + # l = int(l) + # count += 1 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='') - print(str(round(count/total*100,2))) - if s <= l and l < s + r: - seeds[ldx] = d + (l - s) - #print('. Found!') + if s <= seed and seed < s + r: + seed = d + (seed - s) + print(seed) break + else: + print() #print(seeds) -print(min(seeds)) """ for i in range(0,7): tmp = [] diff --git a/2023/day5/part2_1.py b/2023/day5/part2_1.py new file mode 100644 index 0000000..ac10984 --- /dev/null +++ b/2023/day5/part2_1.py @@ -0,0 +1,61 @@ +#!/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) + +nseeds = [] + +for i in range(1000000,3000000): + nseeds.append(i) + +seeds = nseeds + +for idx,i in enumerate(maps): + tmp = [] + i = i.split() + #print(i) + + for ldx,l in enumerate(seeds): + print(l,idx) + 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() + #print(seeds) + +checked = [] + +#for idx,i in enumerate(seeds): +# if seeds[idx] != nseeds[idx]: +# checked.append(seeds[idx]) + +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) + +""" diff --git a/2023/day6/part1.py b/2023/day6/part1.py new file mode 100644 index 0000000..c26d9e5 --- /dev/null +++ b/2023/day6/part1.py @@ -0,0 +1,29 @@ +#!/bin/python3 + +import sys +from pprint import pprint + + +input_f = sys.argv[1] + +arr = [] + + +from aocd import get_data + +maps = map(get_data(2023,6)) + +print(maps) + +with open(input_f) as file: + for line in file: + tmp = line.rstrip() + tmp = tmp.split() + arr.append(tmp) + # continue + # t = tmp[idx] + # r = tmp[len(tmp)] + # #print(t,r) + + + diff --git a/2023/day6/test b/2023/day6/test new file mode 100644 index 0000000..28f5ae9 --- /dev/null +++ b/2023/day6/test @@ -0,0 +1,2 @@ +Time: 7 15 30 +Distance: 9 40 200