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.
.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
<!-- 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 -->
# aoc2ß23

View File

@ -2,6 +2,13 @@ from tools.aoc import AOCDay
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):
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 = []
seed2soil = {}
soil2fertilizer = {}
fertilizer2water = {}
water2light = {}
light2temperature = {}
temperature2humidity = {}
humidity2location = {}
self.seed2soil = {}
self.soil2fertilizer = {}
self.fertilizer2water = {}
self.water2light = {}
self.light2temperature = {}
self.temperature2humidity = {}
self.humidity2location = {}
the_map = None
for line in self.getInput():
if not line:
@ -31,49 +52,36 @@ class Day(AOCDay):
_, s = line.split(": ")
seeds = list(map(int, s.split()))
elif line.startswith("seed-to-soil"):
the_map = seed2soil
the_map = self.seed2soil
elif line.startswith("soil-to-fertilizer"):
the_map = soil2fertilizer
the_map = self.soil2fertilizer
elif line.startswith("fertilizer-to-water"):
the_map = fertilizer2water
the_map = self.fertilizer2water
elif line.startswith("water-to-light"):
the_map = water2light
the_map = self.water2light
elif line.startswith("light-to-temperature"):
the_map = light2temperature
the_map = self.light2temperature
elif line.startswith("temperature-to-humidity"):
the_map = temperature2humidity
the_map = self.temperature2humidity
elif line.startswith("humidity-to-location"):
the_map = humidity2location
the_map = self.humidity2location
else:
dest, source, length = map(int, line.split())
the_map[(dest, length)] = source
the_map[(source, length)] = dest
loc2seed = self.augment_map(humidity2location, temperature2humidity)
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:
self.seed_locations = {}
last_min = 0
the_map = {}
for (dest, length), source in sorted(source_map.items()):
if last_min < dest:
the_map[(last_min, dest - last_min)] = self.lookup(target_map, last_min)
the_map[(dest, length)] = self.lookup(target_map, source)
last_min = dest + length
for (source, length), dest in sorted(self.seed2soil.items()):
if last_min < source:
self.seed2soil[(last_min, source - last_min)] = 0
last_min = source + length
self.seed2soil[(last_min, 2**32)] = 0
return the_map
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
return seeds
def part1(self) -> Any:
seeds = self.parse_input()
return min(self.get_seed_location(s) for s in seeds)
def part2(self) -> Any:
return

View File

@ -70,21 +70,19 @@ class Day(AOCDay):
print(f"{i} = {t}")
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}")
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)
w2 = walk(grid, start, 2 * len(self.getInput()) + 65)
w3 = walk(grid, start, 3 * len(self.getInput()) + 65)
w4 = walk(grid, start, 4 * len(self.getInput()) + 65)
w5 = walk(grid, start, 5 * len(self.getInput()) + 65)
w6 = walk(grid, start, 6 * len(self.getInput()) + 65)
print(f"65={t}, 196={k}, {w2=}, {w3=}, {w4=}, {w5=}, {w5=}")
print(w3 / w2)
print(w4 / w3)
print(w5 / w4)
print(w6 / w5)
g = walk(grid, start, 2 * len(self.getInput()) + 65)
# v = walk(grid, start, (3 * len(self.getInput())) - 1)
print(f"65={t}, 196={k}, 327={g}, {math.log(k)=}, {math.log(g)=}")
print(((k - t) / 14746) * 3)
print((g - t) / 14746)
print((g - k) / 14746)
print(g % k)
print(k / t)
return ""

View File

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

View File

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