From e42b0277284da20963f16a024414a272ec17f3d2 Mon Sep 17 00:00:00 2001 From: Rob Date: Sat, 9 Dec 2023 12:32:58 +0100 Subject: [PATCH] WIP day 5 p2 with ranges --- AdventOfCode.Solutions/2023/Day 05/Day05.cs | 26 ++++----------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/AdventOfCode.Solutions/2023/Day 05/Day05.cs b/AdventOfCode.Solutions/2023/Day 05/Day05.cs index 77ff7a3..647ef8f 100644 --- a/AdventOfCode.Solutions/2023/Day 05/Day05.cs +++ b/AdventOfCode.Solutions/2023/Day 05/Day05.cs @@ -1,4 +1,5 @@ using AdventOfCode.Core; +using AdventOfCode.Core.Shared.Grid; namespace AdventOfCode.Solutions._2023 { @@ -78,30 +79,11 @@ namespace AdventOfCode.Solutions._2023 List location = MapData(data, stringSeperator, data.Count); long[] seedData = data[0].Split(' ').Skip(1).Select(long.Parse).ToArray(); + List ranges = []; long lowestLocation = long.MaxValue; - - List proccessed = []; - // change to use ranges and shift those - for (int seedDataIndex = 0; seedDataIndex < seedData.Length; seedDataIndex += 2) + for(int index = 0; index < seedData.Length / 2; index++) { - for (long seedLocaton = seedData[seedDataIndex]; seedLocaton < seedData[seedDataIndex] + seedData[seedDataIndex + 1]; seedLocaton++) - { - if (proccessed.Contains(seedLocaton)) - continue; - - long soilLocation = GetTargetLocation(soil, seedLocaton); - long fertilizerLocation = GetTargetLocation(fertilizer, soilLocation); - long waterLocation = GetTargetLocation(water, fertilizerLocation); - long lightLocation = GetTargetLocation(light, waterLocation); - long temperatureLocation = GetTargetLocation(temperature, lightLocation); - long humidityLocation = GetTargetLocation(humidity, temperatureLocation); - long locationLocation = GetTargetLocation(location, humidityLocation); - - if (locationLocation < lowestLocation) - lowestLocation = locationLocation; - - proccessed.Add(seedLocaton); - } + ranges.Add(new Line(new Point(seedData[index], 0), seedData[index + 1])); } return lowestLocation.ToString();