Day 20's half hearted attempt

This commit is contained in:
akp 2020-12-20 15:38:19 +00:00
parent a862902083
commit 5ae9201115
No known key found for this signature in database
GPG key ID: D3E7EAA31B39637E
7 changed files with 163 additions and 1 deletions

2
.github/README.md vendored
View file

@ -35,7 +35,7 @@ Puzzle inputs and descriptions are not included in this repository. You'll have
| [17](/17-conwayCubes) | ![Partially complete][partial] | [Link](/17-conwayCubes/python) | |
| [18](/18-operationOrder) | ![Partially complete][partial] | [Link](/18-operationOrder/python) | |
| [19](/19-monsterMessages) | ![Completed][check] | [Link](/19-monsterMessages/python) | [Link](/19-monsterMessages/go) |
| 20 | ![Not yet attempted][pending] | | |
| [20](/20-jurassicJigsaw) | ![Incomplete][cross] | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |

View file

@ -0,0 +1,3 @@
# [Day 20: Jurassic Jigsaw](https://adventofcode.com/2020/day/20)
Gave up on this one. I was struggling to find a decent logical way to do it manually, yet alone write a set of rules to get a computer to do it.

View file

@ -0,0 +1,14 @@
{
"year": "2020",
"day": "20",
"title": "Jurassic Jigsaw",
"testCases": {
"one": [
{
"input": "Tile 2311:\n..##.#..#.\n##..#.....\n#...##..#.\n####.#...#\n##.##.###.\n##...#.###\n.#.#.#..##\n..#....#..\n###...#.#.\n..###..###\n\nTile 1951:\n#.##...##.\n#.####...#\n.....#..##\n#...######\n.##.#....#\n.###.#####\n###.##.##.\n.###....#.\n..#.#..#.#\n#...##.#..\n\nTile 1171:\n####...##.\n#..##.#..#\n##.#..#.#.\n.###.####.\n..###.####\n.##....##.\n.#...####.\n#.##.####.\n####..#...\n.....##...\n\nTile 1427:\n###.##.#..\n.#..#.##..\n.#.##.#..#\n#.#.#.##.#\n....#...##\n...##..##.\n...#.#####\n.#.####.#.\n..#..###.#\n..##.#..#.\n\nTile 1489:\n##.#.#....\n..##...#..\n.##..##...\n..#...#...\n#####...#.\n#..#.#.#.#\n...#.#.#..\n##.#...##.\n..##.##.##\n###.##.#..\n\nTile 2473:\n#....####.\n#..#.##...\n#.##..#...\n######.#.#\n.#...#.#.#\n.#########\n.###.#..#.\n########.#\n##...##.#.\n..###.#.#.\n\nTile 2971:\n..#.#....#\n#...###...\n#.#.###...\n##.##..#..\n.#####..##\n.#..####.#\n#..#.#..#.\n..####.###\n..#.#.###.\n...#.#.#.#\n\nTile 2729:\n...#.#.#.#\n####.#....\n..#.#.....\n....#..#.#\n.##..##.#.\n.#.####...\n####.#.#..\n##.####...\n##..#.##..\n#.##...##.\n\nTile 3079:\n#.#.#####.\n.#..######\n..#.......\n######....\n####.#..#.\n.#...#.##.\n#.#####.##\n..#.###...\n..#.......\n..#.###...\n",
"expected": 20899048083289
}
],
"two": []
}
}

View file

@ -0,0 +1,77 @@
import json
import platform
import sys
from rich import print
from partOne import partOne
from partTwo import partTwo
def run_tests(test_cases):
do_tests = True
if len(test_cases) == 0:
do_tests = False
elif len(test_cases["one"]) == 0 and len(test_cases["two"]) == 0:
do_tests = False
if not do_tests:
print("Info: no test cases specified. Skipping tests\n")
return
print("Test cases")
def rt(tcs, f, n):
for i, tc in enumerate(tcs):
print(f"{n}.{i+1} ", end="")
expectedInt = tc["expected"]
result = f(str(tc["input"]))
if result == expectedInt:
print("[green]pass[/green]")
else:
print(f"[red]fail[/red] (got {result}, expected {expectedInt})")
rt(test_cases["one"], partOne, 1)
rt(test_cases["two"], partTwo, 2)
print()
if __name__ == "__main__":
try:
info = open("info.json").read()
except FileNotFoundError:
print("Error: could not open info.json")
sys.exit(-1)
info = json.loads(info)
year = info["year"]
day = info["day"]
title = info["title"]
print(f"[yellow]AoC {year}[/yellow]: day {day} - {title}")
print(f"Python {platform.python_version()}\n")
try:
challenge_input = open("input.txt").read()
except FileNotFoundError:
print("Error: could not open input.txt")
sys.exit(-1)
if "vis" in sys.argv:
import visualise
print("[green]Running visualisation....[/green]")
visualise.visualise(challenge_input)
sys.exit()
run_tests(info["testCases"])
if "debug" in sys.argv:
sys.exit()
print("Answers")
print("Part 1:", partOne(challenge_input))
print("Part 2:", partTwo(challenge_input))

View file

@ -0,0 +1,23 @@
from typing import List, Set
import re
class Tile:
components: List[List[str]]
edges: Set[str]
number: int
def __init__(self, instr:str) -> None:
split_input = instr.strip().split("\n")
self.number = int(re.search(r"Tile (\d+)", split_input[0]).group(1))
self.components = [list(x) for x in split_input[1:]]
self.edges = []
self.edges.append(split_input[1])
self.edges.append(split_input[-1])
self.edges.append("".join([self.components[x][0] for x in range(len(self.components))]))
self.edges.append("".join([self.components[x][-1] for x in range(len(self.components))]))
def parse(instr: str) -> List[Tile]:
return [Tile(x) for x in instr.strip().split("\n\n")]

View file

@ -0,0 +1,39 @@
from common import *
from pprint import pprint
def partOne(instr: str) -> int:
tiles = parse(instr)
edges = {}
for tile in tiles:
for edge in tile.edges:
if edge not in edges:
edges[edge] = set([tile.number])
else:
edges[edge].add(tile.number)
to_del = []
for edge in edges:
rev = "".join(reversed(edge))
if rev in edges:
edges[edge] = edges[edge].union(edges[rev])
to_del.append(rev)
for r in to_del:
del edges[r]
shared_edge_count = {x.number:0 for x in tiles}
for tile in tiles:
for x in edges:
tn = edges[x]
if tile.number in tn and len(tn) > 1:
shared_edge_count[tile.number] += 1
pprint(shared_edge_count)
pprint(edges)
return 0

View file

@ -0,0 +1,6 @@
from common import *
def partTwo(instr: str) -> int:
input_list = parse(instr)
return 0