From 3e05b238d565915140bc482ab66dd0591e348a0f Mon Sep 17 00:00:00 2001 From: pareronia <49491686+pareronia@users.noreply.github.com> Date: Tue, 1 Nov 2022 09:41:33 +0100 Subject: [PATCH 1/8] concepts module --- doc/concepts.yml | 52 ++++++++++++++++++++++++ src/main/python/aoc/concepts/__init__.py | 0 src/main/python/aoc/concepts/concepts.py | 49 ++++++++++++++++++++++ src/main/python/aoc/concepts/config.py | 44 ++++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 doc/concepts.yml create mode 100644 src/main/python/aoc/concepts/__init__.py create mode 100644 src/main/python/aoc/concepts/concepts.py create mode 100644 src/main/python/aoc/concepts/config.py diff --git a/doc/concepts.yml b/doc/concepts.yml new file mode 100644 index 00000000..74e5cb10 --- /dev/null +++ b/doc/concepts.yml @@ -0,0 +1,52 @@ +concepts: + year: + - 2017: + day: + - 1: + tags: + - circular list + - sum + - rule matching + - 2: + tags: + - minimum + - maximum + - division + - sum + - combinations + - 3: + tags: + - manhattan distance + - grid + - exotic coordinate system + - 4: + tags: + - string + - rule matching + - 10: + tags: + - knot hash + - ascii + - hexadecimal + - xor + - 14: + tags: + - knot hash + - ascii + - hexadecimal + - binary + - xor + - grid + - group finding + - bfs + - 21: + tags: + - grid + - dihedral group of the square + - 2020: + day: + - 20: + tags: + - grid + - dihedral group of the square + - sea monsters diff --git a/src/main/python/aoc/concepts/__init__.py b/src/main/python/aoc/concepts/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/main/python/aoc/concepts/concepts.py b/src/main/python/aoc/concepts/concepts.py new file mode 100644 index 00000000..513c35e7 --- /dev/null +++ b/src/main/python/aoc/concepts/concepts.py @@ -0,0 +1,49 @@ +#! /usr/bin/env python3 + +import sys +import logging +from collections import defaultdict +from collections.abc import Generator +from prettyprinter import cpprint +from typing import IO + +if __name__ == "__main__": + from config import concepts, Day +else: + from aoc.concepts.config import concepts, Day + + +log = logging.getLogger(__name__) + + +def _get_tags() -> dict[str, Day]: + tags = defaultdict(list) + [tags[tag].append(day) for day in _get_days() for tag in day.tags] + return tags + + +def _get_days() -> Generator[Day]: + return concepts.get_days() + + +def _print_days(days: Generator[Day], f: IO[str]) -> None: + print("| Day | Concepts |", file=f) + print("| --- | --- |", file=f) + for day in sorted(days): + t = ", ".join(sorted(day.tags)) + print(f"| {day.year}_{day.day:02} | {t} |", file=f) + + +def _print_tags(tags: dict[str, Day], f: IO[str]) -> None: + print("| Concept | Days |", file=f) + print("| --- | --- |", file=f) + for tag, days in sorted(tags.items()): + d = ", ".join(f"{day.year}_{day.day:02}" for day in sorted(days)) + print(f"| {tag} | {d} |", file=f) + + +if __name__ == "__main__": + cpprint([_ for _ in _get_days()]) + cpprint(_get_tags()) + _print_days(_get_days(), sys.stdout) + _print_tags(_get_tags(), sys.stdout) diff --git a/src/main/python/aoc/concepts/config.py b/src/main/python/aoc/concepts/config.py new file mode 100644 index 00000000..20107363 --- /dev/null +++ b/src/main/python/aoc/concepts/config.py @@ -0,0 +1,44 @@ +#! /usr/bin/env python3 + +import os +import yaml +import logging +from collections.abc import Generator +from typing import NamedTuple +from prettyprinter import cpprint + +log = logging.getLogger(__name__) + + +class Day(NamedTuple): + year: int + day: int + tags: list[str] + + def __lt__(self, other): + if self.year == other.year: + return self.day < other.day + return self.year < other.year + + +class Concepts: + def get_days(self) -> Generator[Day]: + for year in self.concepts["year"]: + for y_num, y_dict in year.items(): + for day in y_dict["day"]: + for d_num, d_dict in day.items(): + yield Day(y_num, d_num, d_dict["tags"]) + + +with open(os.path.join(".", "doc", "concepts.yml"), "r") as f: + concepts_yaml = f.read() +concepts = yaml.load( # nosec + "!!python/object:" + __name__ + ".Concepts\n" + concepts_yaml, + Loader=yaml.Loader, +) +log.debug(concepts.__dict__) + + +if __name__ == "__main__": + print(concepts.__dict__) + cpprint([_ for _ in concepts.get_days()]) From 3ba9799c3a3f76c90e0784fd606738a04a76b32a Mon Sep 17 00:00:00 2001 From: pareronia <49491686+pareronia@users.noreply.github.com> Date: Thu, 10 Nov 2022 19:33:10 +0100 Subject: [PATCH 2/8] concepts module --- doc/concepts.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/concepts.yml b/doc/concepts.yml index 74e5cb10..56e72bb2 100644 --- a/doc/concepts.yml +++ b/doc/concepts.yml @@ -50,3 +50,11 @@ concepts: - grid - dihedral group of the square - sea monsters + - 2021: + day: + - 15: + tags: + - grid + - int grid + - path finding + - A* From af53c0e61b13c167f2326ca095ee9993bc396510 Mon Sep 17 00:00:00 2001 From: pareronia <49491686+pareronia@users.noreply.github.com> Date: Sun, 13 Nov 2022 13:25:43 +0100 Subject: [PATCH 3/8] concepts module --- doc/concepts.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/concepts.yml b/doc/concepts.yml index 56e72bb2..129751de 100644 --- a/doc/concepts.yml +++ b/doc/concepts.yml @@ -1,5 +1,12 @@ concepts: year: + - 2016: + day: + - 13: + tags: + - path finding + - A* + - binary - 2017: day: - 1: From 3fa709767f4d7699d8e31387b38c7b6285ec24cf Mon Sep 17 00:00:00 2001 From: pareronia <49491686+pareronia@users.noreply.github.com> Date: Fri, 2 Dec 2022 23:16:12 +0100 Subject: [PATCH 4/8] concepts module --- doc/concepts.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/concepts.yml b/doc/concepts.yml index 129751de..3411c0db 100644 --- a/doc/concepts.yml +++ b/doc/concepts.yml @@ -65,3 +65,11 @@ concepts: - int grid - path finding - A* + - 2022: + day: + - 1: + tags: + - sum + - 2: + tags: + - simulation From bdc1f0f4a575a04f133e9e2e1935ec690acb9b46 Mon Sep 17 00:00:00 2001 From: pareronia <49491686+pareronia@users.noreply.github.com> Date: Sat, 3 Dec 2022 16:58:10 +0100 Subject: [PATCH 5/8] concepts module --- doc/concepts.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/concepts.yml b/doc/concepts.yml index 3411c0db..fd2d90f0 100644 --- a/doc/concepts.yml +++ b/doc/concepts.yml @@ -73,3 +73,7 @@ concepts: - 2: tags: - simulation + - 3: + tags: + - set operations + - ascii From a9e608a24e5bd4e824d518dbd31910b1f4b7a5b1 Mon Sep 17 00:00:00 2001 From: pareronia <49491686+pareronia@users.noreply.github.com> Date: Sun, 1 Dec 2024 21:20:45 +0100 Subject: [PATCH 6/8] concepts module --- doc/concepts.md | 51 +++++++++++++++++++++++ doc/concepts.yml | 7 ++++ src/main/python/aoc/concepts/__main__.py | 6 +++ src/main/python/aoc/concepts/concepts.py | 52 +++++++++++++++++++----- 4 files changed, 106 insertions(+), 10 deletions(-) create mode 100644 doc/concepts.md create mode 100644 src/main/python/aoc/concepts/__main__.py diff --git a/doc/concepts.md b/doc/concepts.md new file mode 100644 index 00000000..e39cfdc3 --- /dev/null +++ b/doc/concepts.md @@ -0,0 +1,51 @@ + +| Day | Concepts | +| --- | --- | +| 2016_13 | A*, binary, path finding | +| 2017_01 | circular list, rule matching, sum | +| 2017_02 | combinations, division, maximum, minimum, sum | +| 2017_03 | exotic coordinate system, grid, manhattan distance | +| 2017_04 | rule matching, string | +| 2017_10 | ascii, hexadecimal, knot hash, xor | +| 2017_14 | ascii, bfs, binary, grid, group finding, hexadecimal, knot hash, xor | +| 2017_21 | dihedral group of the square, grid | +| 2020_20 | dihedral group of the square, grid, sea monsters | +| 2021_15 | A*, grid, int grid, path finding | +| 2022_01 | sum | +| 2022_02 | simulation | +| 2022_03 | ascii, set operations | +| 2024_01 | counter, difference, transpose | + + + +| Concept | Days | +| --- | --- | +| A* | 2016_13, 2021_15 | +| ascii | 2017_10, 2017_14, 2022_03 | +| bfs | 2017_14 | +| binary | 2016_13, 2017_14 | +| circular list | 2017_01 | +| combinations | 2017_02 | +| counter | 2024_01 | +| difference | 2024_01 | +| dihedral group of the square | 2017_21, 2020_20 | +| division | 2017_02 | +| exotic coordinate system | 2017_03 | +| grid | 2017_03, 2017_14, 2017_21, 2020_20, 2021_15 | +| group finding | 2017_14 | +| hexadecimal | 2017_10, 2017_14 | +| int grid | 2021_15 | +| knot hash | 2017_10, 2017_14 | +| manhattan distance | 2017_03 | +| maximum | 2017_02 | +| minimum | 2017_02 | +| path finding | 2016_13, 2021_15 | +| rule matching | 2017_01, 2017_04 | +| sea monsters | 2020_20 | +| set operations | 2022_03 | +| simulation | 2022_02 | +| string | 2017_04 | +| sum | 2017_01, 2017_02, 2022_01 | +| transpose | 2024_01 | +| xor | 2017_10, 2017_14 | + diff --git a/doc/concepts.yml b/doc/concepts.yml index fd2d90f0..24bffce2 100644 --- a/doc/concepts.yml +++ b/doc/concepts.yml @@ -77,3 +77,10 @@ concepts: tags: - set operations - ascii + - 2024: + day: + - 1: + tags: + - difference + - transpose + - counter diff --git a/src/main/python/aoc/concepts/__main__.py b/src/main/python/aoc/concepts/__main__.py new file mode 100644 index 00000000..5ac9d196 --- /dev/null +++ b/src/main/python/aoc/concepts/__main__.py @@ -0,0 +1,6 @@ +#! /usr/bin/env python3 + +import sys +from .concepts import main + +main(sys.argv[1]) diff --git a/src/main/python/aoc/concepts/concepts.py b/src/main/python/aoc/concepts/concepts.py index 513c35e7..5c007c2e 100644 --- a/src/main/python/aoc/concepts/concepts.py +++ b/src/main/python/aoc/concepts/concepts.py @@ -1,16 +1,19 @@ #! /usr/bin/env python3 -import sys import logging +import sys from collections import defaultdict -from collections.abc import Generator -from prettyprinter import cpprint from typing import IO +from typing import Iterator + +from prettyprinter import cpprint if __name__ == "__main__": - from config import concepts, Day + from config import Day # type:ignore + from config import concepts else: - from aoc.concepts.config import concepts, Day + from aoc.concepts.config import Day + from aoc.concepts.config import concepts log = logging.getLogger(__name__) @@ -18,15 +21,18 @@ def _get_tags() -> dict[str, Day]: tags = defaultdict(list) - [tags[tag].append(day) for day in _get_days() for tag in day.tags] + for day in _get_days(): + for tag in day.tags: + tags[tag].append(day) return tags -def _get_days() -> Generator[Day]: - return concepts.get_days() +def _get_days() -> Iterator[Day]: + for _ in concepts.get_days(): + yield _ -def _print_days(days: Generator[Day], f: IO[str]) -> None: +def _print_days(days: Iterator[Day], f: IO[str]) -> None: print("| Day | Concepts |", file=f) print("| --- | --- |", file=f) for day in sorted(days): @@ -42,8 +48,34 @@ def _print_tags(tags: dict[str, Day], f: IO[str]) -> None: print(f"| {tag} | {d} |", file=f) +def main(file_name: str) -> None: + log.debug(f"file: {file_name}") + with open(file_name, "r", encoding="utf-8") as f: + tmp = f.read() + with open(file_name, "w", encoding="utf-8") as f: + in_days_table, in_tags_table = False, False + for line in tmp.splitlines(): + if line.startswith(" @@ -24,26 +29,32 @@ | ascii | 2017_10, 2017_14, 2022_03 | | bfs | 2017_14 | | binary | 2016_13, 2017_14 | +| char grid search | 2024_04 | | circular list | 2017_01 | | combinations | 2017_02 | | counter | 2024_01 | +| custom sort | 2024_05 | | difference | 2024_01 | | dihedral group of the square | 2017_21, 2020_20 | | division | 2017_02 | | exotic coordinate system | 2017_03 | -| grid | 2017_03, 2017_14, 2017_21, 2020_20, 2021_15 | +| grid | 2017_03, 2017_14, 2017_21, 2020_20, 2021_15, 2024_04, 2024_06 | +| grid navigation | 2024_06 | | group finding | 2017_14 | | hexadecimal | 2017_10, 2017_14 | +| increasing/decreasing | 2024_02 | | int grid | 2021_15 | | knot hash | 2017_10, 2017_14 | | manhattan distance | 2017_03 | | maximum | 2017_02 | | minimum | 2017_02 | | path finding | 2016_13, 2021_15 | +| regex | 2024_03 | | rule matching | 2017_01, 2017_04 | | sea monsters | 2020_20 | | set operations | 2022_03 | | simulation | 2022_02 | +| sort | 2024_05 | | string | 2017_04 | | sum | 2017_01, 2017_02, 2022_01 | | transpose | 2024_01 | diff --git a/doc/concepts.yml b/doc/concepts.yml index 24bffce2..418a4016 100644 --- a/doc/concepts.yml +++ b/doc/concepts.yml @@ -84,3 +84,21 @@ concepts: - difference - transpose - counter + - 2: + tags: + - increasing/decreasing + - 3: + tags: + - regex + - 4: + tags: + - grid + - char grid search + - 5: + tags: + - sort + - custom sort + - 6: + tags: + - grid + - grid navigation From f20ecd0d257a169885948b84c31e38a976c35314 Mon Sep 17 00:00:00 2001 From: pareronia <49491686+pareronia@users.noreply.github.com> Date: Fri, 3 Jan 2025 17:29:43 +0100 Subject: [PATCH 8/8] concepts module --- doc/concepts.md | 50 ++++++-- doc/concepts.yml | 290 ++++++++++++++++++++++++++++++----------------- 2 files changed, 231 insertions(+), 109 deletions(-) diff --git a/doc/concepts.md b/doc/concepts.md index 29985149..943a9ca2 100644 --- a/doc/concepts.md +++ b/doc/concepts.md @@ -9,7 +9,7 @@ | 2017_10 | ascii, hexadecimal, knot hash, xor | | 2017_14 | ascii, bfs, binary, grid, group finding, hexadecimal, knot hash, xor | | 2017_21 | dihedral group of the square, grid | -| 2020_20 | dihedral group of the square, grid, sea monsters | +| 2020_20 | dihedral group of the square, grid, pattern recognition, sea monsters | | 2021_15 | A*, grid, int grid, path finding | | 2022_01 | sum | | 2022_02 | simulation | @@ -20,6 +20,25 @@ | 2024_04 | char grid search, grid | | 2024_05 | custom sort, sort | | 2024_06 | grid, grid navigation | +| 2024_07 | recursion | +| 2024_08 | combinations, geometry, grid | +| 2024_09 | large list | +| 2024_10 | grid, int grid, path finding | +| 2024_11 | memoization, recursion | +| 2024_12 | char grid, geometry, grid, polygons | +| 2024_13 | geometry, linear equations | +| 2024_14 | christmas tree, geometry, loop detection, pattern recognition | +| 2024_15 | char grid, grid | +| 2024_16 | char grid, grid, path finding | +| 2024_17 | bit shifting, reverse engineering, virtual machine | +| 2024_18 | binary search, char grid, grid, path finding | +| 2024_19 | memoization, recursion | +| 2024_20 | char grid, grid, manhattan distance, path finding | +| 2024_21 | memoization, recursion | +| 2024_22 | large list | +| 2024_23 | graph, graph cliques | +| 2024_24 | binary logic, simulation | +| 2024_25 | char grid, grid | @@ -29,34 +48,51 @@ | ascii | 2017_10, 2017_14, 2022_03 | | bfs | 2017_14 | | binary | 2016_13, 2017_14 | +| binary logic | 2024_24 | +| binary search | 2024_18 | +| bit shifting | 2024_17 | +| char grid | 2024_12, 2024_15, 2024_16, 2024_18, 2024_20, 2024_25 | | char grid search | 2024_04 | +| christmas tree | 2024_14 | | circular list | 2017_01 | -| combinations | 2017_02 | +| combinations | 2017_02, 2024_08 | | counter | 2024_01 | | custom sort | 2024_05 | | difference | 2024_01 | | dihedral group of the square | 2017_21, 2020_20 | | division | 2017_02 | | exotic coordinate system | 2017_03 | -| grid | 2017_03, 2017_14, 2017_21, 2020_20, 2021_15, 2024_04, 2024_06 | +| geometry | 2024_08, 2024_12, 2024_13, 2024_14 | +| graph | 2024_23 | +| graph cliques | 2024_23 | +| grid | 2017_03, 2017_14, 2017_21, 2020_20, 2021_15, 2024_04, 2024_06, 2024_08, 2024_10, 2024_12, 2024_15, 2024_16, 2024_18, 2024_20, 2024_25 | | grid navigation | 2024_06 | | group finding | 2017_14 | | hexadecimal | 2017_10, 2017_14 | | increasing/decreasing | 2024_02 | -| int grid | 2021_15 | +| int grid | 2021_15, 2024_10 | | knot hash | 2017_10, 2017_14 | -| manhattan distance | 2017_03 | +| large list | 2024_09, 2024_22 | +| linear equations | 2024_13 | +| loop detection | 2024_14 | +| manhattan distance | 2017_03, 2024_20 | | maximum | 2017_02 | +| memoization | 2024_11, 2024_19, 2024_21 | | minimum | 2017_02 | -| path finding | 2016_13, 2021_15 | +| path finding | 2016_13, 2021_15, 2024_10, 2024_16, 2024_18, 2024_20 | +| pattern recognition | 2020_20, 2024_14 | +| polygons | 2024_12 | +| recursion | 2024_07, 2024_11, 2024_19, 2024_21 | | regex | 2024_03 | +| reverse engineering | 2024_17 | | rule matching | 2017_01, 2017_04 | | sea monsters | 2020_20 | | set operations | 2022_03 | -| simulation | 2022_02 | +| simulation | 2022_02, 2024_24 | | sort | 2024_05 | | string | 2017_04 | | sum | 2017_01, 2017_02, 2022_01 | | transpose | 2024_01 | +| virtual machine | 2024_17 | | xor | 2017_10, 2017_14 | diff --git a/doc/concepts.yml b/doc/concepts.yml index 418a4016..aa44e0e5 100644 --- a/doc/concepts.yml +++ b/doc/concepts.yml @@ -1,104 +1,190 @@ concepts: year: - - 2016: - day: - - 13: - tags: - - path finding - - A* - - binary - - 2017: - day: - - 1: - tags: - - circular list - - sum - - rule matching - - 2: - tags: - - minimum - - maximum - - division - - sum - - combinations - - 3: - tags: - - manhattan distance - - grid - - exotic coordinate system - - 4: - tags: - - string - - rule matching - - 10: - tags: - - knot hash - - ascii - - hexadecimal - - xor - - 14: - tags: - - knot hash - - ascii - - hexadecimal - - binary - - xor - - grid - - group finding - - bfs - - 21: - tags: - - grid - - dihedral group of the square - - 2020: - day: - - 20: - tags: - - grid - - dihedral group of the square - - sea monsters - - 2021: - day: - - 15: - tags: - - grid - - int grid - - path finding - - A* - - 2022: - day: - - 1: - tags: - - sum - - 2: - tags: - - simulation - - 3: - tags: - - set operations - - ascii - - 2024: - day: - - 1: - tags: - - difference - - transpose - - counter - - 2: - tags: - - increasing/decreasing - - 3: - tags: - - regex - - 4: - tags: - - grid - - char grid search - - 5: - tags: - - sort - - custom sort - - 6: - tags: - - grid - - grid navigation + - 2016: + day: + - 13: + tags: + - path finding + - A* + - binary + - 2017: + day: + - 1: + tags: + - circular list + - sum + - rule matching + - 2: + tags: + - minimum + - maximum + - division + - sum + - combinations + - 3: + tags: + - manhattan distance + - grid + - exotic coordinate system + - 4: + tags: + - string + - rule matching + - 10: + tags: + - knot hash + - ascii + - hexadecimal + - xor + - 14: + tags: + - knot hash + - ascii + - hexadecimal + - binary + - xor + - grid + - group finding + - bfs + - 21: + tags: + - grid + - dihedral group of the square + - 2020: + day: + - 20: + tags: + - grid + - dihedral group of the square + - sea monsters + - pattern recognition + - 2021: + day: + - 15: + tags: + - grid + - int grid + - path finding + - A* + - 2022: + day: + - 1: + tags: + - sum + - 2: + tags: + - simulation + - 3: + tags: + - set operations + - ascii + - 2024: + day: + - 1: + tags: + - difference + - transpose + - counter + - 2: + tags: + - increasing/decreasing + - 3: + tags: + - regex + - 4: + tags: + - grid + - char grid search + - 5: + tags: + - sort + - custom sort + - 6: + tags: + - grid + - grid navigation + - 7: + tags: + - recursion + - 8: + tags: + - grid + - geometry + - combinations + - 9: + tags: + - large list + - 10: + tags: + - grid + - int grid + - path finding + - 11: + tags: + - recursion + - memoization + - 12: + tags: + - grid + - char grid + - geometry + - polygons + - 13: + tags: + - geometry + - linear equations + - 14: + tags: + - geometry + - pattern recognition + - loop detection + - christmas tree + - 15: + tags: + - grid + - char grid + - 16: + tags: + - grid + - char grid + - path finding + - 17: + tags: + - virtual machine + - bit shifting + - reverse engineering + - 18: + tags: + - grid + - char grid + - path finding + - binary search + - 19: + tags: + - recursion + - memoization + - 20: + tags: + - grid + - char grid + - path finding + - manhattan distance + - 21: + tags: + - recursion + - memoization + - 22: + tags: + - large list + - 23: + tags: + - graph + - graph cliques + - 24: + tags: + - simulation + - binary logic + - 25: + tags: + - grid + - char grid