Skip to content

Commit cc238a7

Browse files
committed
* Formatting updates
* Add old solutions
1 parent aaff034 commit cc238a7

62 files changed

Lines changed: 2221 additions & 169 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/2021/day08/main.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from collections import defaultdict
22
from functools import reduce
3-
from typing import Set
43

54

65
def get_set_only_item(s):
@@ -53,8 +52,8 @@ def main():
5352
two_letters = len2signals[2][0]
5453
three_letters = len2signals[3][0]
5554
four_letters = len2signals[4][0]
56-
five_letters_common: Set[str] = reduce(set.intersection, len2signals[5])
57-
six_letters_common: Set[str] = reduce(set.intersection, len2signals[6])
55+
five_letters_common: set[str] = reduce(set.intersection, len2signals[5])
56+
six_letters_common: set[str] = reduce(set.intersection, len2signals[6])
5857

5958
a_mapping = three_letters - two_letters
6059
b_d_mapping = four_letters - two_letters

src/2021/day18/main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import List
2-
31
INPUT_TXT = "input.txt"
42
# INPUT_TXT = "input-small.txt"
53

@@ -77,7 +75,7 @@ def reduce(self):
7775

7876
return False
7977

80-
def leaves(self) -> List["Node"]:
78+
def leaves(self) -> list["Node"]:
8179
if self.leaf:
8280
return [self]
8381
else:

src/2021/day19/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import itertools
22
from collections import Counter
3-
from typing import List
43

54
import networkx as nx
65
import numpy as np
@@ -15,7 +14,7 @@ def __init__(self, number, location=None):
1514
self.positions: np.array = None
1615
self.location = location
1716

18-
def add_position(self, position: List[int]):
17+
def add_position(self, position: list[int]):
1918
if self.positions is None:
2019
self.positions = np.array(position)
2120
else:

src/2021/day21/main.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import dataclasses
22
import itertools
33
from collections import Counter
4-
from typing import Tuple
54

65
INPUT_TXT = "input.txt"
76
# INPUT_TXT = "input-small.txt"
@@ -21,8 +20,8 @@ def sum3rolls(self):
2120

2221
@dataclasses.dataclass(frozen=True)
2322
class State:
24-
positions: Tuple[int, int]
25-
points: Tuple[int, int] = (0, 0)
23+
positions: tuple[int, int]
24+
points: tuple[int, int] = (0, 0)
2625
next_player_index: int = 0
2726

2827
def finished(self, limit):

src/2021/day22/main.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from dataclasses import dataclass
2-
from typing import List, Tuple
32

43
from tqdm import tqdm
54

@@ -11,7 +10,7 @@
1110
@dataclass
1211
class Step:
1312
on: bool
14-
ranges: List[Tuple[int, ...]]
13+
ranges: list[tuple[int, ...]]
1514

1615
def within_range(self):
1716
for r in self.ranges:
@@ -32,7 +31,7 @@ def parse_step(line: str) -> Step:
3231
return Step(on=on, ranges=ranges)
3332

3433

35-
def parse_steps(lines: List[str]) -> List[Step]:
34+
def parse_steps(lines: list[str]) -> list[Step]:
3635
return [parse_step(line) for line in lines]
3736

3837

src/2021/day22/main2.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import itertools
22
import math
33
from dataclasses import dataclass
4-
from typing import List, Tuple
54

65
import numpy as np
76
from tqdm import tqdm
@@ -14,7 +13,7 @@
1413
@dataclass
1514
class Step:
1615
on: bool
17-
ranges: List[Tuple[int, ...]]
16+
ranges: list[tuple[int, ...]]
1817

1918

2019
def parse_step(line: str) -> Step:
@@ -28,7 +27,7 @@ def parse_step(line: str) -> Step:
2827
return Step(on=on, ranges=ranges)
2928

3029

31-
def parse_steps(lines: List[str]) -> List[Step]:
30+
def parse_steps(lines: list[str]) -> list[Step]:
3231
return [parse_step(line) for line in lines]
3332

3433

src/2021/day23/main.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from functools import lru_cache
22
from queue import PriorityQueue
3-
from typing import Dict, List, Tuple
43

54
import networkx as nx
65
from matplotlib import pyplot as plt
@@ -33,7 +32,7 @@ def main() -> None:
3332
print(f"Result part 2: {result_part2}") # expected for small input: 44169
3433

3534

36-
def parse_state(lines: List[str]) -> str:
35+
def parse_state(lines: list[str]) -> str:
3736
state = ""
3837
for i, line in enumerate(lines):
3938
state += line.replace("#", "")
@@ -81,7 +80,7 @@ def draw_graph(graph: nx.Graph, target_path: str) -> None:
8180
plt.clf()
8281

8382

84-
def dijkstra(start_state: str, graph: nx.Graph) -> Dict[str, int]:
83+
def dijkstra(start_state: str, graph: nx.Graph) -> dict[str, int]:
8584
state2cost = {start_state: 0}
8685
pq = PriorityQueue()
8786
pq.put((0, start_state))
@@ -100,7 +99,7 @@ def dijkstra(start_state: str, graph: nx.Graph) -> Dict[str, int]:
10099
return state2cost
101100

102101

103-
def get_neighbours(state: str, graph: nx.Graph) -> List[Tuple[str, int]]:
102+
def get_neighbours(state: str, graph: nx.Graph) -> list[tuple[str, int]]:
104103
result = []
105104
for index, ch in enumerate(state):
106105
if ch == ".":

src/2022/day03/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import itertools
22
from functools import reduce
3-
from typing import Any, Iterator, List, Set, Tuple
3+
from typing import Any
4+
from collections.abc import Iterator
45

56

6-
def partition(a_list: List[Any], size: int) -> Iterator[Tuple[Any]]:
7+
def partition(a_list: list[Any], size: int) -> Iterator[tuple[Any]]:
78
it = iter(a_list)
89
return iter(lambda: tuple(itertools.islice(it, size)), ())
910

@@ -16,7 +17,7 @@ def item_to_score(item: str) -> int:
1617
return score
1718

1819

19-
def item_from_singleton_set(items: Set[Any]) -> Any:
20+
def item_from_singleton_set(items: set[Any]) -> Any:
2021
assert len(items) == 1
2122
return list(items)[0]
2223

src/2022/day04/main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
from typing import Tuple
2-
31
import pandas as pd
42

53

6-
def parse_line(line: str) -> Tuple[pd.Interval]:
4+
def parse_line(line: str) -> tuple[pd.Interval]:
75
spl = line.split(",")
86
return tuple(parse_interval(i) for i in spl)
97

src/2022/day10/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def main():
4040
if v - 1 <= c % 40 <= v + 1:
4141
matrix[x, y] = 1
4242

43-
print(f"Result part 2:")
43+
print("Result part 2:")
4444
show(matrix)
4545

4646

0 commit comments

Comments
 (0)