Skip to content

Commit

Permalink
day 15
Browse files Browse the repository at this point in the history
  • Loading branch information
wimglenn committed Dec 15, 2023
1 parent 2493871 commit e405e55
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
6 changes: 4 additions & 2 deletions aoc_wim/aoc2023/q11.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
--- Day 11: Cosmic Expansion ---
https://adventofcode.com/2023/day/11
"""
from aocd import data
from itertools import combinations
from aoc_wim.zgrid import ZGrid

from aocd import data

from aoc_wim.zgrid import manhattan_distance
from aoc_wim.zgrid import ZGrid

grid = ZGrid(data)
h, w = grid.height, grid.width
Expand Down
3 changes: 2 additions & 1 deletion aoc_wim/aoc2023/q12.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
--- Day 12: Hot Springs ---
https://adventofcode.com/2023/day/12
"""
from aocd import data
from functools import cache

from aocd import data


@cache
def fits(ss, cs, h=0):
Expand Down
2 changes: 1 addition & 1 deletion aoc_wim/aoc2023/q13_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
--- Day 13: Point of Incidence ---
https://adventofcode.com/2023/day/13
"""
from aocd import data
import numpy as np
from aocd import data

a = b = 0
for chunk in data.split("\n\n"):
Expand Down
24 changes: 24 additions & 0 deletions aoc_wim/aoc2023/q15.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
--- Day 15: Lens Library ---
https://adventofcode.com/2023/day/15
"""
from aocd import data


def keyfunc(s):
i = 0
for char in s:
i += ord(char)
i *= 17
i %= 256
return i


hashmap = [{} for i in range(256)]
for op in data.split(","):
match op.strip("-").split("="):
case [k, v]: hashmap[keyfunc(k)][k] = int(v)
case [k]: hashmap[keyfunc(k)].pop(k, None)

print("answer_a:", sum(keyfunc(op) for op in data.split(",")))
print("answer_b:", sum(i*sum(k*v for k,v in enumerate(box.values(),1)) for i,box in enumerate(hashmap,1)))
3 changes: 3 additions & 0 deletions tests/2023/15/0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7
1320
-

0 comments on commit e405e55

Please sign in to comment.