Compare commits

..

No commits in common. "06be0bd65043950feb8f6870f81d7d5e925dd915" and "8910705d2e9686b0572243e8b19455996f302532" have entirely different histories.

32 changed files with 59 additions and 157 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

5
.gitignore vendored
View File

@ -160,8 +160,3 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/ .idea/
answer_cache.json
.session
session.cookie
.aoc_tiles/*
!.aoc_tiles/tiles/

View File

@ -1,17 +0,0 @@
repos:
- repo: https://github.com/LiquidFun/aoc_tiles
rev: 0.6.2
hooks:
- id: aoc-tiles
# Optionally use these arguments. Auto add tiles to git adds the tiles to git,
# possibly amends your commit by creating the tile images and updating the README.
# Language sorting shows the preference of the order of the languages to use.
# Exclude paterns are globs which can be used to exclude files when creating
# the tiles. See the customization section in the README for more flags.
# Simply remove the comments (#) below for args and the flags you want.
args:
- --auto-add-tiles-to-git=add
- --contrast-improvement-type=dark
- --overwrite-year=2023
# - --language-sorting=py,jl,kt,rs
# - --exclude-patterns=2021/*/*.apl,2021/*/*.py,2021/*/*.cpp

View File

@ -1,81 +1 @@
# Advent of Code 2ß23 # aoc2ß23
<!-- AOC TILES BEGIN -->
<h1 align="center">
2023 - 47 ⭐ - Python
</h1>
<a href="day01.py">
<img src=".aoc_tiles/tiles/2023/01.png" width="161px">
</a>
<a href="day02.py">
<img src=".aoc_tiles/tiles/2023/02.png" width="161px">
</a>
<a href="day03.py">
<img src=".aoc_tiles/tiles/2023/03.png" width="161px">
</a>
<a href="day04.py">
<img src=".aoc_tiles/tiles/2023/04.png" width="161px">
</a>
<a href="day05.py">
<img src=".aoc_tiles/tiles/2023/05.png" width="161px">
</a>
<a href="day06.py">
<img src=".aoc_tiles/tiles/2023/06.png" width="161px">
</a>
<a href="day07.py">
<img src=".aoc_tiles/tiles/2023/07.png" width="161px">
</a>
<a href="day08.py">
<img src=".aoc_tiles/tiles/2023/08.png" width="161px">
</a>
<a href="day09.py">
<img src=".aoc_tiles/tiles/2023/09.png" width="161px">
</a>
<a href="day10.py">
<img src=".aoc_tiles/tiles/2023/10.png" width="161px">
</a>
<a href="day11.py">
<img src=".aoc_tiles/tiles/2023/11.png" width="161px">
</a>
<a href="day12.py">
<img src=".aoc_tiles/tiles/2023/12.png" width="161px">
</a>
<a href="day13.py">
<img src=".aoc_tiles/tiles/2023/13.png" width="161px">
</a>
<a href="day14.py">
<img src=".aoc_tiles/tiles/2023/14.png" width="161px">
</a>
<a href="day15.py">
<img src=".aoc_tiles/tiles/2023/15.png" width="161px">
</a>
<a href="day16.py">
<img src=".aoc_tiles/tiles/2023/16.png" width="161px">
</a>
<a href="day17.py">
<img src=".aoc_tiles/tiles/2023/17.png" width="161px">
</a>
<a href="day18.py">
<img src=".aoc_tiles/tiles/2023/18.png" width="161px">
</a>
<a href="day19.py">
<img src=".aoc_tiles/tiles/2023/19.png" width="161px">
</a>
<a href="day20.py">
<img src=".aoc_tiles/tiles/2023/20.png" width="161px">
</a>
<a href="day21.py">
<img src=".aoc_tiles/tiles/2023/21.png" width="161px">
</a>
<a href="day22.py">
<img src=".aoc_tiles/tiles/2023/22.png" width="161px">
</a>
<a href="day23.py">
<img src=".aoc_tiles/tiles/2023/23.png" width="161px">
</a>
<a href="day24.py">
<img src=".aoc_tiles/tiles/2023/24.png" width="161px">
</a>
<a href="day25.py">
<img src=".aoc_tiles/tiles/2023/25.png" width="161px">
</a>
<!-- AOC TILES END -->

View File

@ -2,6 +2,13 @@ from tools.aoc import AOCDay
from typing import Any from typing import Any
def lookup(the_map: dict, source: int) -> int:
for (s, l), d in the_map.items():
if s <= source < s + l:
return source - s + d
return source
class Day(AOCDay): class Day(AOCDay):
inputs = [ inputs = [
[ [
@ -14,15 +21,29 @@ class Day(AOCDay):
], ],
] ]
def parse_input(self) -> list: def __init__(self, year: int, day: int):
super().__init__(year, day)
self.seed_locations = {}
def get_seed_location(self, seed: int) -> int:
soil = lookup(self.seed2soil, seed)
fertilizer = lookup(self.soil2fertilizer, soil)
water = lookup(self.fertilizer2water, fertilizer)
light = lookup(self.water2light, water)
temperature = lookup(self.light2temperature, light)
humidity = lookup(self.temperature2humidity, temperature)
location = lookup(self.humidity2location, humidity)
return location
def parse_input(self, part2: bool = False) -> list:
seeds = [] seeds = []
seed2soil = {} self.seed2soil = {}
soil2fertilizer = {} self.soil2fertilizer = {}
fertilizer2water = {} self.fertilizer2water = {}
water2light = {} self.water2light = {}
light2temperature = {} self.light2temperature = {}
temperature2humidity = {} self.temperature2humidity = {}
humidity2location = {} self.humidity2location = {}
the_map = None the_map = None
for line in self.getInput(): for line in self.getInput():
if not line: if not line:
@ -31,49 +52,36 @@ class Day(AOCDay):
_, s = line.split(": ") _, s = line.split(": ")
seeds = list(map(int, s.split())) seeds = list(map(int, s.split()))
elif line.startswith("seed-to-soil"): elif line.startswith("seed-to-soil"):
the_map = seed2soil the_map = self.seed2soil
elif line.startswith("soil-to-fertilizer"): elif line.startswith("soil-to-fertilizer"):
the_map = soil2fertilizer the_map = self.soil2fertilizer
elif line.startswith("fertilizer-to-water"): elif line.startswith("fertilizer-to-water"):
the_map = fertilizer2water the_map = self.fertilizer2water
elif line.startswith("water-to-light"): elif line.startswith("water-to-light"):
the_map = water2light the_map = self.water2light
elif line.startswith("light-to-temperature"): elif line.startswith("light-to-temperature"):
the_map = light2temperature the_map = self.light2temperature
elif line.startswith("temperature-to-humidity"): elif line.startswith("temperature-to-humidity"):
the_map = temperature2humidity the_map = self.temperature2humidity
elif line.startswith("humidity-to-location"): elif line.startswith("humidity-to-location"):
the_map = humidity2location the_map = self.humidity2location
else: else:
dest, source, length = map(int, line.split()) dest, source, length = map(int, line.split())
the_map[(dest, length)] = source the_map[(source, length)] = dest
loc2seed = self.augment_map(humidity2location, temperature2humidity) self.seed_locations = {}
print(loc2seed)
print(self.lookup(loc2seed, 82))
loc2seed = self.augment_map(loc2seed, light2temperature)
print(self.lookup(loc2seed, 82))
return seeds
def augment_map(self, source_map: dict, target_map: dict) -> dict:
last_min = 0 last_min = 0
the_map = {} for (source, length), dest in sorted(self.seed2soil.items()):
for (dest, length), source in sorted(source_map.items()): if last_min < source:
if last_min < dest: self.seed2soil[(last_min, source - last_min)] = 0
the_map[(last_min, dest - last_min)] = self.lookup(target_map, last_min) last_min = source + length
the_map[(dest, length)] = self.lookup(target_map, source) self.seed2soil[(last_min, 2**32)] = 0
last_min = dest + length
return the_map return seeds
def lookup(self, the_map: dict, target: int) -> int:
for (dest, length), source in the_map.items():
if dest <= target < dest + length:
return source + target - dest
return target
def part1(self) -> Any: def part1(self) -> Any:
seeds = self.parse_input() seeds = self.parse_input()
return min(self.get_seed_location(s) for s in seeds)
def part2(self) -> Any: def part2(self) -> Any:
return return

View File

@ -70,21 +70,19 @@ class Day(AOCDay):
print(f"{i} = {t}") print(f"{i} = {t}")
for i in [Coordinate(0, 0), Coordinate(130, 0), Coordinate(0, 130), Coordinate(130, 130)]: for i in [Coordinate(0, 0), Coordinate(130, 0), Coordinate(0, 130), Coordinate(130, 130)]:
t = walk(grid, i, 131) t = walk(grid, i, 65)
print(f"{i} = {t}") print(f"{i} = {t}")
needed_steps = 5000 if self.is_test() else 26501365 needed_steps = 5000 if self.is_test() else 26501365
t = walk(grid, start, 65) t = walk(grid, start, 64)
k = walk(grid, start, len(self.getInput()) + 65) k = walk(grid, start, len(self.getInput()) + 65)
w2 = walk(grid, start, 2 * len(self.getInput()) + 65) g = walk(grid, start, 2 * len(self.getInput()) + 65)
w3 = walk(grid, start, 3 * len(self.getInput()) + 65) # v = walk(grid, start, (3 * len(self.getInput())) - 1)
w4 = walk(grid, start, 4 * len(self.getInput()) + 65) print(f"65={t}, 196={k}, 327={g}, {math.log(k)=}, {math.log(g)=}")
w5 = walk(grid, start, 5 * len(self.getInput()) + 65) print(((k - t) / 14746) * 3)
w6 = walk(grid, start, 6 * len(self.getInput()) + 65) print((g - t) / 14746)
print(f"65={t}, 196={k}, {w2=}, {w3=}, {w4=}, {w5=}, {w5=}") print((g - k) / 14746)
print(w3 / w2) print(g % k)
print(w4 / w3) print(k / t)
print(w5 / w4)
print(w6 / w5)
return "" return ""

View File

@ -1,4 +1,3 @@
from collections import defaultdict
from itertools import combinations from itertools import combinations
from tools.aoc import AOCDay from tools.aoc import AOCDay
from tools.coordinate import Coordinate, Line from tools.coordinate import Coordinate, Line
@ -30,7 +29,7 @@ class Day(AOCDay):
[ [
(47, "input24_test"), (47, "input24_test"),
(None, "input24"), (None, "input24"),
], ]
] ]
def parse_input(self, part2: bool = False) -> list[tuple[Coordinate, Coordinate]]: def parse_input(self, part2: bool = False) -> list[tuple[Coordinate, Coordinate]]:
@ -64,6 +63,6 @@ class Day(AOCDay):
return "" return ""
if __name__ == "__main__": if __name__ == '__main__':
day = Day(2023, 24) day = Day(2023, 24)
day.run(verbose=True) day.run(verbose=True)

View File

@ -1,2 +1 @@
shs-tools ~= 0.3 shs-tools ~= 0.3
pre-commit