From ced2be5f0bff226a92d4857192a2ab9047155026 Mon Sep 17 00:00:00 2001 From: Antoine Date: Tue, 19 Dec 2023 15:33:17 +0100 Subject: [PATCH] Sort imports --- 2023/01/first.py | 1 + 2023/02/second.py | 4 +++- 2023/03/first.py | 2 +- 2023/03/second.py | 3 ++- 2023/04/first.py | 1 + 2023/04/second.py | 5 ++++- 2023/05/first.py | 4 +++- 2023/05/second.py | 5 +++-- 2023/05/utils.py | 1 + 2023/06/first.py | 1 + 2023/06/second.py | 3 ++- 2023/07/first.py | 4 +++- 2023/07/second.py | 6 ++++-- 2023/08/first.py | 1 + 2023/08/second.py | 1 + 2023/09/first.py | 2 ++ 2023/09/second.py | 4 +++- 2023/10/first.py | 1 + 2023/10/second.py | 2 +- 2023/11/second.py | 1 + 2023/13/first.py | 3 ++- 2023/13/second.py | 6 ++++-- 2023/14/first.py | 4 +++- 2023/14/second.py | 4 +++- 2023/15/first.py | 1 + 2023/15/second.py | 4 +++- 2023/16/first.py | 4 +++- 2023/16/second.py | 3 ++- 2023/17/first.py | 5 +++-- 2023/17/second.py | 5 +++-- 2023/18/first.py | 3 ++- 2023/18/second.py | 3 ++- 32 files changed, 70 insertions(+), 27 deletions(-) diff --git a/2023/01/first.py b/2023/01/first.py index 5c5ce78..7a3219e 100644 --- a/2023/01/first.py +++ b/2023/01/first.py @@ -1,5 +1,6 @@ from utils import lines + def extractValue(line): digits = list(filter(str.isdigit, line)) return int(digits[0] + digits[-1]) diff --git a/2023/02/second.py b/2023/02/second.py index cb4fca5..1fbbb46 100644 --- a/2023/02/second.py +++ b/2023/02/second.py @@ -1,7 +1,9 @@ -from utils import lines from collections import defaultdict from math import prod +from utils import lines + + def power(line): game, draws = line.split(': ') maximum = defaultdict(int) diff --git a/2023/03/first.py b/2023/03/first.py index d7ef5a5..c243903 100644 --- a/2023/03/first.py +++ b/2023/03/first.py @@ -1,4 +1,4 @@ -from utils import lines, Point +from utils import Point, lines board = list(lines()) diff --git a/2023/03/second.py b/2023/03/second.py index c4badd6..74f9245 100644 --- a/2023/03/second.py +++ b/2023/03/second.py @@ -1,7 +1,8 @@ -from utils import lines, Point from collections import defaultdict from math import prod +from utils import Point, lines + board = list(lines()) gears = defaultdict(list) adjacent = dict() diff --git a/2023/04/first.py b/2023/04/first.py index 9ea5bea..8706449 100644 --- a/2023/04/first.py +++ b/2023/04/first.py @@ -18,6 +18,7 @@ def score(line: str) -> int: from unittest import TestCase + class TestDay4_1(TestCase): def test_parsing(self): diff --git a/2023/04/second.py b/2023/04/second.py index c201101..3d3f3e2 100644 --- a/2023/04/second.py +++ b/2023/04/second.py @@ -1,6 +1,8 @@ -from utils import lines from collections import defaultdict +from utils import lines + + def toIntegerSet(string: str) -> set[int]: "Converts ' 1 21 53 59 44 ' to {1, 21, 53, 59, 44}" return set(int(x) for x in string.split(' ') if x) @@ -25,6 +27,7 @@ def countPerCard(lines) -> dict[int, int]: from unittest import TestCase + class TestDay4_2(TestCase): def test_parsing(self): diff --git a/2023/05/first.py b/2023/05/first.py index e8953ad..08795bf 100644 --- a/2023/05/first.py +++ b/2023/05/first.py @@ -1,6 +1,8 @@ -from utils import lines, debug from collections import defaultdict +from utils import debug, lines + + def parser(lines): "From an iterable of strings, iterate over the maps described" source = None diff --git a/2023/05/second.py b/2023/05/second.py index 9d1969b..f1866b5 100644 --- a/2023/05/second.py +++ b/2023/05/second.py @@ -1,8 +1,9 @@ -from utils import lines, debug from collections import defaultdict -from more_itertools import grouper from first import parser +from more_itertools import grouper +from utils import debug, lines + class Range: def __init__(self, start, one_past_end): diff --git a/2023/05/utils.py b/2023/05/utils.py index 1292156..d15fe1d 100644 --- a/2023/05/utils.py +++ b/2023/05/utils.py @@ -1,5 +1,6 @@ import sys + def lines(): while True: try: diff --git a/2023/06/first.py b/2023/06/first.py index 6c606c2..26eaaab 100644 --- a/2023/06/first.py +++ b/2023/06/first.py @@ -25,6 +25,7 @@ def part1(time_limits: list[int], records: list[int]) -> int: from unittest import TestCase + class TestDay6_1(TestCase): def test_parse(self): diff --git a/2023/06/second.py b/2023/06/second.py index ca47567..6956450 100644 --- a/2023/06/second.py +++ b/2023/06/second.py @@ -1,4 +1,4 @@ -from first import simulate, number_of_ways_to_win +from first import number_of_ways_to_win, simulate def parse(line: str) -> list[str]: @@ -13,6 +13,7 @@ def parse(line: str) -> list[str]: from unittest import TestCase + class TestDay6_2(TestCase): def test_parse(self): diff --git a/2023/07/first.py b/2023/07/first.py index 90dc432..8ce114d 100644 --- a/2023/07/first.py +++ b/2023/07/first.py @@ -1,6 +1,7 @@ -from utils import lines from collections import Counter, namedtuple +from utils import lines + Hand = namedtuple('Hand', ['type', 'card_values', 'bid']) class CamelCards: @@ -34,6 +35,7 @@ def total_winnings(cls, lines) -> int: from unittest import TestCase + class TestDay7_1(TestCase): def test_hand_type(self): diff --git a/2023/07/second.py b/2023/07/second.py index f929c17..df9468d 100644 --- a/2023/07/second.py +++ b/2023/07/second.py @@ -1,7 +1,8 @@ -from utils import lines from collections import Counter -from first import Hand, CamelCards +from first import CamelCards, Hand +from utils import lines + class CamelCardsVariant(CamelCards): CARDS = "J23456789TQKA" @@ -26,6 +27,7 @@ def hand_type(cls, hand: str) -> tuple: from unittest import TestCase + class TestDay7_2(TestCase): def test_hand_type(self): diff --git a/2023/08/first.py b/2023/08/first.py index 4b26ab7..5bbc075 100644 --- a/2023/08/first.py +++ b/2023/08/first.py @@ -34,6 +34,7 @@ def navigate(network: dict, instructions: str, start: str = 'AAA') -> int: from unittest import TestCase + class TestDay8_1(TestCase): sample = { 'AAA = (BBB, BBB)': ('AAA', 'BBB', 'BBB'), diff --git a/2023/08/second.py b/2023/08/second.py index f0fc465..8e40a37 100644 --- a/2023/08/second.py +++ b/2023/08/second.py @@ -22,6 +22,7 @@ def ghost_solve(network: map, instructions: str) -> int: from unittest import TestCase + class TestDay8_2(TestCase): def test_solve(self): sample = { diff --git a/2023/09/first.py b/2023/09/first.py index 55f1eb9..dfb9433 100644 --- a/2023/09/first.py +++ b/2023/09/first.py @@ -1,5 +1,6 @@ from utils import lines + def parse(line: str) -> list[int]: return list(map(int, line.split())) @@ -19,6 +20,7 @@ def part1(lines) -> int: from unittest import TestCase + class TestDay9_1(TestCase): sample = { diff --git a/2023/09/second.py b/2023/09/second.py index 2a94894..ad4f0f9 100644 --- a/2023/09/second.py +++ b/2023/09/second.py @@ -1,5 +1,6 @@ -from utils import lines from first import parse +from utils import lines + def extrapolate(sequence: list[int]) -> int: diff = [b - a for a, b in zip(sequence, sequence[1:])] @@ -17,6 +18,7 @@ def part2(lines) -> int: from unittest import TestCase + class TestDay9_2(TestCase): sample = { diff --git a/2023/10/first.py b/2023/10/first.py index 6a002d1..708fb24 100644 --- a/2023/10/first.py +++ b/2023/10/first.py @@ -77,6 +77,7 @@ def visualize(lines): from unittest import TestCase + class TestDay10_1(TestCase): samples = [ diff --git a/2023/10/second.py b/2023/10/second.py index 1464ed6..d4fd66c 100644 --- a/2023/10/second.py +++ b/2023/10/second.py @@ -1,7 +1,6 @@ from first import DISPLAY, TILES, find_loop, parse from utils import Point, lines - # Constants INFER_TILE = {tuple(sorted(pair)): c for c, pair in TILES.items()} @@ -47,6 +46,7 @@ def part2(lines, visualize = False): from unittest import TestCase + class TestDay10_2(TestCase): samples = [ diff --git a/2023/11/second.py b/2023/11/second.py index 688c5d0..547086b 100644 --- a/2023/11/second.py +++ b/2023/11/second.py @@ -17,6 +17,7 @@ def part2(lines: list[str], factor: int = 1000000) -> int: from first import sample + class TestDay11_2(TestCase): def test_part1(self): diff --git a/2023/13/first.py b/2023/13/first.py index 712bd98..5134889 100644 --- a/2023/13/first.py +++ b/2023/13/first.py @@ -1,4 +1,5 @@ -from utils import lines, split, Point +from utils import Point, lines, split + class Part1: diff --git a/2023/13/second.py b/2023/13/second.py index eb2aef3..4cf70c5 100644 --- a/2023/13/second.py +++ b/2023/13/second.py @@ -1,6 +1,6 @@ -from utils import lines, split, Point - from first import Part1 +from utils import Point, lines, split + class Part2(Part1): @@ -21,8 +21,10 @@ def find_reflection(zone: list[str], flipped: list[tuple[str]]): # ------------------------------ from unittest import TestCase + from first import sample + class TestDay13_1(TestCase): expected_reflections = [(0, 3), (0, 1)] diff --git a/2023/14/first.py b/2023/14/first.py index 507f677..345c34d 100644 --- a/2023/14/first.py +++ b/2023/14/first.py @@ -1,6 +1,8 @@ -from utils import lines, Point from collections import Counter, defaultdict +from utils import Point, lines + + def part1(lines): previous = defaultdict(int) result = [] diff --git a/2023/14/second.py b/2023/14/second.py index 46647a8..dd89921 100644 --- a/2023/14/second.py +++ b/2023/14/second.py @@ -1,8 +1,10 @@ -from utils import lines, Point from collections import Counter from enum import IntEnum, auto from functools import cache +from utils import Point, lines + + @cache def tilt_left(row: str) -> str: previous = 0 diff --git a/2023/15/first.py b/2023/15/first.py index e414972..fea22bf 100644 --- a/2023/15/first.py +++ b/2023/15/first.py @@ -1,5 +1,6 @@ from functools import cache + @cache def santa_hash(string: str) -> int: result = 0 diff --git a/2023/15/second.py b/2023/15/second.py index f7d2918..b3df11e 100644 --- a/2023/15/second.py +++ b/2023/15/second.py @@ -1,5 +1,6 @@ +from collections import OrderedDict, defaultdict + from first import santa_hash -from collections import defaultdict, OrderedDict def execute(instructions: list[str]): @@ -25,6 +26,7 @@ def execute(instructions: list[str]): from first import sample + class TestDay15_1(TestCase): def test_execute(self): diff --git a/2023/16/first.py b/2023/16/first.py index 05f358f..1238c57 100644 --- a/2023/16/first.py +++ b/2023/16/first.py @@ -1,6 +1,8 @@ -from utils import lines, Point from collections import defaultdict +from utils import Point, lines + + def count_energy(board: list[str], start: Point, direction: (int, int)) -> int: seen = defaultdict(set) diff --git a/2023/16/second.py b/2023/16/second.py index c61f873..aa7cd3a 100644 --- a/2023/16/second.py +++ b/2023/16/second.py @@ -1,7 +1,8 @@ -from utils import lines, Point from collections import defaultdict from first import count_energy +from utils import Point, lines + def part2(lines: list[str]) -> int: results = [] diff --git a/2023/17/first.py b/2023/17/first.py index 48c9f80..46fe2e2 100644 --- a/2023/17/first.py +++ b/2023/17/first.py @@ -1,6 +1,7 @@ -from utils import lines, Point from collections import Counter, defaultdict, deque, namedtuple -from heapq import heappush, heappop +from heapq import heappop, heappush + +from utils import Point, lines # 976 # 964 diff --git a/2023/17/second.py b/2023/17/second.py index 52ea878..7cec543 100644 --- a/2023/17/second.py +++ b/2023/17/second.py @@ -1,6 +1,7 @@ -from utils import lines, Point from collections import Counter, defaultdict, deque, namedtuple -from heapq import heappush, heappop +from heapq import heappop, heappush + +from utils import Point, lines # 976 # 964 diff --git a/2023/18/first.py b/2023/18/first.py index cce99be..bccbf7f 100644 --- a/2023/18/first.py +++ b/2023/18/first.py @@ -1,6 +1,7 @@ -from utils import lines, Point from collections import deque +from utils import Point, lines + MOVE = { 'R': (1, 0), 'L': (-1, 0), diff --git a/2023/18/second.py b/2023/18/second.py index 11c7785..bc10fde 100644 --- a/2023/18/second.py +++ b/2023/18/second.py @@ -1,6 +1,7 @@ -from utils import lines, Point from collections import deque +from utils import Point, lines + MOVE = { 'R': Point(1, 0), 'L': Point(-1, 0),