Add 2021-15 part 2 in Python

Signed-off-by: AKU <tom@tdpain.net>
This commit is contained in:
akp 2021-12-19 21:39:15 +00:00
parent cc7bf39b3f
commit f4d39f96bc
No known key found for this signature in database
GPG key ID: AA5726202C8879B7
4 changed files with 23 additions and 12 deletions

View file

@ -3,13 +3,13 @@
"dir": "challenges/2021/15-chiton",
"implementations": {
"Python": {
"part.1.avg": 0.05848939180374146,
"part.1.max": 0.22109389305114746,
"part.1.min": 0.03475213050842285,
"part.2.avg": 0.00003055143356323242,
"part.2.max": 0.0002415180206298828,
"part.2.min": 0.000008344650268554688
"part.1.avg": 0.10024118185043335,
"part.1.max": 0.26880645751953125,
"part.1.min": 0.04713582992553711,
"part.2.avg": 4.993094868659973,
"part.2.max": 10.088721990585327,
"part.2.min": 2.554753065109253
}
},
"numRuns": 1000
"numRuns": 100
}

View file

@ -24,14 +24,24 @@ def get_adjacent_points(point: Point) -> List[Point]:
]
def parse(instr: str) -> Graph:
def parse(instr: str, expand: bool) -> Graph:
nodes = {}
edges = {}
for y, line in enumerate(instr.strip().splitlines()):
lines = instr.strip().splitlines()
num_lines = len(lines)
line_len = len(lines[0])
for y, line in enumerate(lines):
for x, char in enumerate(line):
number = int(char)
nodes[(x, y)] = int(char)
if expand:
for my in range(5):
for mx in range(5):
nodes[x + (mx * line_len), y + (my * num_lines)] = ((number + my + mx - 1) % 9) + 1
for node in nodes:
edges[node] = edges.get(node, []) + [
p for p in get_adjacent_points(node) if p in nodes
@ -75,9 +85,10 @@ def get_shortest_path_len(graph: Graph) -> int:
class Challenge(BaseChallenge):
@staticmethod
def one(instr: str) -> int:
g = parse(instr)
g = parse(instr, False)
return get_shortest_path_len(g)
@staticmethod
def two(instr: str) -> Any:
raise NotImplementedError
g = parse(instr, True)
return get_shortest_path_len(g)

View file

@ -26,7 +26,7 @@ Solutions to the [2021 Advent of Code](https://adventofcode.com/2021).
| 12 - Passage Pathing | ★ ★ | [Go](12-passagePathing/go) | I couldn't tell you how it works, but it does kinda work and I think I have a vague idea (external help was used). |
| 13 - Transparent Origami | ★ ★ | [Python](13-transparentOrigami/py), [Nim](13-transparentOrigami/nim) | I got stuck for hours on an intermittent off-by-one error. :( |
| 14 - Extended Polymerization | ★ ★ | [Python](14-extendedPolymerization/py) | Another off-by-one error, but this time it was because of dodgy division. Wonderful. |
| 15 - Chiton | ★ | [Python](15-chiton/py) | Pathfinding is hard |
| 15 - Chiton | ★ | [Python](15-chiton/py) | Pathfinding is hard |
| 16 - Packet Decoder | ★ ★ | [Python](16-packetDecoder/py) | Parsing and interpreting stuff is surprisingly enjoyable |
| 17 - Trick Shot | Unattempted | | |
| 18 - Snailfish | Could not solve | | |

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Before After
Before After