From 9d8f32466422579ce29aba97152bf58381f85dac Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Tue, 5 Dec 2023 13:55:38 +0100 Subject: [PATCH] Starting 2023-12-05 p2 --- 2023/day5/{.part1.py.swp => .part2.py.swp} | Bin 12288 -> 12288 bytes 2023/day5/part2.py | 55 +++++++++++++++++++++ 2 files changed, 55 insertions(+) rename 2023/day5/{.part1.py.swp => .part2.py.swp} (86%) create mode 100644 2023/day5/part2.py diff --git a/2023/day5/.part1.py.swp b/2023/day5/.part2.py.swp similarity index 86% rename from 2023/day5/.part1.py.swp rename to 2023/day5/.part2.py.swp index 466fb9b0c7d9283e079ee99099b5837b79b9bd48..7ee61eedf952632e83bfb1a4f08a0c19844e088d 100644 GIT binary patch delta 560 zcmZY4ze~eV5C`xJD$*ZXiz2mHd9*|NNK+e^)`E*7;vnK8Vkx!KC=pFVjFUq9Cny=5 z1;JH`;2`MS!NJKz1P2Fo5*!p9{5C1I;K7I7yFBjQ)z|84(e=#o`~u6R6+#RUUB;^F z=yxw&tR6-8go%s8dPvAR;epRk&`0#*_iknFFq^9lg@^{>qo3#)mLU(5Ai@Ylzz08l zL~rm24{!-5un%RJ1rCiM(JAc13QR)=#vlqk@D(7s570QBAvu60=z=$l_X^E1@8BA4 z;Rde!j?jJX>y9JrK}m8N(xMcp&PC4i z#A@i?8bO>f)v~4On_j0p6Pd)^AvI1_o*A{8X8r>N6QxQS4L43`;Ab@0EGY1WpNETq z;UqUimBC~|1^0R-eg+0%AZ7#NFMJFP&w=<65bp=#H9*`3#5q750K_Ihe3h4hVFM7i z192)4`vb8p5UT>Q2oN&?@jo60hL=Em2Z*-8u1L)(PPLlssG~kPQzvKhH61R-$q#icCM)aT1ppSQOpO2l diff --git a/2023/day5/part2.py b/2023/day5/part2.py new file mode 100644 index 0000000..6f01ba7 --- /dev/null +++ b/2023/day5/part2.py @@ -0,0 +1,55 @@ +#!/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) + +"""