From 1c5ffa221bac071fdf3edc0776ccaf3ea9706080 Mon Sep 17 00:00:00 2001 From: Samuel Ortion Date: Sat, 16 Dec 2023 08:51:08 +0100 Subject: [PATCH] day5: seems to have multiple mapping --- days/05/part1.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 days/05/part1.py diff --git a/days/05/part1.py b/days/05/part1.py new file mode 100644 index 0000000..7132a53 --- /dev/null +++ b/days/05/part1.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +# day 5 - Advent of Code 2023 +# part 1 + +import numpy as np +import pandas as pd + +with open("data/sample.txt", "r") as f: + data = f.read() + +parts = data.split("\n\n") + +seeds = parts[0] +seeds = seeds.split(": ")[1].split() +seeds = list(map(int, seeds)) + +maps = [ + [ + [int(item) for item in values.split()] + for values in themap.split("\n")[1:] + if values != "" + ] + for themap in parts[1:] +] + + +def recursive_min_descent(seed, maps): + current = seed + for submap in maps: + for indication in submap: + destination, source, size = indication + return current + + +""" +soils = list(map(lambda seed: descent(seed, maps), seeds)) + +seeds = range(0, 99) + +df = pd.DataFrame( + dict(seed=seeds, soil=list(map(lambda seed: descent(seed, maps), seeds))) +) + +""" +# Check that no map indication overlaps +for submap in maps: + for indication1 in submap: + _, start1, range1 = indication1 + for indication2 in submap: + if indication1 == indication2: + continue + _, start2, range2 = indication2 + if not (start2 > start1 + range1 or start1 > start2 + range2): + print("overlap") + +print(df)