Compare commits
10 Commits
b34578de33
...
f22d39ab8a
Author | SHA1 | Date |
---|---|---|
David Doblas Jiménez | f22d39ab8a | |
David Doblas Jiménez | da4e8d2aa3 | |
David Doblas Jiménez | 4740d7c891 | |
David Doblas Jiménez | 867ab20520 | |
David Doblas Jiménez | 02c2ac36b1 | |
David Doblas Jiménez | a38def1920 | |
David Doblas Jiménez | 1d0137c0e8 | |
David Doblas Jiménez | 80cc8790a8 | |
David Doblas Jiménez | c3faa9ea58 | |
David Doblas Jiménez | 7762c1fda9 |
|
@ -0,0 +1,123 @@
|
|||
# --- Day 13: Knights of the Dinner Table ---
|
||||
|
||||
# In years past, the holiday feast with your family hasn't gone so well. Not
|
||||
# everyone gets along! This year, you resolve, will be different. You're going
|
||||
# to find the optimal seating arrangement and avoid all those awkward
|
||||
# conversations.
|
||||
|
||||
# You start by writing up a list of everyone invited and the amount their
|
||||
# happiness would increase or decrease if they were to find themselves sitting
|
||||
# next to each other person. You have a circular table that will be just big
|
||||
# enough to fit everyone comfortably, and so each person will have exactly two
|
||||
# neighbors.
|
||||
|
||||
# For example, suppose you have only four attendees planned, and you calculate
|
||||
# their potential happiness as follows:
|
||||
|
||||
# Alice would gain 54 happiness units by sitting next to Bob.
|
||||
# Alice would lose 79 happiness units by sitting next to Carol.
|
||||
# Alice would lose 2 happiness units by sitting next to David.
|
||||
# Bob would gain 83 happiness units by sitting next to Alice.
|
||||
# Bob would lose 7 happiness units by sitting next to Carol.
|
||||
# Bob would lose 63 happiness units by sitting next to David.
|
||||
# Carol would lose 62 happiness units by sitting next to Alice.
|
||||
# Carol would gain 60 happiness units by sitting next to Bob.
|
||||
# Carol would gain 55 happiness units by sitting next to David.
|
||||
# David would gain 46 happiness units by sitting next to Alice.
|
||||
# David would lose 7 happiness units by sitting next to Bob.
|
||||
# David would gain 41 happiness units by sitting next to Carol.
|
||||
|
||||
# Then, if you seat Alice next to David, Alice would lose 2 happiness units
|
||||
# (because David talks so much), but David would gain 46 happiness units
|
||||
# (because Alice is such a good listener), for a total change of 44.
|
||||
|
||||
# If you continue around the table, you could then seat Bob next to Alice (Bob
|
||||
# gains 83, Alice gains 54). Finally, seat Carol, who sits next to Bob (Carol
|
||||
# gains 60, Bob loses 7) and David (Carol gains 55, David gains 41). The
|
||||
# arrangement looks like this:
|
||||
|
||||
# +41 +46
|
||||
# +55 David -2
|
||||
# Carol Alice
|
||||
# +60 Bob +54
|
||||
# -7 +83
|
||||
|
||||
# After trying every other seating arrangement in this hypothetical scenario,
|
||||
# you find that this one is the most optimal, with a total change in happiness
|
||||
# of 330.
|
||||
|
||||
# What is the total change in happiness for the optimal seating arrangement of
|
||||
# the actual guest list?
|
||||
|
||||
import re
|
||||
from collections import defaultdict
|
||||
from itertools import permutations
|
||||
from typing import DefaultDict
|
||||
|
||||
with open("files/P13.txt") as f:
|
||||
sittings = [line for line in f.read().strip().split("\n")]
|
||||
|
||||
|
||||
arrengements: DefaultDict = defaultdict(dict)
|
||||
for happiness in sittings:
|
||||
pattern = r"(?P<p1>\S+) would (?P<op>lose|gain) (?P<val>\d+) happiness units by sitting next to (?P<p2>\S+)."
|
||||
matches = re.match(pattern, happiness)
|
||||
p1, op, val, p2 = re.match(pattern, happiness).group(
|
||||
"p1", "op", "val", "p2"
|
||||
)
|
||||
arrengements[p1][p2] = -int(val) if op == "lose" else int(val)
|
||||
|
||||
|
||||
def part_1() -> None:
|
||||
max_happiness = 0
|
||||
for ordering in permutations(arrengements.keys()):
|
||||
happiness = sum(
|
||||
arrengements[a][b] + arrengements[b][a]
|
||||
for a, b in zip(ordering, ordering[1:])
|
||||
)
|
||||
happiness += (
|
||||
arrengements[ordering[0]][ordering[-1]]
|
||||
+ arrengements[ordering[-1]][ordering[0]]
|
||||
)
|
||||
max_happiness = max(max_happiness, happiness)
|
||||
print(f"The total change in happiness is {max_happiness}")
|
||||
|
||||
|
||||
# --- Part Two ---
|
||||
|
||||
# In all the commotion, you realize that you forgot to seat yourself. At this
|
||||
# point, you're pretty apathetic toward the whole thing, and your happiness
|
||||
# wouldn't really go up or down regardless of who you sit next to. You assume
|
||||
# everyone else would be just as ambivalent about sitting next to you, too.
|
||||
|
||||
# So, add yourself to the list, and give all happiness relationships that
|
||||
# involve you a score of 0.
|
||||
|
||||
# What is the total change in happiness for the optimal seating arrangement
|
||||
# that actually includes yourself?
|
||||
|
||||
|
||||
def part_2() -> None:
|
||||
for somebody in list(arrengements.keys()):
|
||||
arrengements["me"][somebody] = 0
|
||||
arrengements[somebody]["me"] = 0
|
||||
|
||||
max_happiness = 0
|
||||
for ordering in permutations(arrengements.keys()):
|
||||
happiness = sum(
|
||||
arrengements[a][b] + arrengements[b][a]
|
||||
for a, b in zip(ordering, ordering[1:])
|
||||
)
|
||||
happiness += (
|
||||
arrengements[ordering[0]][ordering[-1]]
|
||||
+ arrengements[ordering[-1]][ordering[0]]
|
||||
)
|
||||
max_happiness = max(max_happiness, happiness)
|
||||
print(
|
||||
f"The total change in happiness is {max_happiness}, including myself"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
part_1()
|
||||
part_2()
|
|
@ -0,0 +1,56 @@
|
|||
Alice would gain 54 happiness units by sitting next to Bob.
|
||||
Alice would lose 81 happiness units by sitting next to Carol.
|
||||
Alice would lose 42 happiness units by sitting next to David.
|
||||
Alice would gain 89 happiness units by sitting next to Eric.
|
||||
Alice would lose 89 happiness units by sitting next to Frank.
|
||||
Alice would gain 97 happiness units by sitting next to George.
|
||||
Alice would lose 94 happiness units by sitting next to Mallory.
|
||||
Bob would gain 3 happiness units by sitting next to Alice.
|
||||
Bob would lose 70 happiness units by sitting next to Carol.
|
||||
Bob would lose 31 happiness units by sitting next to David.
|
||||
Bob would gain 72 happiness units by sitting next to Eric.
|
||||
Bob would lose 25 happiness units by sitting next to Frank.
|
||||
Bob would lose 95 happiness units by sitting next to George.
|
||||
Bob would gain 11 happiness units by sitting next to Mallory.
|
||||
Carol would lose 83 happiness units by sitting next to Alice.
|
||||
Carol would gain 8 happiness units by sitting next to Bob.
|
||||
Carol would gain 35 happiness units by sitting next to David.
|
||||
Carol would gain 10 happiness units by sitting next to Eric.
|
||||
Carol would gain 61 happiness units by sitting next to Frank.
|
||||
Carol would gain 10 happiness units by sitting next to George.
|
||||
Carol would gain 29 happiness units by sitting next to Mallory.
|
||||
David would gain 67 happiness units by sitting next to Alice.
|
||||
David would gain 25 happiness units by sitting next to Bob.
|
||||
David would gain 48 happiness units by sitting next to Carol.
|
||||
David would lose 65 happiness units by sitting next to Eric.
|
||||
David would gain 8 happiness units by sitting next to Frank.
|
||||
David would gain 84 happiness units by sitting next to George.
|
||||
David would gain 9 happiness units by sitting next to Mallory.
|
||||
Eric would lose 51 happiness units by sitting next to Alice.
|
||||
Eric would lose 39 happiness units by sitting next to Bob.
|
||||
Eric would gain 84 happiness units by sitting next to Carol.
|
||||
Eric would lose 98 happiness units by sitting next to David.
|
||||
Eric would lose 20 happiness units by sitting next to Frank.
|
||||
Eric would lose 6 happiness units by sitting next to George.
|
||||
Eric would gain 60 happiness units by sitting next to Mallory.
|
||||
Frank would gain 51 happiness units by sitting next to Alice.
|
||||
Frank would gain 79 happiness units by sitting next to Bob.
|
||||
Frank would gain 88 happiness units by sitting next to Carol.
|
||||
Frank would gain 33 happiness units by sitting next to David.
|
||||
Frank would gain 43 happiness units by sitting next to Eric.
|
||||
Frank would gain 77 happiness units by sitting next to George.
|
||||
Frank would lose 3 happiness units by sitting next to Mallory.
|
||||
George would lose 14 happiness units by sitting next to Alice.
|
||||
George would lose 12 happiness units by sitting next to Bob.
|
||||
George would lose 52 happiness units by sitting next to Carol.
|
||||
George would gain 14 happiness units by sitting next to David.
|
||||
George would lose 62 happiness units by sitting next to Eric.
|
||||
George would lose 18 happiness units by sitting next to Frank.
|
||||
George would lose 17 happiness units by sitting next to Mallory.
|
||||
Mallory would lose 36 happiness units by sitting next to Alice.
|
||||
Mallory would gain 76 happiness units by sitting next to Bob.
|
||||
Mallory would lose 34 happiness units by sitting next to Carol.
|
||||
Mallory would gain 37 happiness units by sitting next to David.
|
||||
Mallory would gain 40 happiness units by sitting next to Eric.
|
||||
Mallory would gain 18 happiness units by sitting next to Frank.
|
||||
Mallory would gain 7 happiness units by sitting next to George.
|
|
@ -0,0 +1,221 @@
|
|||
# --- Day 12: Passage Pathing ---
|
||||
|
||||
# With your submarine's subterranean subsystems subsisting suboptimally, the
|
||||
# only way you're getting out of this cave anytime soon is by finding a path
|
||||
# yourself. Not just a path - the only way to know if you've found the best
|
||||
# path is to find all of them.
|
||||
|
||||
# Fortunately, the sensors are still mostly working, and so you build a rough
|
||||
# map of the remaining caves (your puzzle input). For example:
|
||||
|
||||
# start-A
|
||||
# start-b
|
||||
# A-c
|
||||
# A-b
|
||||
# b-d
|
||||
# A-end
|
||||
# b-end
|
||||
|
||||
# This is a list of how all of the caves are connected. You start in the cave
|
||||
# named start, and your destination is the cave named end. An entry like b-d
|
||||
# means that cave b is connected to cave d - that is, you can move between
|
||||
# them.
|
||||
|
||||
# So, the above cave system looks roughly like this:
|
||||
|
||||
# start
|
||||
# / \
|
||||
# c--A-----b--d
|
||||
# \ /
|
||||
# end
|
||||
|
||||
# Your goal is to find the number of distinct paths that start at start, end at
|
||||
# end, and don't visit small caves more than once. There are two types of
|
||||
# caves: big caves (written in uppercase, like A) and small caves (written in
|
||||
# lowercase, like b). It would be a waste of time to visit any small cave more
|
||||
# than once, but big caves are large enough that it might be worth visiting
|
||||
# them multiple times. So, all paths you find should visit small caves at most
|
||||
# once, and can visit big caves any number of times.
|
||||
|
||||
# Given these rules, there are 10 paths through this example cave system:
|
||||
|
||||
# start,A,b,A,c,A,end
|
||||
# start,A,b,A,end
|
||||
# start,A,b,end
|
||||
# start,A,c,A,b,A,end
|
||||
# start,A,c,A,b,end
|
||||
# start,A,c,A,end
|
||||
# start,A,end
|
||||
# start,b,A,c,A,end
|
||||
# start,b,A,end
|
||||
# start,b,end
|
||||
|
||||
# (Each line in the above list corresponds to a single path; the caves visited
|
||||
# by that path are listed in the order they are visited and separated by
|
||||
# commas.)
|
||||
|
||||
# Note that in this cave system, cave d is never visited by any path: to do so,
|
||||
# cave b would need to be visited twice (once on the way to cave d and a second
|
||||
# time when returning from cave d), and since cave b is small, this is not
|
||||
# allowed.
|
||||
|
||||
# Here is a slightly larger example:
|
||||
|
||||
# dc-end
|
||||
# HN-start
|
||||
# start-kj
|
||||
# dc-start
|
||||
# dc-HN
|
||||
# LN-dc
|
||||
# HN-end
|
||||
# kj-sa
|
||||
# kj-HN
|
||||
# kj-dc
|
||||
|
||||
# The 19 paths through it are as follows:
|
||||
|
||||
# start,HN,dc,HN,end
|
||||
# start,HN,dc,HN,kj,HN,end
|
||||
# start,HN,dc,end
|
||||
# start,HN,dc,kj,HN,end
|
||||
# start,HN,end
|
||||
# start,HN,kj,HN,dc,HN,end
|
||||
# start,HN,kj,HN,dc,end
|
||||
# start,HN,kj,HN,end
|
||||
# start,HN,kj,dc,HN,end
|
||||
# start,HN,kj,dc,end
|
||||
# start,dc,HN,end
|
||||
# start,dc,HN,kj,HN,end
|
||||
# start,dc,end
|
||||
# start,dc,kj,HN,end
|
||||
# start,kj,HN,dc,HN,end
|
||||
# start,kj,HN,dc,end
|
||||
# start,kj,HN,end
|
||||
# start,kj,dc,HN,end
|
||||
# start,kj,dc,end
|
||||
|
||||
# Finally, this even larger example has 226 paths through it:
|
||||
|
||||
# fs-end
|
||||
# he-DX
|
||||
# fs-he
|
||||
# start-DX
|
||||
# pj-DX
|
||||
# end-zg
|
||||
# zg-sl
|
||||
# zg-pj
|
||||
# pj-he
|
||||
# RW-he
|
||||
# fs-DX
|
||||
# pj-RW
|
||||
# zg-RW
|
||||
# start-pj
|
||||
# he-WI
|
||||
# zg-he
|
||||
# pj-fs
|
||||
# start-RW
|
||||
|
||||
# How many paths through this cave system are there that visit small caves at
|
||||
# most once?
|
||||
|
||||
from collections import defaultdict
|
||||
from typing import DefaultDict
|
||||
|
||||
caves_map = defaultdict(list)
|
||||
with open("files/P12.txt") as f:
|
||||
for row in f:
|
||||
start, end = row.strip().split("-")
|
||||
caves_map[start].append(end)
|
||||
caves_map[end].append(start)
|
||||
|
||||
|
||||
def dfs(
|
||||
node: str,
|
||||
graph: DefaultDict[str, list[str]],
|
||||
visited: set[str],
|
||||
already_visited: bool,
|
||||
counter: int = 0,
|
||||
):
|
||||
if node == "end":
|
||||
return 1
|
||||
for neighbour in graph[node]:
|
||||
if neighbour.isupper():
|
||||
counter += dfs(neighbour, graph, visited, already_visited)
|
||||
else:
|
||||
if neighbour not in visited:
|
||||
counter += dfs(
|
||||
neighbour, graph, visited | {neighbour}, already_visited
|
||||
)
|
||||
elif already_visited and neighbour not in {"start", "end"}:
|
||||
counter += dfs(neighbour, graph, visited, False)
|
||||
return counter
|
||||
|
||||
|
||||
def part_1() -> None:
|
||||
ans = dfs("start", caves_map, {"start"}, already_visited=False)
|
||||
print(f"There are {ans} paths visiting small caves")
|
||||
|
||||
|
||||
# --- Part Two ---
|
||||
|
||||
# After reviewing the available paths, you realize you might have time to visit
|
||||
# a single small cave twice. Specifically, big caves can be visited any number
|
||||
# of times, a single small cave can be visited at most twice, and the remaining
|
||||
# small caves can be visited at most once. However, the caves named start and
|
||||
# end can only be visited exactly once each: once you leave the start cave, you
|
||||
# may not return to it, and once you reach the end cave, the path must end
|
||||
# immediately.
|
||||
|
||||
# Now, the 36 possible paths through the first example above are:
|
||||
|
||||
# start,A,b,A,b,A,c,A,end
|
||||
# start,A,b,A,b,A,end
|
||||
# start,A,b,A,b,end
|
||||
# start,A,b,A,c,A,b,A,end
|
||||
# start,A,b,A,c,A,b,end
|
||||
# start,A,b,A,c,A,c,A,end
|
||||
# start,A,b,A,c,A,end
|
||||
# start,A,b,A,end
|
||||
# start,A,b,d,b,A,c,A,end
|
||||
# start,A,b,d,b,A,end
|
||||
# start,A,b,d,b,end
|
||||
# start,A,b,end
|
||||
# start,A,c,A,b,A,b,A,end
|
||||
# start,A,c,A,b,A,b,end
|
||||
# start,A,c,A,b,A,c,A,end
|
||||
# start,A,c,A,b,A,end
|
||||
# start,A,c,A,b,d,b,A,end
|
||||
# start,A,c,A,b,d,b,end
|
||||
# start,A,c,A,b,end
|
||||
# start,A,c,A,c,A,b,A,end
|
||||
# start,A,c,A,c,A,b,end
|
||||
# start,A,c,A,c,A,end
|
||||
# start,A,c,A,end
|
||||
# start,A,end
|
||||
# start,b,A,b,A,c,A,end
|
||||
# start,b,A,b,A,end
|
||||
# start,b,A,b,end
|
||||
# start,b,A,c,A,b,A,end
|
||||
# start,b,A,c,A,b,end
|
||||
# start,b,A,c,A,c,A,end
|
||||
# start,b,A,c,A,end
|
||||
# start,b,A,end
|
||||
# start,b,d,b,A,c,A,end
|
||||
# start,b,d,b,A,end
|
||||
# start,b,d,b,end
|
||||
# start,b,end
|
||||
|
||||
# The slightly larger example above now has 103 paths through it, and the even
|
||||
# larger example now has 3509 paths through it.
|
||||
|
||||
# Given these new rules, how many paths through this cave system are there?
|
||||
|
||||
|
||||
def part_2() -> None:
|
||||
ans = dfs("start", caves_map, {"start"}, already_visited=True)
|
||||
print(f"There are {ans} paths in total")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
part_1()
|
||||
part_2()
|
|
@ -0,0 +1,184 @@
|
|||
# --- Day 13: Transparent Origami ---
|
||||
|
||||
# You reach another volcanically active part of the cave. It would be nice if
|
||||
# you could do some kind of thermal imaging so you could tell ahead of time
|
||||
# which caves are too hot to safely enter.
|
||||
|
||||
# Fortunately, the submarine seems to be equipped with a thermal camera! When
|
||||
# you activate it, you are greeted with:
|
||||
|
||||
# Congratulations on your purchase! To activate this infrared thermal imaging
|
||||
# camera system, please enter the code found on page 1 of the manual.
|
||||
|
||||
# Apparently, the Elves have never used this feature. To your surprise, you
|
||||
# manage to find the manual; as you go to open it, page 1 falls out. It's a
|
||||
# large sheet of transparent paper! The transparent paper is marked with random
|
||||
# dots and includes instructions on how to fold it up (your puzzle input).
|
||||
# For example:
|
||||
|
||||
# 6,10
|
||||
# 0,14
|
||||
# 9,10
|
||||
# 0,3
|
||||
# 10,4
|
||||
# 4,11
|
||||
# 6,0
|
||||
# 6,12
|
||||
# 4,1
|
||||
# 0,13
|
||||
# 10,12
|
||||
# 3,4
|
||||
# 3,0
|
||||
# 8,4
|
||||
# 1,10
|
||||
# 2,14
|
||||
# 8,10
|
||||
# 9,0
|
||||
|
||||
# fold along y=7
|
||||
# fold along x=5
|
||||
|
||||
# The first section is a list of dots on the transparent paper. 0,0 represents
|
||||
# the top-left coordinate. The first value, x, increases to the right. The
|
||||
# second value, y, increases downward. So, the coordinate 3,0 is to the right
|
||||
# of 0,0, and the coordinate 0,7 is below 0,0. The coordinates in this example
|
||||
# form the following pattern, where # is a dot on the paper and . is an empty,
|
||||
# unmarked position:
|
||||
|
||||
# ...#..#..#.
|
||||
# ....#......
|
||||
# ...........
|
||||
# #..........
|
||||
# ...#....#.#
|
||||
# ...........
|
||||
# ...........
|
||||
# ...........
|
||||
# ...........
|
||||
# ...........
|
||||
# .#....#.##.
|
||||
# ....#......
|
||||
# ......#...#
|
||||
# #..........
|
||||
# #.#........
|
||||
|
||||
# Then, there is a list of fold instructions. Each instruction indicates a line
|
||||
# on the transparent paper and wants you to fold the paper up (for horizontal
|
||||
# y=... lines) or left (for vertical x=... lines). In this example, the first
|
||||
# fold instruction is fold along y=7, which designates the line formed by all
|
||||
# of the positions where y is 7 (marked here with -):
|
||||
|
||||
# ...#..#..#.
|
||||
# ....#......
|
||||
# ...........
|
||||
# #..........
|
||||
# ...#....#.#
|
||||
# ...........
|
||||
# ...........
|
||||
# -----------
|
||||
# ...........
|
||||
# ...........
|
||||
# .#....#.##.
|
||||
# ....#......
|
||||
# ......#...#
|
||||
# #..........
|
||||
# #.#........
|
||||
|
||||
# Because this is a horizontal line, fold the bottom half up. Some of the dots
|
||||
# might end up overlapping after the fold is complete, but dots will never
|
||||
# appear exactly on a fold line. The result of doing this fold looks like this:
|
||||
|
||||
# #.##..#..#.
|
||||
# #...#......
|
||||
# ......#...#
|
||||
# #...#......
|
||||
# .#.#..#.###
|
||||
# ...........
|
||||
# ...........
|
||||
|
||||
# Now, only 17 dots are visible.
|
||||
|
||||
# Notice, for example, the two dots in the bottom left corner before the
|
||||
# transparent paper is folded; after the fold is complete, those dots appear in
|
||||
# the top left corner (at 0,0 and 0,1). Because the paper is transparent, the
|
||||
# dot just below them in the result (at 0,3) remains visible, as it can be seen
|
||||
# through the transparent paper.
|
||||
|
||||
# Also notice that some dots can end up overlapping; in this case, the dots
|
||||
# merge together and become a single dot.
|
||||
|
||||
# The second fold instruction is fold along x=5, which indicates this line:
|
||||
|
||||
# #.##.|#..#.
|
||||
# #...#|.....
|
||||
# .....|#...#
|
||||
# #...#|.....
|
||||
# .#.#.|#.###
|
||||
# .....|.....
|
||||
# .....|.....
|
||||
|
||||
# Because this is a vertical line, fold left:
|
||||
|
||||
# #####
|
||||
# #...#
|
||||
# #...#
|
||||
# #...#
|
||||
# #####
|
||||
# .....
|
||||
# .....
|
||||
|
||||
# The instructions made a square!
|
||||
|
||||
# The transparent paper is pretty big, so for now, focus on just completing the
|
||||
# first fold. After the first fold in the example above, 17 dots are visible -
|
||||
# dots that end up overlapping after the fold is completed count as a single
|
||||
# dot.
|
||||
|
||||
# How many dots are visible after completing just the first fold instruction on
|
||||
# your transparent paper?
|
||||
|
||||
from copy import copy
|
||||
|
||||
with open("files/P13.txt", "r") as f:
|
||||
dots, folds = [line for line in f.read().strip().split("\n\n")]
|
||||
|
||||
_dots = {tuple(map(int, row.split(","))) for row in dots.split("\n")}
|
||||
_folds = [(s[11] == "y", int(s[13:])) for s in folds.split("\n")]
|
||||
|
||||
|
||||
def fold(dim, value, dots):
|
||||
folded = {dot for dot in dots if dot[dim] < value}
|
||||
for x, y in dots - folded:
|
||||
folded.add((x, 2 * value - y) if dim else (2 * value - x, y))
|
||||
return folded
|
||||
|
||||
|
||||
def part_1():
|
||||
ans = len(fold(*_folds[0], _dots))
|
||||
print(f"There are {ans} dots visible after 1 fold")
|
||||
|
||||
|
||||
# --- Part Two ---
|
||||
|
||||
# Finish folding the transparent paper according to the instructions. The
|
||||
# manual says the code is always eight capital letters.
|
||||
|
||||
# What code do you use to activate the infrared thermal imaging camera system?
|
||||
|
||||
|
||||
def part_2():
|
||||
dots = copy(_dots)
|
||||
for dim, value in _folds:
|
||||
dots = fold(dim, value, dots)
|
||||
|
||||
maxX, maxY = map(max, zip(*dots))
|
||||
|
||||
print("The code is: \n")
|
||||
for y in range(maxY + 1):
|
||||
for x in range(maxX + 1):
|
||||
print("X" if (x, y) in dots else " ", end="")
|
||||
print()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
part_1()
|
||||
part_2()
|
|
@ -0,0 +1,22 @@
|
|||
end-MY
|
||||
MY-xc
|
||||
ho-NF
|
||||
start-ho
|
||||
NF-xc
|
||||
NF-yf
|
||||
end-yf
|
||||
xc-TP
|
||||
MY-qo
|
||||
yf-TP
|
||||
dc-NF
|
||||
dc-xc
|
||||
start-dc
|
||||
yf-MY
|
||||
MY-ho
|
||||
EM-uh
|
||||
xc-yf
|
||||
ho-dc
|
||||
uh-NF
|
||||
yf-ho
|
||||
end-uh
|
||||
start-NF
|
|
@ -0,0 +1,987 @@
|
|||
982,10
|
||||
1094,887
|
||||
895,815
|
||||
1216,453
|
||||
1258,747
|
||||
162,663
|
||||
552,568
|
||||
271,662
|
||||
333,863
|
||||
1252,65
|
||||
1009,687
|
||||
900,887
|
||||
199,273
|
||||
254,352
|
||||
345,787
|
||||
688,502
|
||||
825,325
|
||||
137,879
|
||||
1258,467
|
||||
547,42
|
||||
251,275
|
||||
446,628
|
||||
108,84
|
||||
1257,668
|
||||
1141,316
|
||||
679,548
|
||||
930,831
|
||||
463,700
|
||||
785,393
|
||||
485,578
|
||||
678,78
|
||||
1047,37
|
||||
1123,613
|
||||
586,535
|
||||
65,275
|
||||
1233,665
|
||||
137,15
|
||||
1115,210
|
||||
306,890
|
||||
946,234
|
||||
959,122
|
||||
518,814
|
||||
229,204
|
||||
985,439
|
||||
44,534
|
||||
48,838
|
||||
1258,483
|
||||
237,250
|
||||
763,852
|
||||
1134,117
|
||||
857,324
|
||||
674,310
|
||||
1032,537
|
||||
1148,809
|
||||
900,623
|
||||
549,178
|
||||
157,137
|
||||
721,247
|
||||
244,623
|
||||
584,351
|
||||
438,518
|
||||
527,674
|
||||
1292,86
|
||||
977,618
|
||||
420,667
|
||||
1170,812
|
||||
445,627
|
||||
438,887
|
||||
224,814
|
||||
1263,197
|
||||
738,409
|
||||
1262,504
|
||||
393,199
|
||||
1302,16
|
||||
259,50
|
||||
934,357
|
||||
470,451
|
||||
460,414
|
||||
552,684
|
||||
585,789
|
||||
1131,367
|
||||
23,346
|
||||
1089,245
|
||||
827,42
|
||||
200,819
|
||||
917,666
|
||||
1295,807
|
||||
58,289
|
||||
678,816
|
||||
1201,497
|
||||
176,320
|
||||
269,716
|
||||
130,602
|
||||
826,854
|
||||
758,344
|
||||
1009,262
|
||||
499,60
|
||||
1191,329
|
||||
905,453
|
||||
1262,761
|
||||
180,82
|
||||
162,309
|
||||
189,658
|
||||
547,341
|
||||
460,793
|
||||
1285,434
|
||||
162,809
|
||||
189,684
|
||||
48,761
|
||||
708,147
|
||||
378,884
|
||||
15,807
|
||||
751,395
|
||||
1163,831
|
||||
708,35
|
||||
484,40
|
||||
827,597
|
||||
1243,789
|
||||
15,620
|
||||
281,381
|
||||
944,773
|
||||
221,875
|
||||
1203,456
|
||||
1126,3
|
||||
1272,325
|
||||
137,572
|
||||
518,528
|
||||
171,297
|
||||
1073,644
|
||||
711,753
|
||||
137,836
|
||||
902,210
|
||||
90,318
|
||||
976,532
|
||||
185,546
|
||||
1272,345
|
||||
681,465
|
||||
796,82
|
||||
826,317
|
||||
208,628
|
||||
1255,680
|
||||
77,665
|
||||
1183,526
|
||||
181,647
|
||||
857,570
|
||||
290,884
|
||||
294,406
|
||||
974,767
|
||||
974,575
|
||||
596,381
|
||||
1148,757
|
||||
1164,28
|
||||
1215,340
|
||||
850,190
|
||||
89,740
|
||||
661,651
|
||||
1310,75
|
||||
893,602
|
||||
999,870
|
||||
1113,379
|
||||
1300,135
|
||||
925,551
|
||||
596,737
|
||||
770,404
|
||||
662,653
|
||||
184,136
|
||||
6,294
|
||||
930,483
|
||||
713,579
|
||||
803,24
|
||||
763,135
|
||||
585,105
|
||||
694,325
|
||||
179,611
|
||||
699,278
|
||||
82,572
|
||||
147,831
|
||||
661,549
|
||||
18,361
|
||||
1164,448
|
||||
976,362
|
||||
1205,492
|
||||
663,54
|
||||
912,127
|
||||
1240,44
|
||||
813,345
|
||||
740,243
|
||||
1014,10
|
||||
530,121
|
||||
1222,308
|
||||
218,702
|
||||
710,341
|
||||
1057,250
|
||||
0,317
|
||||
961,124
|
||||
57,271
|
||||
585,278
|
||||
1190,627
|
||||
671,172
|
||||
716,579
|
||||
1081,432
|
||||
782,422
|
||||
179,472
|
||||
1101,388
|
||||
263,597
|
||||
1226,651
|
||||
982,458
|
||||
796,760
|
||||
467,579
|
||||
1146,663
|
||||
1228,322
|
||||
914,217
|
||||
382,894
|
||||
872,518
|
||||
363,99
|
||||
209,53
|
||||
1148,585
|
||||
475,646
|
||||
38,345
|
||||
458,852
|
||||
319,278
|
||||
200,747
|
||||
1141,662
|
||||
648,241
|
||||
140,642
|
||||
887,453
|
||||
120,179
|
||||
623,679
|
||||
1283,539
|
||||
508,28
|
||||
383,5
|
||||
1170,642
|
||||
716,331
|
||||
420,543
|
||||
262,807
|
||||
237,154
|
||||
927,835
|
||||
857,122
|
||||
1019,795
|
||||
753,652
|
||||
518,808
|
||||
140,700
|
||||
996,789
|
||||
719,149
|
||||
127,220
|
||||
890,799
|
||||
768,393
|
||||
253,250
|
||||
1091,365
|
||||
1036,707
|
||||
45,211
|
||||
1079,117
|
||||
57,789
|
||||
845,98
|
||||
977,326
|
||||
751,843
|
||||
320,824
|
||||
397,434
|
||||
140,194
|
||||
448,235
|
||||
1146,585
|
||||
60,255
|
||||
1251,605
|
||||
594,331
|
||||
597,346
|
||||
1213,652
|
||||
1111,273
|
||||
82,85
|
||||
619,289
|
||||
89,74
|
||||
1021,558
|
||||
18,808
|
||||
376,357
|
||||
415,815
|
||||
137,711
|
||||
647,54
|
||||
619,605
|
||||
1061,441
|
||||
425,690
|
||||
905,217
|
||||
216,875
|
||||
555,73
|
||||
671,807
|
||||
1310,317
|
||||
1273,425
|
||||
1136,494
|
||||
1200,824
|
||||
527,560
|
||||
1258,259
|
||||
775,329
|
||||
1101,53
|
||||
288,325
|
||||
206,101
|
||||
67,423
|
||||
473,602
|
||||
806,768
|
||||
1221,740
|
||||
699,502
|
||||
453,122
|
||||
1279,175
|
||||
557,320
|
||||
877,649
|
||||
251,619
|
||||
474,84
|
||||
1203,553
|
||||
217,688
|
||||
1130,476
|
||||
557,126
|
||||
214,477
|
||||
293,449
|
||||
714,157
|
||||
749,117
|
||||
549,850
|
||||
333,774
|
||||
925,445
|
||||
600,362
|
||||
1305,91
|
||||
934,628
|
||||
326,877
|
||||
1192,259
|
||||
582,576
|
||||
68,117
|
||||
301,499
|
||||
596,157
|
||||
883,796
|
||||
599,889
|
||||
766,287
|
||||
982,595
|
||||
468,312
|
||||
430,219
|
||||
1041,716
|
||||
649,243
|
||||
1116,345
|
||||
768,865
|
||||
412,355
|
||||
1052,105
|
||||
1198,571
|
||||
497,773
|
||||
1081,14
|
||||
1084,309
|
||||
293,445
|
||||
542,865
|
||||
1119,86
|
||||
930,747
|
||||
716,315
|
||||
1034,10
|
||||
1278,406
|
||||
934,852
|
||||
514,760
|
||||
164,232
|
||||
497,809
|
||||
1155,644
|
||||
1304,294
|
||||
1173,15
|
||||
600,782
|
||||
187,281
|
||||
852,42
|
||||
1056,352
|
||||
763,589
|
||||
185,98
|
||||
80,747
|
||||
1238,318
|
||||
140,252
|
||||
818,679
|
||||
80,658
|
||||
499,698
|
||||
95,51
|
||||
320,70
|
||||
984,877
|
||||
318,319
|
||||
234,227
|
||||
421,777
|
||||
187,21
|
||||
60,563
|
||||
1057,644
|
||||
395,641
|
||||
403,171
|
||||
458,70
|
||||
445,659
|
||||
597,623
|
||||
60,479
|
||||
37,105
|
||||
820,309
|
||||
32,392
|
||||
1086,366
|
||||
353,744
|
||||
82,124
|
||||
507,24
|
||||
474,866
|
||||
1079,441
|
||||
273,194
|
||||
1170,252
|
||||
416,572
|
||||
326,429
|
||||
1052,329
|
||||
562,239
|
||||
689,841
|
||||
591,149
|
||||
1089,651
|
||||
826,488
|
||||
274,383
|
||||
959,469
|
||||
1292,310
|
||||
719,597
|
||||
990,308
|
||||
673,471
|
||||
686,10
|
||||
1102,259
|
||||
1208,326
|
||||
17,23
|
||||
761,626
|
||||
1166,422
|
||||
328,884
|
||||
278,852
|
||||
1241,278
|
||||
263,37
|
||||
244,53
|
||||
843,579
|
||||
990,362
|
||||
755,423
|
||||
446,259
|
||||
335,610
|
||||
393,703
|
||||
1108,569
|
||||
836,84
|
||||
170,742
|
||||
765,170
|
||||
970,105
|
||||
465,658
|
||||
714,737
|
||||
763,813
|
||||
303,469
|
||||
992,575
|
||||
1145,567
|
||||
10,135
|
||||
12,264
|
||||
792,534
|
||||
810,575
|
||||
209,235
|
||||
52,35
|
||||
537,627
|
||||
1123,281
|
||||
517,183
|
||||
1033,208
|
||||
343,696
|
||||
1245,275
|
||||
991,616
|
||||
596,605
|
||||
1228,533
|
||||
656,436
|
||||
950,831
|
||||
880,770
|
||||
781,234
|
||||
1153,549
|
||||
1130,364
|
||||
380,595
|
||||
365,660
|
||||
185,12
|
||||
474,810
|
||||
547,852
|
||||
726,351
|
||||
639,172
|
||||
334,756
|
||||
69,168
|
||||
1304,742
|
||||
1184,422
|
||||
231,453
|
||||
1213,242
|
||||
856,299
|
||||
288,569
|
||||
636,584
|
||||
1104,101
|
||||
835,611
|
||||
1081,515
|
||||
1241,504
|
||||
1153,773
|
||||
156,40
|
||||
662,488
|
||||
544,287
|
||||
1310,10
|
||||
1153,345
|
||||
137,183
|
||||
1163,876
|
||||
1121,731
|
||||
518,360
|
||||
473,647
|
||||
1255,214
|
||||
242,355
|
||||
970,341
|
||||
333,618
|
||||
180,250
|
||||
716,663
|
||||
380,511
|
||||
776,627
|
||||
380,747
|
||||
802,0
|
||||
1295,620
|
||||
925,343
|
||||
636,86
|
||||
246,7
|
||||
874,362
|
||||
333,887
|
||||
75,198
|
||||
261,666
|
||||
793,836
|
||||
827,149
|
||||
130,292
|
||||
1146,309
|
||||
793,711
|
||||
974,127
|
||||
1134,544
|
||||
796,812
|
||||
989,618
|
||||
430,80
|
||||
497,85
|
||||
1009,150
|
||||
80,595
|
||||
343,847
|
||||
740,651
|
||||
629,520
|
||||
1163,422
|
||||
363,347
|
||||
984,429
|
||||
1253,579
|
||||
341,498
|
||||
435,789
|
||||
1207,294
|
||||
492,348
|
||||
127,674
|
||||
549,47
|
||||
661,354
|
||||
622,502
|
||||
759,294
|
||||
930,595
|
||||
1218,655
|
||||
144,757
|
||||
910,749
|
||||
1203,135
|
||||
796,816
|
||||
1253,693
|
||||
693,336
|
||||
874,282
|
||||
649,578
|
||||
334,653
|
||||
380,63
|
||||
656,765
|
||||
560,553
|
||||
457,1
|
||||
237,644
|
||||
984,884
|
||||
542,323
|
||||
55,589
|
||||
770,40
|
||||
512,218
|
||||
112,393
|
||||
1036,187
|
||||
219,38
|
||||
837,247
|
||||
360,392
|
||||
1253,5
|
||||
808,46
|
||||
631,346
|
||||
782,248
|
||||
37,10
|
||||
301,262
|
||||
87,463
|
||||
781,525
|
||||
803,831
|
||||
179,367
|
||||
229,880
|
||||
1004,442
|
||||
1126,891
|
||||
147,63
|
||||
381,418
|
||||
32,502
|
||||
483,490
|
||||
954,518
|
||||
1084,361
|
||||
52,427
|
||||
545,497
|
||||
408,371
|
||||
827,404
|
||||
1211,423
|
||||
528,248
|
||||
135,497
|
||||
436,362
|
||||
52,707
|
||||
713,623
|
||||
462,824
|
||||
1285,15
|
||||
187,613
|
||||
825,578
|
||||
130,490
|
||||
495,441
|
||||
237,602
|
||||
508,194
|
||||
393,666
|
||||
1037,476
|
||||
1121,796
|
||||
1036,511
|
||||
1193,625
|
||||
982,884
|
||||
1064,147
|
||||
725,12
|
||||
291,617
|
||||
919,597
|
||||
108,560
|
||||
328,877
|
||||
403,723
|
||||
484,294
|
||||
627,355
|
||||
763,81
|
||||
109,2
|
||||
691,289
|
||||
453,570
|
||||
190,814
|
||||
271,232
|
||||
1278,488
|
||||
907,171
|
||||
1015,231
|
||||
945,201
|
||||
1221,74
|
||||
1086,120
|
||||
254,542
|
||||
1081,686
|
||||
826,294
|
||||
393,695
|
||||
504,126
|
||||
836,810
|
||||
1130,530
|
||||
749,329
|
||||
5,540
|
||||
1267,145
|
||||
1125,546
|
||||
766,824
|
||||
572,389
|
||||
1295,422
|
||||
1051,844
|
||||
88,124
|
||||
1230,595
|
||||
890,95
|
||||
169,680
|
||||
164,214
|
||||
1094,7
|
||||
930,35
|
||||
1094,831
|
||||
813,773
|
||||
753,320
|
||||
525,515
|
||||
290,635
|
||||
25,744
|
||||
629,15
|
||||
1076,799
|
||||
1089,875
|
||||
1173,711
|
||||
880,124
|
||||
181,602
|
||||
103,294
|
||||
930,299
|
||||
542,193
|
||||
95,395
|
||||
0,877
|
||||
340,630
|
||||
599,441
|
||||
864,259
|
||||
1129,602
|
||||
364,187
|
||||
890,667
|
||||
929,220
|
||||
865,501
|
||||
1202,84
|
||||
877,243
|
||||
18,533
|
||||
792,814
|
||||
1272,569
|
||||
873,276
|
||||
155,834
|
||||
853,1
|
||||
1148,886
|
||||
764,670
|
||||
1230,236
|
||||
585,385
|
||||
108,670
|
||||
1088,605
|
||||
436,702
|
||||
818,546
|
||||
15,870
|
||||
551,294
|
||||
410,299
|
||||
810,319
|
||||
1081,242
|
||||
975,610
|
||||
1066,361
|
||||
333,467
|
||||
1215,395
|
||||
432,289
|
||||
408,147
|
||||
639,807
|
||||
305,124
|
||||
152,232
|
||||
602,187
|
||||
1053,49
|
||||
244,85
|
||||
191,86
|
||||
1096,234
|
||||
82,147
|
||||
782,646
|
||||
1081,208
|
||||
852,852
|
||||
928,58
|
||||
43,278
|
||||
57,665
|
||||
1217,609
|
||||
437,838
|
||||
462,376
|
||||
525,893
|
||||
524,292
|
||||
738,837
|
||||
52,187
|
||||
872,159
|
||||
261,247
|
||||
873,504
|
||||
169,662
|
||||
1129,647
|
||||
385,178
|
||||
200,595
|
||||
562,655
|
||||
249,453
|
||||
1262,56
|
||||
103,600
|
||||
278,357
|
||||
930,147
|
||||
229,275
|
||||
48,504
|
||||
229,462
|
||||
547,135
|
||||
1089,467
|
||||
761,492
|
||||
15,274
|
||||
1228,847
|
||||
383,423
|
||||
609,795
|
||||
880,568
|
||||
811,250
|
||||
888,399
|
||||
927,59
|
||||
1139,597
|
||||
192,518
|
||||
977,887
|
||||
483,404
|
||||
1037,504
|
||||
1253,229
|
||||
448,101
|
||||
522,380
|
||||
545,728
|
||||
95,340
|
||||
864,266
|
||||
1292,808
|
||||
142,676
|
||||
1215,843
|
||||
401,708
|
||||
880,331
|
||||
162,886
|
||||
967,422
|
||||
1175,497
|
||||
157,533
|
||||
1295,274
|
||||
48,56
|
||||
547,813
|
||||
898,539
|
||||
1126,443
|
||||
932,458
|
||||
1059,619
|
||||
184,539
|
||||
547,387
|
||||
274,411
|
||||
925,178
|
||||
484,317
|
||||
589,320
|
||||
589,23
|
||||
915,105
|
||||
1171,794
|
||||
459,684
|
||||
1245,890
|
||||
217,618
|
||||
828,15
|
||||
57,5
|
||||
469,546
|
||||
967,696
|
||||
674,533
|
||||
475,395
|
||||
361,561
|
||||
165,567
|
||||
699,33
|
||||
676,4
|
||||
761,268
|
||||
863,257
|
||||
200,75
|
||||
396,217
|
||||
470,193
|
||||
929,418
|
||||
124,345
|
||||
162,585
|
||||
60,639
|
||||
376,728
|
||||
43,145
|
||||
37,425
|
||||
751,106
|
||||
318,767
|
||||
570,243
|
||||
656,129
|
||||
508,0
|
||||
528,24
|
||||
80,819
|
||||
555,471
|
||||
1036,383
|
||||
1027,705
|
||||
599,141
|
||||
195,210
|
||||
157,361
|
||||
586,105
|
||||
364,707
|
||||
1305,757
|
||||
1072,348
|
||||
711,305
|
||||
959,91
|
||||
381,674
|
||||
1015,679
|
||||
311,198
|
||||
222,605
|
||||
528,870
|
||||
1180,602
|
||||
1165,740
|
||||
499,834
|
||||
229,242
|
||||
1037,838
|
||||
1118,824
|
||||
1064,684
|
||||
679,133
|
||||
1285,744
|
||||
192,376
|
||||
196,70
|
||||
710,500
|
||||
1006,101
|
||||
1131,472
|
||||
632,78
|
||||
1119,808
|
||||
902,371
|
||||
691,347
|
||||
159,5
|
||||
378,436
|
||||
594,31
|
||||
758,568
|
||||
962,679
|
||||
257,105
|
||||
425,652
|
||||
328,465
|
||||
1020,635
|
||||
433,649
|
||||
1121,658
|
||||
1071,82
|
||||
1093,56
|
||||
755,471
|
||||
761,21
|
||||
93,609
|
||||
179,646
|
||||
100,585
|
||||
295,231
|
||||
1283,91
|
||||
1173,431
|
||||
557,652
|
||||
396,341
|
||||
992,319
|
||||
320,308
|
||||
1146,231
|
||||
216,600
|
||||
1258,635
|
||||
700,360
|
||||
94,341
|
||||
913,789
|
||||
1068,91
|
||||
1250,639
|
||||
502,232
|
||||
1115,658
|
||||
102,98
|
||||
1203,507
|
||||
1191,565
|
||||
401,260
|
||||
599,453
|
||||
602,147
|
||||
60,679
|
||||
706,169
|
||||
114,854
|
||||
1141,680
|
||||
360,831
|
||||
738,505
|
||||
1086,80
|
||||
1170,700
|
||||
946,707
|
||||
1064,7
|
||||
126,422
|
||||
1004,890
|
||||
544,607
|
||||
1170,526
|
||||
801,824
|
||||
117,267
|
||||
1267,189
|
||||
928,894
|
||||
701,795
|
||||
865,267
|
||||
274,467
|
||||
31,719
|
||||
43,705
|
||||
396,553
|
||||
484,630
|
||||
758,684
|
||||
107,456
|
||||
542,501
|
||||
365,201
|
||||
572,837
|
||||
144,137
|
||||
333,7
|
||||
77,229
|
||||
1243,105
|
||||
1165,824
|
||||
194,414
|
||||
333,455
|
||||
172,431
|
||||
1086,774
|
||||
765,497
|
||||
1128,86
|
||||
328,299
|
||||
892,318
|
||||
504,768
|
||||
545,892
|
||||
157,757
|
||||
565,74
|
||||
753,59
|
||||
773,267
|
||||
1215,51
|
||||
383,59
|
||||
710,112
|
||||
1235,143
|
||||
895,79
|
||||
1104,316
|
||||
31,175
|
||||
517,611
|
||||
1203,387
|
||||
544,635
|
||||
872,887
|
||||
1201,28
|
||||
1037,390
|
||||
460,190
|
||||
835,248
|
||||
438,691
|
||||
677,348
|
||||
277,208
|
||||
1056,542
|
||||
765,688
|
||||
985,455
|
||||
340,105
|
||||
1039,507
|
||||
1019,347
|
||||
703,88
|
||||
88,586
|
||||
589,275
|
||||
639,759
|
||||
1051,50
|
||||
1121,684
|
||||
23,735
|
||||
52,483
|
||||
1125,12
|
||||
492,585
|
||||
840,539
|
||||
|
||||
fold along x=655
|
||||
fold along y=447
|
||||
fold along x=327
|
||||
fold along y=223
|
||||
fold along x=163
|
||||
fold along y=111
|
||||
fold along x=81
|
||||
fold along y=55
|
||||
fold along x=40
|
||||
fold along y=27
|
||||
fold along y=13
|
||||
fold along y=6
|
Binary file not shown.
Loading…
Reference in New Issue