Day 10 completed

completed with the help of shapely python module

other minors changes in day5
This commit is contained in:
2023-12-10 17:34:02 +01:00
parent cdaa539b79
commit 64a270ee39
11 changed files with 315 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
import re
from dataclasses import dataclass
from typing import Optional, Dict, List, Tuple
from typing import Optional, Dict, List, Tuple, OrderedDict as OrderedDictType
from collections import OrderedDict
@dataclass
@@ -18,17 +19,17 @@ class AlmanacMap:
return self.destination + (source - self.source)
def extract(input_file: str) -> Tuple[List[int], Dict[str, List[AlmanacMap]]]:
def extract(input_file: str) -> Tuple[List[int], OrderedDictType[str, List[AlmanacMap]]]:
seeds = []
maps = {
"seed-to-soil": [],
"soil-to-fertilizer": [],
"fertilizer-to-water": [],
"water-to-light": [],
"light-to-temperature": [],
"temperature-to-humidity": [],
"humidity-to-location": [],
}
maps = OrderedDict(
("seed-to-soil", []),
("soil-to-fertilizer", []),
("fertilizer-to-water", []),
("water-to-light", []),
("light-to-temperature", []),
("temperature-to-humidity", []),
("humidity-to-location", []),
)
with open(input_file) as input:
current_map = {}
@@ -44,3 +45,21 @@ def extract(input_file: str) -> Tuple[List[int], Dict[str, List[AlmanacMap]]]:
destination, source, length = match.group(1).split(" ")
current_map.append(AlmanacMap(destination=int(destination), source=int(source), length=int(length)))
return seeds, maps
def next_maps(a_map: AlmanacMap, map_type: str, maps: OrderedDictType[str, AlmanacMap]) -> List[AlmanacMap]:
mini = a_map.destination
maxi = a_map.destination + a_map.length
maps_next_level = list(
filter(
lambda m: m.destination <= maxi and (m.destination + m.length) >= mini,
maps[maps.keys().index(map_type) + 1],
)
)
return maps_next_level
def seed_to_location_map(maps):
seed_to_location = []
for seed_group in maps["seed-to-soil"]:
return seed_to_location

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env python3.11
# Is killed on WSL2 after vmmem increase to 16GB
from data import extract
from day5.common import extract
seeds, maps = extract("input.txt")
lowest_location = None

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env python3.11
# Is killed on WSL2 after vmmem increase to 16GB
from data import extract
from day5.common import extract
import concurrent.futures
def seed_to_location(seed, maps):