diff --git a/aoc_wim/aoc2015/q04.py b/aoc_wim/aoc2015/q04.py index fb13e83d..b73d517e 100644 --- a/aoc_wim/aoc2015/q04.py +++ b/aoc_wim/aoc2015/q04.py @@ -3,6 +3,7 @@ https://adventofcode.com/2015/day/4 """ from _md5 import md5 + from aocd import data diff --git a/aoc_wim/aoc2015/q07.py b/aoc_wim/aoc2015/q07.py index f1e8eb4c..42268d95 100644 --- a/aoc_wim/aoc2015/q07.py +++ b/aoc_wim/aoc2015/q07.py @@ -5,8 +5,8 @@ import operator import re -from aocd import data import numpy as np +from aocd import data # TODO: change to use topological sort diff --git a/aoc_wim/aoc2015/q17.py b/aoc_wim/aoc2015/q17.py index 00bd8621..b7af8546 100644 --- a/aoc_wim/aoc2015/q17.py +++ b/aoc_wim/aoc2015/q17.py @@ -3,6 +3,7 @@ https://adventofcode.com/2015/day/17 """ from aocd import data + from aoc_wim.stuff import subset_sum vals = [int(n) for n in data.splitlines()] diff --git a/aoc_wim/aoc2015/q22.py b/aoc_wim/aoc2015/q22.py index 8a7eb9e7..444c670d 100644 --- a/aoc_wim/aoc2015/q22.py +++ b/aoc_wim/aoc2015/q22.py @@ -4,6 +4,7 @@ """ from aocd import data from fields import Fields + from aoc_wim.search import AStar diff --git a/aoc_wim/aoc2016/__init__.py b/aoc_wim/aoc2016/__init__.py index fdc602f5..27fb697b 100644 --- a/aoc_wim/aoc2016/__init__.py +++ b/aoc_wim/aoc2016/__init__.py @@ -1,8 +1,8 @@ import logging -from multiprocessing import current_process +import re from _md5 import md5 from functools import partial -import re +from multiprocessing import current_process log = logging.getLogger(__name__) diff --git a/aoc_wim/aoc2016/q01.py b/aoc_wim/aoc2016/q01.py index c68e7f5a..5a25ad2d 100644 --- a/aoc_wim/aoc2016/q01.py +++ b/aoc_wim/aoc2016/q01.py @@ -3,6 +3,7 @@ https://adventofcode.com/2016/day/1 """ from aocd import data + from aoc_wim.zgrid import manhattan_distance diff --git a/aoc_wim/aoc2016/q02.py b/aoc_wim/aoc2016/q02.py index b1ba4ca2..2ed7043c 100644 --- a/aoc_wim/aoc2016/q02.py +++ b/aoc_wim/aoc2016/q02.py @@ -3,6 +3,7 @@ https://adventofcode.com/2016/day/2 """ from aocd import data + from aoc_wim.zgrid import ZGrid diff --git a/aoc_wim/aoc2016/q05.py b/aoc_wim/aoc2016/q05.py index eff2086a..e5ab1598 100644 --- a/aoc_wim/aoc2016/q05.py +++ b/aoc_wim/aoc2016/q05.py @@ -2,13 +2,15 @@ --- Day 5: How About a Nice Game of Chess? --- https://adventofcode.com/2016/day/5 """ -from aocd import data import os from collections import deque from concurrent.futures import ProcessPoolExecutor -from aoc_wim.aoc2016 import md5_miner_q05 from itertools import count +from aocd import data + +from aoc_wim.aoc2016 import md5_miner_q05 + def main(): code1 = [] diff --git a/aoc_wim/aoc2016/q05_single_core.py b/aoc_wim/aoc2016/q05_single_core.py index 4f545d73..bf13ea53 100644 --- a/aoc_wim/aoc2016/q05_single_core.py +++ b/aoc_wim/aoc2016/q05_single_core.py @@ -3,6 +3,7 @@ https://adventofcode.com/2016/day/5 """ from _md5 import md5 + from aocd import data diff --git a/aoc_wim/aoc2016/q06.py b/aoc_wim/aoc2016/q06.py index af45ec0e..ffb2d682 100644 --- a/aoc_wim/aoc2016/q06.py +++ b/aoc_wim/aoc2016/q06.py @@ -3,6 +3,7 @@ https://adventofcode.com/2016/day/6 """ from collections import Counter + from aocd import data counters = [Counter(x) for x in zip(*data.splitlines())] diff --git a/aoc_wim/aoc2016/q08.py b/aoc_wim/aoc2016/q08.py index 8bdeeb64..60aa7d13 100644 --- a/aoc_wim/aoc2016/q08.py +++ b/aoc_wim/aoc2016/q08.py @@ -4,6 +4,7 @@ """ import numpy as np from aocd import data + from aoc_wim.ocr import AOCR diff --git a/aoc_wim/aoc2016/q09.py b/aoc_wim/aoc2016/q09.py index 8eb29617..6774c517 100644 --- a/aoc_wim/aoc2016/q09.py +++ b/aoc_wim/aoc2016/q09.py @@ -2,9 +2,9 @@ --- Day 9: Explosives in Cyberspace --- https://adventofcode.com/2016/day/9 """ -from collections import deque -import re import logging +import re +from collections import deque from aocd import data diff --git a/aoc_wim/aoc2016/q10.py b/aoc_wim/aoc2016/q10.py index 62fb59fc..00c327a3 100644 --- a/aoc_wim/aoc2016/q10.py +++ b/aoc_wim/aoc2016/q10.py @@ -3,6 +3,7 @@ https://adventofcode.com/2016/day/10 """ from math import prod + from aocd import data from parse import parse diff --git a/aoc_wim/aoc2016/q11.py b/aoc_wim/aoc2016/q11.py index 9a26e96e..8c1a0c2e 100644 --- a/aoc_wim/aoc2016/q11.py +++ b/aoc_wim/aoc2016/q11.py @@ -6,6 +6,7 @@ from itertools import product from aocd import data + from aoc_wim.search import AStar diff --git a/aoc_wim/aoc2016/q12.py b/aoc_wim/aoc2016/q12.py index eb4020ba..833954cd 100644 --- a/aoc_wim/aoc2016/q12.py +++ b/aoc_wim/aoc2016/q12.py @@ -3,6 +3,7 @@ https://adventofcode.com/2016/day/12 """ from aocd import data + from aoc_wim.aoc2016 import AssembunnyComputer diff --git a/aoc_wim/aoc2016/q13.py b/aoc_wim/aoc2016/q13.py index aec669c5..62edfb1e 100644 --- a/aoc_wim/aoc2016/q13.py +++ b/aoc_wim/aoc2016/q13.py @@ -2,10 +2,12 @@ --- Day 13: A Maze of Twisty Little Cubicles --- https://adventofcode.com/2016/day/13 """ -from aoc_wim.zgrid import ZGrid -from aocd import data from functools import partial +from aocd import data + +from aoc_wim.zgrid import ZGrid + def wall(z, fav_number): if z.real < 0 or z.imag < 0: diff --git a/aoc_wim/aoc2016/q14.py b/aoc_wim/aoc2016/q14.py index 7b00c8d6..8736bd12 100644 --- a/aoc_wim/aoc2016/q14.py +++ b/aoc_wim/aoc2016/q14.py @@ -6,11 +6,13 @@ import re from collections import defaultdict from collections import deque +from concurrent.futures import ProcessPoolExecutor +from itertools import count + from aocd import data + from aoc_wim.aoc2016 import md5_miner_q14a from aoc_wim.aoc2016 import md5_miner_q14b -from concurrent.futures import ProcessPoolExecutor -from itertools import count def search(data, stretch): diff --git a/aoc_wim/aoc2016/q14_single_core.py b/aoc_wim/aoc2016/q14_single_core.py index 65e5decc..297d5510 100644 --- a/aoc_wim/aoc2016/q14_single_core.py +++ b/aoc_wim/aoc2016/q14_single_core.py @@ -3,9 +3,10 @@ https://adventofcode.com/2016/day/14 """ import re +from _md5 import md5 from collections import defaultdict + from aocd import data -from _md5 import md5 def search(data, stretch): diff --git a/aoc_wim/aoc2016/q17.py b/aoc_wim/aoc2016/q17.py index e46d5195..0eb5cee0 100644 --- a/aoc_wim/aoc2016/q17.py +++ b/aoc_wim/aoc2016/q17.py @@ -2,8 +2,9 @@ --- Day 17: Two Steps Forward --- https://adventofcode.com/2016/day/17 """ -from collections import deque from _md5 import md5 +from collections import deque + from aocd import data diff --git a/aoc_wim/aoc2016/q23.py b/aoc_wim/aoc2016/q23.py index b45705e1..45caa925 100644 --- a/aoc_wim/aoc2016/q23.py +++ b/aoc_wim/aoc2016/q23.py @@ -3,6 +3,7 @@ https://adventofcode.com/2016/day/23 """ from aocd import data + from aoc_wim.aoc2016 import AssembunnyComputer diff --git a/aoc_wim/aoc2016/q24.py b/aoc_wim/aoc2016/q24.py index ad56919f..0aeb99e3 100644 --- a/aoc_wim/aoc2016/q24.py +++ b/aoc_wim/aoc2016/q24.py @@ -2,12 +2,14 @@ --- Day 24: Air Duct Spelunking --- https://adventofcode.com/2016/day/24 """ -from aoc_wim.zgrid import ZGrid from itertools import combinations from itertools import permutations + import networkx as nx from aocd import data +from aoc_wim.zgrid import ZGrid + grid = ZGrid(data, on=".", off="#") graph = grid.graph(extra="0123456789") distances = {} diff --git a/aoc_wim/aoc2016/q25.py b/aoc_wim/aoc2016/q25.py index 7136e209..25350530 100644 --- a/aoc_wim/aoc2016/q25.py +++ b/aoc_wim/aoc2016/q25.py @@ -3,6 +3,7 @@ https://adventofcode.com/2016/day/25 """ import re + from aocd import data x, y = re.findall(r"\d+", data)[:2] diff --git a/aoc_wim/aoc2017/q03.py b/aoc_wim/aoc2017/q03.py index d72a14f5..d91dca86 100644 --- a/aoc_wim/aoc2017/q03.py +++ b/aoc_wim/aoc2017/q03.py @@ -3,6 +3,7 @@ https://adventofcode.com/2017/day/3 """ from aocd import data + from aoc_wim.zgrid import manhattan_distance diff --git a/aoc_wim/aoc2017/q07.py b/aoc_wim/aoc2017/q07.py index c0815cdd..96d6e9fc 100644 --- a/aoc_wim/aoc2017/q07.py +++ b/aoc_wim/aoc2017/q07.py @@ -6,7 +6,6 @@ from collections import deque from aocd import data -from wimpy import cached_property class Node: @@ -16,7 +15,7 @@ def __init__(self, name): self.parent = None self.children = [] - @cached_property + @property def rweight(self): return self.weight + sum(x.rweight for x in self.children) diff --git a/aoc_wim/aoc2017/q11.py b/aoc_wim/aoc2017/q11.py index 60b6ab92..54dbb99f 100644 --- a/aoc_wim/aoc2017/q11.py +++ b/aoc_wim/aoc2017/q11.py @@ -2,9 +2,10 @@ --- Day 11: Hex Ed --- https://adventofcode.com/2017/day/11 """ -from aoc_wim import zgrid from aocd import data +from aoc_wim import zgrid + z = d = dmax = 0 grid = zgrid.ZGrid({z: 1}) for step in data.split(","): diff --git a/aoc_wim/aoc2017/q18.py b/aoc_wim/aoc2017/q18.py index fe9f4330..320dc39e 100644 --- a/aoc_wim/aoc2017/q18.py +++ b/aoc_wim/aoc2017/q18.py @@ -2,8 +2,10 @@ --- Day 18: Duet --- https://adventofcode.com/2017/day/18 """ -from aocd import data from collections import deque + +from aocd import data + from aoc_wim.aoc2017 import Comp # import logging; logging.basicConfig(format="%(message)s", level=logging.DEBUG) diff --git a/aoc_wim/aoc2017/q19.py b/aoc_wim/aoc2017/q19.py index 59af7cf2..fa0c89ff 100644 --- a/aoc_wim/aoc2017/q19.py +++ b/aoc_wim/aoc2017/q19.py @@ -3,6 +3,7 @@ https://adventofcode.com/2017/day/19 """ from aocd import data + from aoc_wim.zgrid import ZGrid diff --git a/aoc_wim/aoc2017/q20.py b/aoc_wim/aoc2017/q20.py index 73b64117..e71c2ee3 100644 --- a/aoc_wim/aoc2017/q20.py +++ b/aoc_wim/aoc2017/q20.py @@ -3,14 +3,14 @@ https://adventofcode.com/2017/day/20 """ from collections import defaultdict +from itertools import batched from aocd import data from parse import parse -from wimpy import chunks def key(p): - return [abs(x) + abs(y) + abs(z) for x, y, z in chunks(reversed(p), 3)] + return [abs(x) + abs(y) + abs(z) for x, y, z in batched(reversed(p), 3)] def abs_accel(p): diff --git a/aoc_wim/aoc2017/q23.py b/aoc_wim/aoc2017/q23.py index 38b89357..5871a58e 100644 --- a/aoc_wim/aoc2017/q23.py +++ b/aoc_wim/aoc2017/q23.py @@ -3,6 +3,7 @@ https://adventofcode.com/2017/day/23 """ from aocd import data + from aoc_wim.aoc2017 import Comp # import logging; logging.basicConfig(format="%(message)s", level=logging.DEBUG) diff --git a/aoc_wim/aoc2018/q06.py b/aoc_wim/aoc2018/q06.py index f172a5ba..683a4883 100644 --- a/aoc_wim/aoc2018/q06.py +++ b/aoc_wim/aoc2018/q06.py @@ -3,6 +3,7 @@ https://adventofcode.com/2018/day/6 """ from io import StringIO + import numpy as np from aocd import data diff --git a/aoc_wim/aoc2018/q10.py b/aoc_wim/aoc2018/q10.py index 9f6485ae..969344af 100644 --- a/aoc_wim/aoc2018/q10.py +++ b/aoc_wim/aoc2018/q10.py @@ -3,8 +3,10 @@ https://adventofcode.com/2018/day/10 """ import re + import numpy as np from aocd import data + from aoc_wim.ocr import AOCR from aoc_wim.zgrid import ZGrid diff --git a/aoc_wim/aoc2018/q18.py b/aoc_wim/aoc2018/q18.py index 5cf3b5d9..cf07c06a 100644 --- a/aoc_wim/aoc2018/q18.py +++ b/aoc_wim/aoc2018/q18.py @@ -3,6 +3,7 @@ https://adventofcode.com/2018/day/18 """ import time + import numpy as np from aocd import data from scipy.signal import convolve2d diff --git a/aoc_wim/aoc2018/q19.py b/aoc_wim/aoc2018/q19.py index 46721693..51be0810 100644 --- a/aoc_wim/aoc2018/q19.py +++ b/aoc_wim/aoc2018/q19.py @@ -3,7 +3,9 @@ https://adventofcode.com/2018/day/19 """ import math + from aocd import data + from aoc_wim.aoc2018.q16 import all_ops diff --git a/aoc_wim/aoc2018/q20.py b/aoc_wim/aoc2018/q20.py index a84a373a..690a5bfc 100644 --- a/aoc_wim/aoc2018/q20.py +++ b/aoc_wim/aoc2018/q20.py @@ -4,6 +4,7 @@ """ import networkx as nx from aocd import data + from aoc_wim.zgrid import manhattan_distance from aoc_wim.zgrid import ZGrid diff --git a/aoc_wim/aoc2018/q22.py b/aoc_wim/aoc2018/q22.py index 13452425..e4c5ea82 100644 --- a/aoc_wim/aoc2018/q22.py +++ b/aoc_wim/aoc2018/q22.py @@ -4,9 +4,10 @@ """ from aocd import data from parse import parse + from aoc_wim.search import AStar -from aoc_wim.zgrid import zrange from aoc_wim.zgrid import manhattan_distance +from aoc_wim.zgrid import zrange # TODO: use zgrid diff --git a/aoc_wim/aoc2018/q23.py b/aoc_wim/aoc2018/q23.py index 7d4ff58c..dcca2102 100644 --- a/aoc_wim/aoc2018/q23.py +++ b/aoc_wim/aoc2018/q23.py @@ -2,11 +2,11 @@ --- Day 23: Experimental Emergency Teleportation --- https://adventofcode.com/2018/day/23 """ +import math from heapq import heappop from heapq import heappush from itertools import product -import math import numpy as np from aocd import data from parse import parse diff --git a/aoc_wim/aoc2018/q24.py b/aoc_wim/aoc2018/q24.py index 0cc4b1a4..19474ae6 100644 --- a/aoc_wim/aoc2018/q24.py +++ b/aoc_wim/aoc2018/q24.py @@ -7,7 +7,6 @@ from aocd import data from parse import parse -from wimpy import strip_prefix log = logging.getLogger(__name__) @@ -60,14 +59,10 @@ def __init__(self, id, text, system, boost=0): self.weak = [] self.immune = [] for prop in props.strip(" ()").split("; "): - if not prop: - continue if prop.startswith("immune to "): - prop = strip_prefix(prop, "immune to ", strict=True) - self.immune.extend(prop.split(", ")) - else: - prop = strip_prefix(prop, "weak to ", strict=True) - self.weak.extend(prop.split(", ")) + self.immune += prop.removeprefix("immune to ").split(", ") + elif prop.startswith("weak to "): + self.weak += prop.removeprefix("weak to ").split(", ") self.target = None @property diff --git a/aoc_wim/aoc2018/q25.py b/aoc_wim/aoc2018/q25.py index 3344816a..912c2481 100644 --- a/aoc_wim/aoc2018/q25.py +++ b/aoc_wim/aoc2018/q25.py @@ -3,6 +3,7 @@ https://adventofcode.com/2018/day/25 """ from itertools import combinations + import networkx as nx from aocd import data diff --git a/aoc_wim/aoc2019/q01.py b/aoc_wim/aoc2019/q01.py index c1f83c80..e57e518d 100644 --- a/aoc_wim/aoc2019/q01.py +++ b/aoc_wim/aoc2019/q01.py @@ -2,8 +2,8 @@ --- Day 1: The Tyranny of the Rocket Equation --- https://adventofcode.com/2019/day/1 """ -from aocd import data import numpy as np +from aocd import data A = np.fromstring(data, dtype=int, sep="\n") diff --git a/aoc_wim/aoc2019/q02.py b/aoc_wim/aoc2019/q02.py index 127b56e5..a6c1c784 100644 --- a/aoc_wim/aoc2019/q02.py +++ b/aoc_wim/aoc2019/q02.py @@ -2,9 +2,10 @@ --- Day 2: 1202 Program Alarm --- https://adventofcode.com/2019/day/2 """ -from aoc_wim.aoc2019 import IntComputer from aocd import data +from aoc_wim.aoc2019 import IntComputer + def part_a(data, r1=None, r2=None): comp = IntComputer(data) diff --git a/aoc_wim/aoc2019/q03.py b/aoc_wim/aoc2019/q03.py index e8b5d744..947ee1c2 100644 --- a/aoc_wim/aoc2019/q03.py +++ b/aoc_wim/aoc2019/q03.py @@ -3,6 +3,7 @@ https://adventofcode.com/2019/day/3 """ from aocd import data + from aoc_wim.zgrid import manhattan_distance from aoc_wim.zgrid import ZGrid diff --git a/aoc_wim/aoc2019/q05.py b/aoc_wim/aoc2019/q05.py index f241a310..809ae7c5 100644 --- a/aoc_wim/aoc2019/q05.py +++ b/aoc_wim/aoc2019/q05.py @@ -2,9 +2,10 @@ --- Day 5: Sunny with a Chance of Asteroids --- https://adventofcode.com/2019/day/5 """ -from aoc_wim.aoc2019 import IntComputer from aocd import data +from aoc_wim.aoc2019 import IntComputer + def compute(data, input_val): comp = IntComputer(data, inputs=[input_val]) diff --git a/aoc_wim/aoc2019/q07.py b/aoc_wim/aoc2019/q07.py index c4b79054..82a4ff54 100644 --- a/aoc_wim/aoc2019/q07.py +++ b/aoc_wim/aoc2019/q07.py @@ -3,7 +3,9 @@ https://adventofcode.com/2019/day/7 """ from itertools import permutations + from aocd import data + from aoc_wim.aoc2019 import IntComputer diff --git a/aoc_wim/aoc2019/q08.py b/aoc_wim/aoc2019/q08.py index fe8d7b47..e5b2fcec 100644 --- a/aoc_wim/aoc2019/q08.py +++ b/aoc_wim/aoc2019/q08.py @@ -2,8 +2,9 @@ --- Day 8: Space Image Format --- https://adventofcode.com/2019/day/8 """ -from aocd import data import numpy as np +from aocd import data + from aoc_wim.ocr import AOCR hw = {16: (2, 2), 12: (2, 3)} diff --git a/aoc_wim/aoc2019/q09.py b/aoc_wim/aoc2019/q09.py index 52b6696d..3e577cc2 100644 --- a/aoc_wim/aoc2019/q09.py +++ b/aoc_wim/aoc2019/q09.py @@ -3,6 +3,7 @@ https://adventofcode.com/2019/day/9 """ from aocd import data + from aoc_wim.aoc2019 import IntComputer diff --git a/aoc_wim/aoc2019/q10.py b/aoc_wim/aoc2019/q10.py index 19638ab3..1704b033 100644 --- a/aoc_wim/aoc2019/q10.py +++ b/aoc_wim/aoc2019/q10.py @@ -3,10 +3,12 @@ https://adventofcode.com/2019/day/10 """ import logging -from aocd import data -from fractions import Fraction from collections import defaultdict +from fractions import Fraction from operator import itemgetter + +from aocd import data + from aoc_wim.zgrid import ZGrid diff --git a/aoc_wim/aoc2019/q11.py b/aoc_wim/aoc2019/q11.py index 85554343..96d5bef1 100644 --- a/aoc_wim/aoc2019/q11.py +++ b/aoc_wim/aoc2019/q11.py @@ -2,10 +2,12 @@ --- Day 11: Space Police --- https://adventofcode.com/2019/day/11 """ +from collections import deque + from aocd import data + from aoc_wim.aoc2019 import IntComputer from aoc_wim.ocr import AOCR -from collections import deque class Robot: diff --git a/aoc_wim/aoc2019/q12.py b/aoc_wim/aoc2019/q12.py index 721f8b79..c8fa1c2f 100644 --- a/aoc_wim/aoc2019/q12.py +++ b/aoc_wim/aoc2019/q12.py @@ -2,11 +2,12 @@ --- Day 12: The N-Body Problem --- https://adventofcode.com/2019/day/12 """ -from aocd import data +import re from itertools import count from math import lcm + import numpy as np -import re +from aocd import data def simulate(data, n=0): diff --git a/aoc_wim/aoc2019/q13.py b/aoc_wim/aoc2019/q13.py index f0bd8131..c1ad8c30 100644 --- a/aoc_wim/aoc2019/q13.py +++ b/aoc_wim/aoc2019/q13.py @@ -3,7 +3,9 @@ https://adventofcode.com/2019/day/13 """ from collections import deque + from aocd import data + from aoc_wim.aoc2019 import IntComputer diff --git a/aoc_wim/aoc2019/q14.py b/aoc_wim/aoc2019/q14.py index 058762a0..14cdd9e3 100644 --- a/aoc_wim/aoc2019/q14.py +++ b/aoc_wim/aoc2019/q14.py @@ -2,10 +2,12 @@ --- Day 14: Space Stoichiometry --- https://adventofcode.com/2019/day/14 """ -from aocd import data from collections import Counter -from aoc_wim.search import Bisect + import networkx as nx +from aocd import data + +from aoc_wim.search import Bisect def parsed(data): diff --git a/aoc_wim/aoc2019/q15.py b/aoc_wim/aoc2019/q15.py index d656ef70..fb84c831 100644 --- a/aoc_wim/aoc2019/q15.py +++ b/aoc_wim/aoc2019/q15.py @@ -3,7 +3,9 @@ https://adventofcode.com/2019/day/15 """ from collections import deque + from aocd import data + from aoc_wim.aoc2019 import IntComputer from aoc_wim.search import AStar from aoc_wim.zgrid import ZGrid diff --git a/aoc_wim/aoc2019/q16.py b/aoc_wim/aoc2019/q16.py index 9dc7f4d9..b81be592 100644 --- a/aoc_wim/aoc2019/q16.py +++ b/aoc_wim/aoc2019/q16.py @@ -2,9 +2,10 @@ --- Day 16: Flawed Frequency Transmission --- https://adventofcode.com/2019/day/16 """ -from aocd import data from itertools import cycle + import numpy as np +from aocd import data def square_wave(w=1): diff --git a/aoc_wim/aoc2019/q17.py b/aoc_wim/aoc2019/q17.py index 1e5cfac9..e4543622 100644 --- a/aoc_wim/aoc2019/q17.py +++ b/aoc_wim/aoc2019/q17.py @@ -3,6 +3,7 @@ https://adventofcode.com/2019/day/17 """ from aocd import data + from aoc_wim.aoc2019 import IntComputer from aoc_wim.zgrid import ZGrid diff --git a/aoc_wim/aoc2019/q18.py b/aoc_wim/aoc2019/q18.py index 2d56be82..65fa2815 100644 --- a/aoc_wim/aoc2019/q18.py +++ b/aoc_wim/aoc2019/q18.py @@ -4,10 +4,12 @@ """ import string from itertools import combinations + +import networkx as nx from aocd import data -from aoc_wim.zgrid import ZGrid + from aoc_wim.search import AStar -import networkx as nx +from aoc_wim.zgrid import ZGrid class Q18AStar(AStar): diff --git a/aoc_wim/aoc2019/q19.py b/aoc_wim/aoc2019/q19.py index 8101a610..0142dc9d 100644 --- a/aoc_wim/aoc2019/q19.py +++ b/aoc_wim/aoc2019/q19.py @@ -2,11 +2,13 @@ --- Day 19: Tractor Beam --- https://adventofcode.com/2019/day/19 """ +import functools + from aocd import data + from aoc_wim.aoc2019 import IntComputer -from aoc_wim.zgrid import ZGrid from aoc_wim.search import Bisect -import functools +from aoc_wim.zgrid import ZGrid @functools.lru_cache(maxsize=100**2) diff --git a/aoc_wim/aoc2019/q20.py b/aoc_wim/aoc2019/q20.py index dbe69d7d..0453c955 100644 --- a/aoc_wim/aoc2019/q20.py +++ b/aoc_wim/aoc2019/q20.py @@ -2,12 +2,14 @@ --- Day 20: Donut Maze --- https://adventofcode.com/2019/day/20 """ -from aocd import data -from aoc_wim.zgrid import ZGrid -from aoc_wim.search import AStar -from bidict import bidict import string + import numpy as np +from aocd import data +from bidict import bidict + +from aoc_wim.search import AStar +from aoc_wim.zgrid import ZGrid grid = ZGrid(data, on=".", off="#") h, w = np.array(grid).shape diff --git a/aoc_wim/aoc2019/q21.py b/aoc_wim/aoc2019/q21.py index a3d40bc2..aeb2bd3b 100644 --- a/aoc_wim/aoc2019/q21.py +++ b/aoc_wim/aoc2019/q21.py @@ -3,6 +3,7 @@ https://adventofcode.com/2019/day/21 """ from aocd import data + from aoc_wim.aoc2019 import IntComputer # Jump if (there's a hole 1 space away (not A) diff --git a/aoc_wim/aoc2019/q22.py b/aoc_wim/aoc2019/q22.py index ae92f91e..8fe0db12 100644 --- a/aoc_wim/aoc2019/q22.py +++ b/aoc_wim/aoc2019/q22.py @@ -3,6 +3,7 @@ https://adventofcode.com/2019/day/22 """ from math import prod + from aocd import data diff --git a/aoc_wim/aoc2019/q23.py b/aoc_wim/aoc2019/q23.py index 1b7a4550..df8d5b84 100644 --- a/aoc_wim/aoc2019/q23.py +++ b/aoc_wim/aoc2019/q23.py @@ -3,7 +3,9 @@ https://adventofcode.com/2019/day/23 """ import logging + from aocd import data + from aoc_wim.aoc2019 import IntComputer diff --git a/aoc_wim/aoc2019/q24.py b/aoc_wim/aoc2019/q24.py index 28df969a..9a7ecb98 100644 --- a/aoc_wim/aoc2019/q24.py +++ b/aoc_wim/aoc2019/q24.py @@ -3,6 +3,7 @@ https://adventofcode.com/2019/day/24 """ from aocd import data + from aoc_wim.zgrid import ZGrid diff --git a/aoc_wim/aoc2019/q25.py b/aoc_wim/aoc2019/q25.py index ddd5b453..5b25a115 100644 --- a/aoc_wim/aoc2019/q25.py +++ b/aoc_wim/aoc2019/q25.py @@ -4,11 +4,13 @@ """ import logging from collections import deque +from functools import cached_property +from itertools import combinations + import anytree from aocd import data + from aoc_wim.aoc2019 import IntComputer -from itertools import combinations -from wimpy.util import cached_property log = logging.getLogger(__name__) diff --git a/aoc_wim/aoc2020/q01.py b/aoc_wim/aoc2020/q01.py index 0d80ff14..d80dd942 100644 --- a/aoc_wim/aoc2020/q01.py +++ b/aoc_wim/aoc2020/q01.py @@ -3,7 +3,9 @@ https://adventofcode.com/2020/day/1 """ from collections import Counter + from aocd import data + from aoc_wim.aoc2020 import find_pair diff --git a/aoc_wim/aoc2020/q03.py b/aoc_wim/aoc2020/q03.py index 097df758..156e24db 100644 --- a/aoc_wim/aoc2020/q03.py +++ b/aoc_wim/aoc2020/q03.py @@ -3,7 +3,9 @@ https://adventofcode.com/2020/day/3 """ from math import prod + from aocd import data + from aoc_wim.zgrid import ZGrid grid = ZGrid(data) diff --git a/aoc_wim/aoc2020/q04.py b/aoc_wim/aoc2020/q04.py index 6df41336..10240c42 100644 --- a/aoc_wim/aoc2020/q04.py +++ b/aoc_wim/aoc2020/q04.py @@ -10,8 +10,8 @@ from marshmallow.validate import OneOf from marshmallow.validate import Range from marshmallow.validate import Regexp -from marshmallow.validate import Validator from marshmallow.validate import ValidationError +from marshmallow.validate import Validator class Height(Validator): diff --git a/aoc_wim/aoc2020/q07.py b/aoc_wim/aoc2020/q07.py index b7867781..bbbb52e9 100644 --- a/aoc_wim/aoc2020/q07.py +++ b/aoc_wim/aoc2020/q07.py @@ -2,9 +2,10 @@ --- Day 7: Handy Haversacks --- https://adventofcode.com/2020/day/7 """ -from aocd import data from collections import deque + import networkx as nx +from aocd import data g = nx.DiGraph() for line in data.splitlines(): diff --git a/aoc_wim/aoc2020/q08.py b/aoc_wim/aoc2020/q08.py index 2578c83d..cabbf91a 100644 --- a/aoc_wim/aoc2020/q08.py +++ b/aoc_wim/aoc2020/q08.py @@ -3,6 +3,7 @@ https://adventofcode.com/2020/day/8 """ from aocd import data + from aoc_wim.aoc2020 import Comp # import logging; logging.basicConfig(format="%(message)s", level=logging.DEBUG) diff --git a/aoc_wim/aoc2020/q09.py b/aoc_wim/aoc2020/q09.py index 3e1c3485..c7b7232d 100644 --- a/aoc_wim/aoc2020/q09.py +++ b/aoc_wim/aoc2020/q09.py @@ -3,7 +3,7 @@ https://adventofcode.com/2020/day/9 """ from aocd import data -from wimpy import chunks + from aoc_wim.aoc2020 import find_pair numbers = [int(x) for x in data.splitlines()] @@ -11,10 +11,14 @@ if len(numbers) < n: n = 5 # hackish - lower "preamble" for the example test to work -for *pre, target in chunks(numbers, chunk_size=n + 1, overlap=n): - if find_pair(set(pre), target) is None: +pre = set(numbers[:n]) +for i in range(n, len(numbers)): + target = numbers[i] + if find_pair(pre, target) is None: print("answer_a:", target) break + pre.remove(numbers[i - n]) + pre.add(target) start = 0 stop = 2 diff --git a/aoc_wim/aoc2020/q10.py b/aoc_wim/aoc2020/q10.py index 4ebf6849..3cbf7d27 100644 --- a/aoc_wim/aoc2020/q10.py +++ b/aoc_wim/aoc2020/q10.py @@ -3,6 +3,7 @@ https://adventofcode.com/2020/day/10 """ from aocd import data + from aoc_wim.stuff import Tribonacci numbers = [int(x) for x in data.split()] diff --git a/aoc_wim/aoc2020/q11.py b/aoc_wim/aoc2020/q11.py index 5baceb39..c00a4dcb 100644 --- a/aoc_wim/aoc2020/q11.py +++ b/aoc_wim/aoc2020/q11.py @@ -3,6 +3,7 @@ https://adventofcode.com/2020/day/11 """ from aocd import data + from aoc_wim.zgrid import ZGrid diff --git a/aoc_wim/aoc2020/q12.py b/aoc_wim/aoc2020/q12.py index b4982fab..33d0576a 100644 --- a/aoc_wim/aoc2020/q12.py +++ b/aoc_wim/aoc2020/q12.py @@ -3,8 +3,9 @@ https://adventofcode.com/2020/day/12 """ from aocd import data -from aoc_wim.zgrid import ZGrid + from aoc_wim.zgrid import manhattan_distance +from aoc_wim.zgrid import ZGrid za = zb = 0 # ferry dza = ZGrid.east # direction (part a) diff --git a/aoc_wim/aoc2020/q13.py b/aoc_wim/aoc2020/q13.py index 649e8dfd..10c940fc 100644 --- a/aoc_wim/aoc2020/q13.py +++ b/aoc_wim/aoc2020/q13.py @@ -3,6 +3,7 @@ https://adventofcode.com/2020/day/13 """ import math + from aocd import data t0, table = data.splitlines() diff --git a/aoc_wim/aoc2020/q14.py b/aoc_wim/aoc2020/q14.py index c6a0ac6d..087a1b1f 100644 --- a/aoc_wim/aoc2020/q14.py +++ b/aoc_wim/aoc2020/q14.py @@ -2,9 +2,10 @@ --- Day 14: Docking Data --- https://adventofcode.com/2020/day/14 """ -from aocd import data from itertools import combinations +from aocd import data + da = {} db = {} for line in data.splitlines(): diff --git a/aoc_wim/aoc2020/q16.py b/aoc_wim/aoc2020/q16.py index 12fb971b..6b3c8a49 100644 --- a/aoc_wim/aoc2020/q16.py +++ b/aoc_wim/aoc2020/q16.py @@ -2,9 +2,10 @@ --- Day 16: Ticket Translation --- https://adventofcode.com/2020/day/16 """ -from aocd import data from math import prod +from aocd import data + def parsed(data): fields_raw, my_ticket_raw, nearby_tickets_raw = data.split("\n\n") diff --git a/aoc_wim/aoc2020/q17.py b/aoc_wim/aoc2020/q17.py index 7f12a8b5..8bb09c93 100644 --- a/aoc_wim/aoc2020/q17.py +++ b/aoc_wim/aoc2020/q17.py @@ -2,8 +2,8 @@ --- Day 17: Conway Cubes --- https://adventofcode.com/2020/day/17 """ -from aocd import data import numpy as np +from aocd import data from scipy.signal import convolve diff --git a/aoc_wim/aoc2020/q17_sans_scipy.py b/aoc_wim/aoc2020/q17_sans_scipy.py index 57b3a8bc..50fe87a1 100644 --- a/aoc_wim/aoc2020/q17_sans_scipy.py +++ b/aoc_wim/aoc2020/q17_sans_scipy.py @@ -2,9 +2,10 @@ --- Day 17: Conway Cubes --- https://adventofcode.com/2020/day/17 """ -from aocd import data from itertools import product + import numpy as np +from aocd import data def evolve(A): diff --git a/aoc_wim/aoc2020/q18.py b/aoc_wim/aoc2020/q18.py index aa2d30e8..8eed1726 100644 --- a/aoc_wim/aoc2020/q18.py +++ b/aoc_wim/aoc2020/q18.py @@ -2,9 +2,10 @@ --- Day 18: Operation Order --- https://adventofcode.com/2020/day/18 """ -from aocd import data from collections import deque +from aocd import data + def evaluate(d, part="a"): op = "*" diff --git a/aoc_wim/aoc2020/q19.py b/aoc_wim/aoc2020/q19.py index 35844ec7..29afa22a 100644 --- a/aoc_wim/aoc2020/q19.py +++ b/aoc_wim/aoc2020/q19.py @@ -2,8 +2,8 @@ --- Day 19: Monster Messages --- https://adventofcode.com/2020/day/19 """ -from aocd import data import regex as re +from aocd import data rules_raw, messages = data.replace('"', "").split("\n\n") diff --git a/aoc_wim/aoc2020/q19_lark.py b/aoc_wim/aoc2020/q19_lark.py index 7993b8e6..98575e3a 100644 --- a/aoc_wim/aoc2020/q19_lark.py +++ b/aoc_wim/aoc2020/q19_lark.py @@ -2,8 +2,8 @@ --- Day 19: Monster Messages --- https://adventofcode.com/2020/day/19 """ -from aocd import data import lark +from aocd import data def solve(rules, messages): diff --git a/aoc_wim/aoc2020/q20.py b/aoc_wim/aoc2020/q20.py index 3ccbeb62..30bfb364 100644 --- a/aoc_wim/aoc2020/q20.py +++ b/aoc_wim/aoc2020/q20.py @@ -3,12 +3,14 @@ https://adventofcode.com/2020/day/20 """ import math -from aocd import data -from aoc_wim.zgrid import ZGrid +from itertools import combinations + import networkx as nx import numpy as np +from aocd import data from parse import parse -from itertools import combinations + +from aoc_wim.zgrid import ZGrid class Tile: diff --git a/aoc_wim/aoc2020/q22.py b/aoc_wim/aoc2020/q22.py index d337859f..6480ca99 100644 --- a/aoc_wim/aoc2020/q22.py +++ b/aoc_wim/aoc2020/q22.py @@ -2,10 +2,11 @@ --- Day 22: Crab Combat --- https://adventofcode.com/2020/day/22 """ -from aocd import data from collections import deque from itertools import islice +from aocd import data + def play(p1, p2, part="a"): seen = set() diff --git a/aoc_wim/aoc2020/q23.py b/aoc_wim/aoc2020/q23.py index b63d19f9..a252d31a 100644 --- a/aoc_wim/aoc2020/q23.py +++ b/aoc_wim/aoc2020/q23.py @@ -2,9 +2,10 @@ --- Day 23: Crab Cups --- https://adventofcode.com/2020/day/23 """ -from aocd import data from operator import attrgetter +from aocd import data + class Cup: diff --git a/aoc_wim/aoc2020/q24.py b/aoc_wim/aoc2020/q24.py index 434cc2bb..572345f9 100644 --- a/aoc_wim/aoc2020/q24.py +++ b/aoc_wim/aoc2020/q24.py @@ -2,8 +2,10 @@ --- Day 24: Lobby Layout --- https://adventofcode.com/2020/day/24 """ -from aocd import data import re + +from aocd import data + from aoc_wim import zgrid diff --git a/aoc_wim/aoc2020/q24_scipy.py b/aoc_wim/aoc2020/q24_scipy.py index 2a8acd08..421bb6b9 100644 --- a/aoc_wim/aoc2020/q24_scipy.py +++ b/aoc_wim/aoc2020/q24_scipy.py @@ -2,12 +2,14 @@ --- Day 24: Lobby Layout --- https://adventofcode.com/2020/day/24 """ -from aocd import data import re -from aoc_wim import zgrid + import numpy as np +from aocd import data from scipy.signal import convolve2d +from aoc_wim import zgrid + pat = r"(se|sw|ne|nw|e|w)" grid = zgrid.ZGrid(on=1, off=0) diff --git a/aoc_wim/aoc2021/q02.py b/aoc_wim/aoc2021/q02.py index 606b30db..2a53b9dc 100644 --- a/aoc_wim/aoc2021/q02.py +++ b/aoc_wim/aoc2021/q02.py @@ -3,6 +3,7 @@ https://adventofcode.com/2021/day/2 """ from aocd import data + from aoc_wim.zgrid import ZGrid aim = za = zb = 0 diff --git a/aoc_wim/aoc2021/q05.py b/aoc_wim/aoc2021/q05.py index 72df7bf9..8fcdfdfe 100644 --- a/aoc_wim/aoc2021/q05.py +++ b/aoc_wim/aoc2021/q05.py @@ -2,8 +2,9 @@ --- Day 5: Hydrothermal Venture --- https://adventofcode.com/2021/day/5 """ -from aocd import data from collections import Counter + +from aocd import data from parse import parse da = Counter() diff --git a/aoc_wim/aoc2021/q07.py b/aoc_wim/aoc2021/q07.py index 4cf97340..ec266641 100644 --- a/aoc_wim/aoc2021/q07.py +++ b/aoc_wim/aoc2021/q07.py @@ -2,8 +2,8 @@ --- Day 7: The Treachery of Whales --- https://adventofcode.com/2021/day/7 """ -from aocd import data import numpy as np +from aocd import data A = np.array([int(n) for n in data.split(",")]) a = b = np.inf diff --git a/aoc_wim/aoc2021/q08.py b/aoc_wim/aoc2021/q08.py index 086e9d13..c9493af2 100644 --- a/aoc_wim/aoc2021/q08.py +++ b/aoc_wim/aoc2021/q08.py @@ -2,9 +2,10 @@ --- Day 8: Seven Segment Search --- https://adventofcode.com/2021/day/8 """ -from aocd import data from itertools import permutations +from aocd import data + segments = { 1: "cf", 7: "acf", diff --git a/aoc_wim/aoc2021/q09.py b/aoc_wim/aoc2021/q09.py index f9d7e982..5e843ad3 100644 --- a/aoc_wim/aoc2021/q09.py +++ b/aoc_wim/aoc2021/q09.py @@ -2,8 +2,9 @@ --- Day 9: Smoke Basin --- https://adventofcode.com/2021/day/9 """ -from aocd import data import networkx as nx +from aocd import data + from aoc_wim.zgrid import ZGrid g = ZGrid(data) diff --git a/aoc_wim/aoc2021/q10.py b/aoc_wim/aoc2021/q10.py index 5988686e..9061e0c0 100644 --- a/aoc_wim/aoc2021/q10.py +++ b/aoc_wim/aoc2021/q10.py @@ -2,9 +2,10 @@ --- Day 10: Syntax Scoring --- https://adventofcode.com/2021/day/10 """ -from aocd import data from statistics import median +from aocd import data + class ParserError(Exception): def __init__(self, line, expected, found): diff --git a/aoc_wim/aoc2021/q11.py b/aoc_wim/aoc2021/q11.py index e39d32ff..1557234b 100644 --- a/aoc_wim/aoc2021/q11.py +++ b/aoc_wim/aoc2021/q11.py @@ -3,6 +3,7 @@ https://adventofcode.com/2021/day/11 """ from aocd import data + from aoc_wim.zgrid import ZGrid diff --git a/aoc_wim/aoc2021/q12.py b/aoc_wim/aoc2021/q12.py index d0092f83..7c8c7f2d 100644 --- a/aoc_wim/aoc2021/q12.py +++ b/aoc_wim/aoc2021/q12.py @@ -2,10 +2,11 @@ --- Day 12: Passage Pathing --- https://adventofcode.com/2021/day/12 """ -from aocd import data from collections import defaultdict from collections import deque +from aocd import data + caves = defaultdict(set) for line in data.splitlines(): diff --git a/aoc_wim/aoc2021/q13.py b/aoc_wim/aoc2021/q13.py index 17511b7d..c708f173 100644 --- a/aoc_wim/aoc2021/q13.py +++ b/aoc_wim/aoc2021/q13.py @@ -2,9 +2,11 @@ --- Day 13: Transparent Origami --- https://adventofcode.com/2021/day/13 """ +from ast import literal_eval + from aocd import data + from aoc_wim.ocr import AOCR -from ast import literal_eval zs, folds = data.replace(",", "+").split("\n\n") d = {literal_eval(z + "j"): "#" for z in zs.split()} diff --git a/aoc_wim/aoc2021/q14.py b/aoc_wim/aoc2021/q14.py index e1ff6c50..cd215f3a 100644 --- a/aoc_wim/aoc2021/q14.py +++ b/aoc_wim/aoc2021/q14.py @@ -3,6 +3,7 @@ https://adventofcode.com/2021/day/14 """ from collections import Counter + from aocd import data polymer, rules = data.split("\n\n") diff --git a/aoc_wim/aoc2021/q16.py b/aoc_wim/aoc2021/q16.py index 0f2e4b44..3b14751b 100644 --- a/aoc_wim/aoc2021/q16.py +++ b/aoc_wim/aoc2021/q16.py @@ -4,6 +4,7 @@ """ import io import math + from aocd import data diff --git a/aoc_wim/aoc2021/q17.py b/aoc_wim/aoc2021/q17.py index f1ccdccd..809e927d 100644 --- a/aoc_wim/aoc2021/q17.py +++ b/aoc_wim/aoc2021/q17.py @@ -4,6 +4,7 @@ """ from aocd import data from parse import parse + from aoc_wim.zgrid import ZGrid diff --git a/aoc_wim/aoc2021/q18.py b/aoc_wim/aoc2021/q18.py index 56b23601..c18b8b94 100644 --- a/aoc_wim/aoc2021/q18.py +++ b/aoc_wim/aoc2021/q18.py @@ -2,9 +2,10 @@ --- Day 18: Snailfish --- https://adventofcode.com/2021/day/18 """ -from aocd import data import json +from aocd import data + class SnailfishNumber: """shh, it's really a binary tree""" diff --git a/aoc_wim/aoc2021/q19.py b/aoc_wim/aoc2021/q19.py index 984eb300..54bfebb5 100644 --- a/aoc_wim/aoc2021/q19.py +++ b/aoc_wim/aoc2021/q19.py @@ -2,12 +2,13 @@ --- Day 19: Beacon Scanner --- https://adventofcode.com/2021/day/19 """ -from aocd import data -from parse import parse -import numpy as np -from itertools import combinations import heapq +from itertools import combinations + import networkx as nx +import numpy as np +from aocd import data +from parse import parse from scipy.spatial.transform import Rotation as R Rx = R.from_rotvec([np.pi/2, 0, 0]).as_matrix().astype(int) diff --git a/aoc_wim/aoc2021/q20.py b/aoc_wim/aoc2021/q20.py index a9e7aa0b..1f01ebb5 100644 --- a/aoc_wim/aoc2021/q20.py +++ b/aoc_wim/aoc2021/q20.py @@ -2,8 +2,8 @@ --- Day 20: Trench Map --- https://adventofcode.com/2021/day/20 """ -from aocd import data import numpy as np +from aocd import data from scipy.signal import convolve2d s, grid = data.split("\n\n") diff --git a/aoc_wim/aoc2021/q21.py b/aoc_wim/aoc2021/q21.py index 77a4c09e..633c14ee 100644 --- a/aoc_wim/aoc2021/q21.py +++ b/aoc_wim/aoc2021/q21.py @@ -2,9 +2,10 @@ --- Day 21: Dirac Dice --- https://adventofcode.com/2021/day/21 """ -from aocd import data from collections import Counter +from aocd import data + def play_deterministic(p1, p2): pos = [p1, p2] diff --git a/aoc_wim/aoc2021/q22.py b/aoc_wim/aoc2021/q22.py index 671d5846..69a583d2 100644 --- a/aoc_wim/aoc2021/q22.py +++ b/aoc_wim/aoc2021/q22.py @@ -2,9 +2,10 @@ --- Day 22: Reactor Reboot --- https://adventofcode.com/2021/day/22 """ +from dataclasses import dataclass + from aocd import data from parse import parse -from dataclasses import dataclass @dataclass diff --git a/aoc_wim/aoc2021/q22_slow.py b/aoc_wim/aoc2021/q22_slow.py index f672c4b3..9bf5fa5c 100644 --- a/aoc_wim/aoc2021/q22_slow.py +++ b/aoc_wim/aoc2021/q22_slow.py @@ -2,9 +2,10 @@ --- Day 22: Reactor Reboot --- https://adventofcode.com/2021/day/22 """ +from dataclasses import dataclass + from aocd import data from parse import parse -from dataclasses import dataclass @dataclass diff --git a/aoc_wim/aoc2021/q23.py b/aoc_wim/aoc2021/q23.py index a41f1473..42b53057 100644 --- a/aoc_wim/aoc2021/q23.py +++ b/aoc_wim/aoc2021/q23.py @@ -2,11 +2,12 @@ --- Day 23: Amphipod --- https://adventofcode.com/2021/day/23 """ +import networkx as nx from aocd import data + from aoc_wim.search import AStar -import networkx as nx -from aoc_wim.zgrid import ZGrid from aoc_wim.zgrid import manhattan_distance +from aoc_wim.zgrid import ZGrid class Q23AStar(AStar): diff --git a/aoc_wim/aoc2021/q24.py b/aoc_wim/aoc2021/q24.py index 70bfcc9a..8aeb7a3d 100644 --- a/aoc_wim/aoc2021/q24.py +++ b/aoc_wim/aoc2021/q24.py @@ -2,8 +2,8 @@ --- Day 24: Arithmetic Logic Unit --- https://adventofcode.com/2021/day/24 """ -from aocd import data import parse +from aocd import data class Comp: diff --git a/aoc_wim/aoc2021/q25.py b/aoc_wim/aoc2021/q25.py index 267b4ccd..47f75063 100644 --- a/aoc_wim/aoc2021/q25.py +++ b/aoc_wim/aoc2021/q25.py @@ -3,6 +3,7 @@ https://adventofcode.com/2021/day/25 """ from aocd import data + from aoc_wim.zgrid import ZGrid diff --git a/aoc_wim/aoc2022/q01.py b/aoc_wim/aoc2022/q01.py index 5772c136..65cde2f2 100644 --- a/aoc_wim/aoc2022/q01.py +++ b/aoc_wim/aoc2022/q01.py @@ -2,9 +2,10 @@ --- Day 1: Calorie Counting --- https://adventofcode.com/2022/day/1 """ -from aocd import data from heapq import nlargest +from aocd import data + cals = [] for chunk in data.split("\n\n"): cals.append(sum(map(int, chunk.split()))) diff --git a/aoc_wim/aoc2022/q02.py b/aoc_wim/aoc2022/q02.py index d1853ea2..2a5a82da 100644 --- a/aoc_wim/aoc2022/q02.py +++ b/aoc_wim/aoc2022/q02.py @@ -2,11 +2,12 @@ --- Day 2: Rock Paper Scissors --- https://adventofcode.com/2022/day/2 """ -from aocd import data from enum import Enum -from bidict import bidict from functools import cached_property +from aocd import data +from bidict import bidict + class Shape(Enum): A = X = Rock = 1 diff --git a/aoc_wim/aoc2022/q03.py b/aoc_wim/aoc2022/q03.py index ab82f69b..c9414cef 100644 --- a/aoc_wim/aoc2022/q03.py +++ b/aoc_wim/aoc2022/q03.py @@ -2,8 +2,9 @@ --- Day 3: Rucksack Reorganization --- https://adventofcode.com/2022/day/3 """ +from itertools import batched + from aocd import data -from wimpy import chunks a = 0 for line in data.splitlines(): @@ -14,7 +15,7 @@ a += ord(c.lower()) - ord("a") + 1 b = 0 -for s1, s2, s3 in chunks(data.splitlines()): +for s1, s2, s3 in batched(data.splitlines(), 3): [c] = set(s1).intersection(s2, s3) b += c.isupper() * 26 b += ord(c.lower()) - ord("a") + 1 diff --git a/aoc_wim/aoc2022/q06.py b/aoc_wim/aoc2022/q06.py index 971c0dc1..36c9aaf4 100644 --- a/aoc_wim/aoc2022/q06.py +++ b/aoc_wim/aoc2022/q06.py @@ -2,9 +2,10 @@ --- Day 6: Tuning Trouble --- https://adventofcode.com/2022/day/6 """ -from aocd import data from collections import Counter +from aocd import data + def marker(data, n): counts = Counter(data[:n]) diff --git a/aoc_wim/aoc2022/q07.py b/aoc_wim/aoc2022/q07.py index 1afa87b0..faf0d502 100644 --- a/aoc_wim/aoc2022/q07.py +++ b/aoc_wim/aoc2022/q07.py @@ -2,9 +2,10 @@ --- Day 7: No Space Left On Device --- https://adventofcode.com/2022/day/7 """ -from aocd import data -from pathlib import Path from collections import Counter +from pathlib import Path + +from aocd import data cwd = root = Path("/") dirs = Counter() diff --git a/aoc_wim/aoc2022/q08.py b/aoc_wim/aoc2022/q08.py index cc2a40f5..56073177 100644 --- a/aoc_wim/aoc2022/q08.py +++ b/aoc_wim/aoc2022/q08.py @@ -3,7 +3,9 @@ https://adventofcode.com/2022/day/8 """ from aocd import data -from aoc_wim.zgrid import ZGrid, zrange + +from aoc_wim.zgrid import ZGrid +from aoc_wim.zgrid import zrange grid = ZGrid(data, transform=int) h, w = grid.height, grid.width diff --git a/aoc_wim/aoc2022/q10.py b/aoc_wim/aoc2022/q10.py index 3af0ec7d..2e391453 100644 --- a/aoc_wim/aoc2022/q10.py +++ b/aoc_wim/aoc2022/q10.py @@ -3,6 +3,7 @@ https://adventofcode.com/2022/day/10 """ from aocd import data + from aoc_wim.ocr import AOCR diff --git a/aoc_wim/aoc2022/q11.py b/aoc_wim/aoc2022/q11.py index 8424f0bb..72e32d43 100644 --- a/aoc_wim/aoc2022/q11.py +++ b/aoc_wim/aoc2022/q11.py @@ -2,12 +2,13 @@ --- Day 11: Monkey in the Middle --- https://adventofcode.com/2022/day/11 """ -from aocd import data -from parse import parse from collections import deque from heapq import nlargest from math import prod +from aocd import data +from parse import parse + template = """\ Monkey {:d}: diff --git a/aoc_wim/aoc2022/q12.py b/aoc_wim/aoc2022/q12.py index 6734ff74..30735c01 100644 --- a/aoc_wim/aoc2022/q12.py +++ b/aoc_wim/aoc2022/q12.py @@ -3,8 +3,9 @@ https://adventofcode.com/2022/day/12 """ from aocd import data -from aoc_wim.zgrid import ZGrid + from aoc_wim.search import AStar +from aoc_wim.zgrid import ZGrid grid = ZGrid(data) start = grid.z("S") diff --git a/aoc_wim/aoc2022/q13.py b/aoc_wim/aoc2022/q13.py index f1089589..3b7886c9 100644 --- a/aoc_wim/aoc2022/q13.py +++ b/aoc_wim/aoc2022/q13.py @@ -2,9 +2,10 @@ --- Day 13: Distress Signal --- https://adventofcode.com/2022/day/13 """ -from aocd import data -from json import loads from functools import cmp_to_key +from json import loads + +from aocd import data def cmp(a, b): diff --git a/aoc_wim/aoc2022/q13_rich.py b/aoc_wim/aoc2022/q13_rich.py index 701a6b15..adadbf73 100644 --- a/aoc_wim/aoc2022/q13_rich.py +++ b/aoc_wim/aoc2022/q13_rich.py @@ -2,9 +2,10 @@ --- Day 13: Distress Signal --- https://adventofcode.com/2022/day/13 """ -from aocd import data from json import loads +from aocd import data + class Packet: diff --git a/aoc_wim/aoc2022/q14.py b/aoc_wim/aoc2022/q14.py index 7b3327ec..24acab78 100644 --- a/aoc_wim/aoc2022/q14.py +++ b/aoc_wim/aoc2022/q14.py @@ -3,10 +3,12 @@ https://adventofcode.com/2022/day/14 """ import os + from aocd import data + +from aoc_wim.search import BFS from aoc_wim.zgrid import ZGrid from aoc_wim.zgrid import zline -from aoc_wim.search import BFS grid = ZGrid() for line in data.splitlines(): diff --git a/aoc_wim/aoc2022/q15.py b/aoc_wim/aoc2022/q15.py index ff0b7836..5ee41700 100644 --- a/aoc_wim/aoc2022/q15.py +++ b/aoc_wim/aoc2022/q15.py @@ -2,11 +2,13 @@ --- Day 15: Beacon Exclusion Zone --- https://adventofcode.com/2022/day/15 """ +from itertools import combinations + from aocd import data +from intervaltree import IntervalTree from parse import parse + from aoc_wim.zgrid import manhattan_distance -from intervaltree import IntervalTree -from itertools import combinations class Sensor: diff --git a/aoc_wim/aoc2022/q16.py b/aoc_wim/aoc2022/q16.py index 21022c2a..8de1e7c3 100644 --- a/aoc_wim/aoc2022/q16.py +++ b/aoc_wim/aoc2022/q16.py @@ -2,10 +2,11 @@ --- Day 16: Proboscidea Volcanium --- https://adventofcode.com/2022/day/16 """ -from aocd import data +import itertools from collections import defaultdict from collections import deque -import itertools + +from aocd import data from parse import parse diff --git a/aoc_wim/aoc2022/q17.py b/aoc_wim/aoc2022/q17.py index 17c517fc..aa7fbeec 100644 --- a/aoc_wim/aoc2022/q17.py +++ b/aoc_wim/aoc2022/q17.py @@ -3,6 +3,7 @@ https://adventofcode.com/2022/day/17 """ from aocd import data + from aoc_wim.zgrid import ZGrid diff --git a/aoc_wim/aoc2022/q18.py b/aoc_wim/aoc2022/q18.py index 8039cd1a..0acd8124 100644 --- a/aoc_wim/aoc2022/q18.py +++ b/aoc_wim/aoc2022/q18.py @@ -2,10 +2,11 @@ --- Day 18: Boiling Boulders --- https://adventofcode.com/2022/day/18 """ -from aocd import data -import networkx as nx from itertools import product +import networkx as nx +from aocd import data + def adj6(x, y, z): return [ diff --git a/aoc_wim/aoc2022/q19.py b/aoc_wim/aoc2022/q19.py index af4162b4..029cbf20 100644 --- a/aoc_wim/aoc2022/q19.py +++ b/aoc_wim/aoc2022/q19.py @@ -2,10 +2,11 @@ --- Day 19: Not Enough Minerals --- https://adventofcode.com/2022/day/19 """ -from aocd import data import math import re +from aocd import data + lines = data.split("\n\n") if "\n\n" in data else data.splitlines() bps = [] diff --git a/aoc_wim/aoc2022/q21.py b/aoc_wim/aoc2022/q21.py index b95e1bd5..bafb9ae5 100644 --- a/aoc_wim/aoc2022/q21.py +++ b/aoc_wim/aoc2022/q21.py @@ -2,9 +2,10 @@ --- Day 21: Monkey Math --- https://adventofcode.com/2022/day/21 """ -from aocd import data import operator as op +from aocd import data + ops = { "+": op.add, "*": op.mul, diff --git a/aoc_wim/aoc2022/q22.py b/aoc_wim/aoc2022/q22.py index 297f9697..e107c4b6 100644 --- a/aoc_wim/aoc2022/q22.py +++ b/aoc_wim/aoc2022/q22.py @@ -4,7 +4,9 @@ """ import math import re + from aocd import data + from aoc_wim.zgrid import ZGrid diff --git a/aoc_wim/aoc2022/q23.py b/aoc_wim/aoc2022/q23.py index 39fdd32e..6845a34b 100644 --- a/aoc_wim/aoc2022/q23.py +++ b/aoc_wim/aoc2022/q23.py @@ -2,9 +2,10 @@ --- Day 23: Unstable Diffusion --- https://adventofcode.com/2022/day/23 """ -from aocd import data import numpy as np +from aocd import data from scipy.signal import convolve2d + from aoc_wim.ocr import autocrop diff --git a/aoc_wim/aoc2022/q23_sans_scipy.py b/aoc_wim/aoc2022/q23_sans_scipy.py index 5165a080..761e3a03 100644 --- a/aoc_wim/aoc2022/q23_sans_scipy.py +++ b/aoc_wim/aoc2022/q23_sans_scipy.py @@ -2,11 +2,13 @@ --- Day 23: Unstable Diffusion --- https://adventofcode.com/2022/day/23 """ -from aocd import data -from aoc_wim.zgrid import ZGrid from collections import defaultdict from collections import deque +from aocd import data + +from aoc_wim.zgrid import ZGrid + grid = ZGrid(data, transform={".": None}) edges = deque([ diff --git a/aoc_wim/aoc2022/q24.py b/aoc_wim/aoc2022/q24.py index 1f0697df..3fff1dfa 100644 --- a/aoc_wim/aoc2022/q24.py +++ b/aoc_wim/aoc2022/q24.py @@ -3,6 +3,7 @@ https://adventofcode.com/2022/day/24 """ from aocd import data + from aoc_wim.zgrid import ZGrid diff --git a/aoc_wim/aoc2023/q02.py b/aoc_wim/aoc2023/q02.py index 00339233..6af03995 100644 --- a/aoc_wim/aoc2023/q02.py +++ b/aoc_wim/aoc2023/q02.py @@ -2,9 +2,10 @@ --- Day 2: Cube Conundrum --- https://adventofcode.com/2023/day/2 """ -from aocd import data -from math import prod from collections import Counter +from math import prod + +from aocd import data bag = Counter("rgb"*12 + "g" + "bb") a = b = 0 diff --git a/aoc_wim/aoc2023/q03.py b/aoc_wim/aoc2023/q03.py index 023b0e6d..4b70f020 100644 --- a/aoc_wim/aoc2023/q03.py +++ b/aoc_wim/aoc2023/q03.py @@ -3,6 +3,7 @@ https://adventofcode.com/2023/day/3 """ from aocd import data + from aoc_wim.zgrid import ZGrid g = ZGrid(data) diff --git a/aoc_wim/aoc2023/q06.py b/aoc_wim/aoc2023/q06.py index b307d1fc..b06f7a7c 100644 --- a/aoc_wim/aoc2023/q06.py +++ b/aoc_wim/aoc2023/q06.py @@ -2,7 +2,9 @@ --- Day 6: Wait For It --- https://adventofcode.com/2023/day/6 """ -from math import prod, sqrt +from math import prod +from math import sqrt + from aocd import data diff --git a/aoc_wim/aoc2023/q07.py b/aoc_wim/aoc2023/q07.py index 41a5f8e7..8c33a7b4 100644 --- a/aoc_wim/aoc2023/q07.py +++ b/aoc_wim/aoc2023/q07.py @@ -2,9 +2,10 @@ --- Day 7: Camel Cards --- https://adventofcode.com/2023/day/7 """ -from aocd import data from collections import Counter +from aocd import data + tr = str.maketrans("TQKA", "IKLM") diff --git a/aoc_wim/aoc2023/q08.py b/aoc_wim/aoc2023/q08.py index 866a9c5a..6027b0b3 100644 --- a/aoc_wim/aoc2023/q08.py +++ b/aoc_wim/aoc2023/q08.py @@ -3,6 +3,7 @@ https://adventofcode.com/2023/day/8 """ from math import lcm + from aocd import data path, graph = data.split("\n\n") diff --git a/aoc_wim/aoc2023/q09.py b/aoc_wim/aoc2023/q09.py index a6981a29..d073a680 100644 --- a/aoc_wim/aoc2023/q09.py +++ b/aoc_wim/aoc2023/q09.py @@ -2,8 +2,8 @@ --- Day 9: Mirage Maintenance --- https://adventofcode.com/2023/day/9 """ -from aocd import data import numpy as np +from aocd import data n = len(data.splitlines()) diff --git a/aoc_wim/ocr.py b/aoc_wim/ocr.py index a354deb9..3fcb9068 100644 --- a/aoc_wim/ocr.py +++ b/aoc_wim/ocr.py @@ -1,7 +1,8 @@ import numpy as np from termcolor import cprint -from aoc_wim.zgrid import ZGrid + from aoc_wim.zgrid import array2txt +from aoc_wim.zgrid import ZGrid glyphs = """ diff --git a/aoc_wim/search.py b/aoc_wim/search.py index 87858553..ee3679dc 100644 --- a/aoc_wim/search.py +++ b/aoc_wim/search.py @@ -1,8 +1,8 @@ import heapq +import logging from collections import defaultdict from collections import deque from itertools import count -import logging log = logging.getLogger(__name__) diff --git a/aoc_wim/util.py b/aoc_wim/util.py index f930705a..8d5fd242 100644 --- a/aoc_wim/util.py +++ b/aoc_wim/util.py @@ -4,8 +4,8 @@ import sys import tempfile import webbrowser -from pathlib import Path from datetime import datetime +from pathlib import Path from textwrap import dedent from aocd import get_data diff --git a/aoc_wim/zgrid.py b/aoc_wim/zgrid.py index 13ee7ff0..d998622a 100644 --- a/aoc_wim/zgrid.py +++ b/aoc_wim/zgrid.py @@ -2,8 +2,9 @@ import string from collections import ChainMap from collections import deque -import numpy as np + import networkx as nx +import numpy as np log = logging.getLogger(__name__) diff --git a/pyproject.toml b/pyproject.toml index 609bde98..2c4f52c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,6 @@ dependencies = [ "termcolor", "fields", "networkx", - "wimpy", "marshmallow", "regex", "intervaltree", diff --git a/tests/2016/test_08_two_factor_authentication.py b/tests/2016/test_08_two_factor_authentication.py index 3f94920c..37d4bb55 100644 --- a/tests/2016/test_08_two_factor_authentication.py +++ b/tests/2016/test_08_two_factor_authentication.py @@ -1,6 +1,7 @@ +import numpy as np + from aoc_wim.aoc2016 import q08 from aoc_wim.zgrid import ZGrid -import numpy as np frames = """\ diff --git a/tests/2017/test_22_sporifica_virus.py b/tests/2017/test_22_sporifica_virus.py index f721beb5..ef708580 100644 --- a/tests/2017/test_22_sporifica_virus.py +++ b/tests/2017/test_22_sporifica_virus.py @@ -1,4 +1,5 @@ import pytest + from aoc_wim.aoc2017.q22 import mutate diff --git a/tests/2018/test_05_alchemical_reduction.py b/tests/2018/test_05_alchemical_reduction.py index 3677bd17..8dfa62ff 100644 --- a/tests/2018/test_05_alchemical_reduction.py +++ b/tests/2018/test_05_alchemical_reduction.py @@ -1,4 +1,5 @@ import pytest + from aoc_wim.aoc2018 import q05 diff --git a/tests/2018/test_11_chronal_charge.py b/tests/2018/test_11_chronal_charge.py index ab813815..33f2a083 100644 --- a/tests/2018/test_11_chronal_charge.py +++ b/tests/2018/test_11_chronal_charge.py @@ -1,4 +1,5 @@ import pytest + from aoc_wim.aoc2018 import q11 diff --git a/tests/2019/test_02_1202_program_alarm.py b/tests/2019/test_02_1202_program_alarm.py index dfaef7ce..88536b30 100644 --- a/tests/2019/test_02_1202_program_alarm.py +++ b/tests/2019/test_02_1202_program_alarm.py @@ -1,4 +1,5 @@ import pytest + from aoc_wim.aoc2019 import IntComputer diff --git a/tests/2019/test_05_sunny_with_a_chance_of_asteroids.py b/tests/2019/test_05_sunny_with_a_chance_of_asteroids.py index d3b0c3cb..596ff0d3 100644 --- a/tests/2019/test_05_sunny_with_a_chance_of_asteroids.py +++ b/tests/2019/test_05_sunny_with_a_chance_of_asteroids.py @@ -1,4 +1,5 @@ import random + from aoc_wim.aoc2019.q05 import compute diff --git a/tests/2019/test_10_monitoring_station.py b/tests/2019/test_10_monitoring_station.py index 2c022280..74383905 100644 --- a/tests/2019/test_10_monitoring_station.py +++ b/tests/2019/test_10_monitoring_station.py @@ -1,5 +1,7 @@ import logging + import pytest + from aoc_wim.aoc2019 import q10 diff --git a/tests/2019/test_17_set_and_forget.py b/tests/2019/test_17_set_and_forget.py index de0d6d35..4ba9074f 100644 --- a/tests/2019/test_17_set_and_forget.py +++ b/tests/2019/test_17_set_and_forget.py @@ -1,4 +1,5 @@ import pytest + from aoc_wim.aoc2019 import q17 from aoc_wim.zgrid import ZGrid diff --git a/tests/2019/test_19_tractor_beam.py b/tests/2019/test_19_tractor_beam.py index 4b4f7214..bd099f9d 100644 --- a/tests/2019/test_19_tractor_beam.py +++ b/tests/2019/test_19_tractor_beam.py @@ -1,6 +1,6 @@ -from aoc_wim.zgrid import zrange -from aoc_wim.zgrid import ZGrid from aoc_wim.aoc2019 import q19 +from aoc_wim.zgrid import ZGrid +from aoc_wim.zgrid import zrange minibeam = """\ diff --git a/tests/2020/test_22_crab_combat.py b/tests/2020/test_22_crab_combat.py index 0781b566..029158d9 100644 --- a/tests/2020/test_22_crab_combat.py +++ b/tests/2020/test_22_crab_combat.py @@ -1,6 +1,7 @@ -from aoc_wim.aoc2020 import q22 from collections import deque +from aoc_wim.aoc2020 import q22 + # Here is an example of a small game that would loop forever without the # infinite game prevention rule: diff --git a/tests/2021/test_10_syntax_scoring.py b/tests/2021/test_10_syntax_scoring.py index 8ef01280..d5f38789 100644 --- a/tests/2021/test_10_syntax_scoring.py +++ b/tests/2021/test_10_syntax_scoring.py @@ -1,6 +1,7 @@ -import pytest import re +import pytest + from aoc_wim.aoc2021 import q10 diff --git a/tests/2021/test_18_snailfish.py b/tests/2021/test_18_snailfish.py index e2ed8ab7..992f0205 100644 --- a/tests/2021/test_18_snailfish.py +++ b/tests/2021/test_18_snailfish.py @@ -1,4 +1,5 @@ import json + import pytest from aoc_wim.aoc2021.q18 import SnailfishNumber diff --git a/tests/2021/test_24_arithmetic_logic_unit.py b/tests/2021/test_24_arithmetic_logic_unit.py index 93189f04..f06a5c19 100644 --- a/tests/2021/test_24_arithmetic_logic_unit.py +++ b/tests/2021/test_24_arithmetic_logic_unit.py @@ -1,4 +1,5 @@ import pytest + from aoc_wim.aoc2021.q24 import Comp diff --git a/tests/conftest.py b/tests/conftest.py index b59a1480..0ac38019 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,8 +1,9 @@ import datetime import re -import pytest import sys +import pytest + Module = type(sys) mock_aocd = Module("aocd") mock_aocd.data = ""