Compare commits
5 Commits
8910705d2e
...
06be0bd650
| Author | SHA1 | Date | |
|---|---|---|---|
| 06be0bd650 | |||
| 2985d013b0 | |||
| b713a4ddbf | |||
| e2acccf2e5 | |||
| 2c9c027eb1 |
BIN
.aoc_tiles/tiles/2023/01.png
Normal file
|
After Width: | Height: | Size: 9.4 KiB |
BIN
.aoc_tiles/tiles/2023/02.png
Normal file
|
After Width: | Height: | Size: 9.9 KiB |
BIN
.aoc_tiles/tiles/2023/03.png
Normal file
|
After Width: | Height: | Size: 9.7 KiB |
BIN
.aoc_tiles/tiles/2023/04.png
Normal file
|
After Width: | Height: | Size: 9.0 KiB |
BIN
.aoc_tiles/tiles/2023/05.png
Normal file
|
After Width: | Height: | Size: 9.9 KiB |
BIN
.aoc_tiles/tiles/2023/06.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
.aoc_tiles/tiles/2023/07.png
Normal file
|
After Width: | Height: | Size: 9.8 KiB |
BIN
.aoc_tiles/tiles/2023/08.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
.aoc_tiles/tiles/2023/09.png
Normal file
|
After Width: | Height: | Size: 9.9 KiB |
BIN
.aoc_tiles/tiles/2023/10.png
Normal file
|
After Width: | Height: | Size: 9.1 KiB |
BIN
.aoc_tiles/tiles/2023/11.png
Normal file
|
After Width: | Height: | Size: 7.7 KiB |
BIN
.aoc_tiles/tiles/2023/12.png
Normal file
|
After Width: | Height: | Size: 8.8 KiB |
BIN
.aoc_tiles/tiles/2023/13.png
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
BIN
.aoc_tiles/tiles/2023/14.png
Normal file
|
After Width: | Height: | Size: 8.0 KiB |
BIN
.aoc_tiles/tiles/2023/15.png
Normal file
|
After Width: | Height: | Size: 8.8 KiB |
BIN
.aoc_tiles/tiles/2023/16.png
Normal file
|
After Width: | Height: | Size: 8.8 KiB |
BIN
.aoc_tiles/tiles/2023/17.png
Normal file
|
After Width: | Height: | Size: 8.7 KiB |
BIN
.aoc_tiles/tiles/2023/18.png
Normal file
|
After Width: | Height: | Size: 8.9 KiB |
BIN
.aoc_tiles/tiles/2023/19.png
Normal file
|
After Width: | Height: | Size: 9.3 KiB |
BIN
.aoc_tiles/tiles/2023/20.png
Normal file
|
After Width: | Height: | Size: 9.6 KiB |
BIN
.aoc_tiles/tiles/2023/21.png
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
.aoc_tiles/tiles/2023/22.png
Normal file
|
After Width: | Height: | Size: 8.5 KiB |
BIN
.aoc_tiles/tiles/2023/23.png
Normal file
|
After Width: | Height: | Size: 9.4 KiB |
BIN
.aoc_tiles/tiles/2023/24.png
Normal file
|
After Width: | Height: | Size: 7.0 KiB |
BIN
.aoc_tiles/tiles/2023/25.png
Normal file
|
After Width: | Height: | Size: 7.5 KiB |
5
.gitignore
vendored
@ -160,3 +160,8 @@ 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/
|
||||
17
.pre-commit-config.yaml
Normal file
@ -0,0 +1,17 @@
|
||||
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
|
||||
82
README.md
@ -1 +1,81 @@
|
||||
# aoc2ß23
|
||||
# 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 -->
|
||||
84
day05.py
@ -2,13 +2,6 @@ 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 = [
|
||||
[
|
||||
@ -21,29 +14,15 @@ class Day(AOCDay):
|
||||
],
|
||||
]
|
||||
|
||||
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:
|
||||
def parse_input(self) -> list:
|
||||
seeds = []
|
||||
self.seed2soil = {}
|
||||
self.soil2fertilizer = {}
|
||||
self.fertilizer2water = {}
|
||||
self.water2light = {}
|
||||
self.light2temperature = {}
|
||||
self.temperature2humidity = {}
|
||||
self.humidity2location = {}
|
||||
seed2soil = {}
|
||||
soil2fertilizer = {}
|
||||
fertilizer2water = {}
|
||||
water2light = {}
|
||||
light2temperature = {}
|
||||
temperature2humidity = {}
|
||||
humidity2location = {}
|
||||
the_map = None
|
||||
for line in self.getInput():
|
||||
if not line:
|
||||
@ -52,36 +31,49 @@ class Day(AOCDay):
|
||||
_, s = line.split(": ")
|
||||
seeds = list(map(int, s.split()))
|
||||
elif line.startswith("seed-to-soil"):
|
||||
the_map = self.seed2soil
|
||||
the_map = seed2soil
|
||||
elif line.startswith("soil-to-fertilizer"):
|
||||
the_map = self.soil2fertilizer
|
||||
the_map = soil2fertilizer
|
||||
elif line.startswith("fertilizer-to-water"):
|
||||
the_map = self.fertilizer2water
|
||||
the_map = fertilizer2water
|
||||
elif line.startswith("water-to-light"):
|
||||
the_map = self.water2light
|
||||
the_map = water2light
|
||||
elif line.startswith("light-to-temperature"):
|
||||
the_map = self.light2temperature
|
||||
the_map = light2temperature
|
||||
elif line.startswith("temperature-to-humidity"):
|
||||
the_map = self.temperature2humidity
|
||||
the_map = temperature2humidity
|
||||
elif line.startswith("humidity-to-location"):
|
||||
the_map = self.humidity2location
|
||||
the_map = humidity2location
|
||||
else:
|
||||
dest, source, length = map(int, line.split())
|
||||
the_map[(source, length)] = dest
|
||||
|
||||
self.seed_locations = {}
|
||||
last_min = 0
|
||||
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
|
||||
the_map[(dest, length)] = source
|
||||
|
||||
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:
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
def part1(self) -> Any:
|
||||
seeds = self.parse_input()
|
||||
return min(self.get_seed_location(s) for s in seeds)
|
||||
|
||||
def part2(self) -> Any:
|
||||
return
|
||||
|
||||
22
day21.py
@ -70,19 +70,21 @@ 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, 65)
|
||||
t = walk(grid, i, 131)
|
||||
print(f"{i} = {t}")
|
||||
needed_steps = 5000 if self.is_test() else 26501365
|
||||
t = walk(grid, start, 64)
|
||||
t = walk(grid, start, 65)
|
||||
k = walk(grid, start, len(self.getInput()) + 65)
|
||||
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)
|
||||
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)
|
||||
return ""
|
||||
|
||||
|
||||
|
||||
5
day24.py
@ -1,3 +1,4 @@
|
||||
from collections import defaultdict
|
||||
from itertools import combinations
|
||||
from tools.aoc import AOCDay
|
||||
from tools.coordinate import Coordinate, Line
|
||||
@ -29,7 +30,7 @@ class Day(AOCDay):
|
||||
[
|
||||
(47, "input24_test"),
|
||||
(None, "input24"),
|
||||
]
|
||||
],
|
||||
]
|
||||
|
||||
def parse_input(self, part2: bool = False) -> list[tuple[Coordinate, Coordinate]]:
|
||||
@ -63,6 +64,6 @@ class Day(AOCDay):
|
||||
return ""
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
day = Day(2023, 24)
|
||||
day.run(verbose=True)
|
||||
|
||||
@ -1 +1,2 @@
|
||||
shs-tools ~= 0.3
|
||||
shs-tools ~= 0.3
|
||||
pre-commit
|
||||