rename repo, subdir for yearly challenges
This commit is contained in:
1727
2020/day20/INPUT.txt
Normal file
1727
2020/day20/INPUT.txt
Normal file
File diff suppressed because it is too large
Load Diff
30
2020/day20/Makefile
Normal file
30
2020/day20/Makefile
Normal file
@@ -0,0 +1,30 @@
|
||||
INPUT := INPUT.txt
|
||||
SHELL := /bin/bash
|
||||
CFLAGS := -w -g
|
||||
#CFLAGS := -w -g -pg
|
||||
#CFLAGS := -w -O3
|
||||
TIME := \time -f "\ttime: %E real, %U user, %S sys\n\tcontext-switch:\t%c+%w, page-faults: %F+%R\n"
|
||||
export PATH := .:$(PATH)
|
||||
|
||||
.PHONY: clean all compile deploy ex1 ex2
|
||||
|
||||
all: ex1 ex2
|
||||
|
||||
output:
|
||||
@$(MAKE) --no-print-directory all 2>&1 > OUTPUT
|
||||
|
||||
compile: ex1-c ex2-c
|
||||
|
||||
ex1:
|
||||
@$(TIME) ex1.bash < $(INPUT) 2>&1
|
||||
@#$(TIME) ex1-c 2020 < $(INPUT) 2>&1
|
||||
|
||||
ex2:
|
||||
@#$(TIME) ex2.bash < $(INPUT) 2>&1
|
||||
@#$(TIME) ex1-c 30000000 < $(INPUT) 2>&1
|
||||
|
||||
clean:
|
||||
@rm -f ex1-c ex2-c core
|
||||
|
||||
deploy:
|
||||
@$(MAKE) -C .. deploy
|
274
2020/day20/README
Normal file
274
2020/day20/README
Normal file
@@ -0,0 +1,274 @@
|
||||
--- Day 20: Jurassic Jigsaw ---
|
||||
|
||||
The high-speed train leaves the forest and quickly carries you south. You can even see a desert in the distance! Since you have some spare time, you might as well see if there was anything interesting in the image the Mythical Information Bureau satellite captured.
|
||||
|
||||
After decoding the satellite messages, you discover that the data actually contains many small images created by the satellite's camera array. The camera array consists of many cameras; rather than produce a single square image, they produce many smaller square image tiles that need to be reassembled back into a single image.
|
||||
|
||||
Each camera in the camera array returns a single monochrome image tile with a random unique ID number. The tiles (your puzzle input) arrived in a random order.
|
||||
|
||||
Worse yet, the camera array appears to be malfunctioning: each image tile has been rotated and flipped to a random orientation. Your first task is to reassemble the original image by orienting the tiles so they fit together.
|
||||
|
||||
To show how the tiles should be reassembled, each tile's image data includes a border that should line up exactly with its adjacent tiles. All tiles have this border, and the border lines up exactly when the tiles are both oriented correctly. Tiles at the edge of the image also have this border, but the outermost edges won't line up with any other tiles.
|
||||
|
||||
For example, suppose you have the following nine tiles:
|
||||
|
||||
Tile 2311:
|
||||
..##.#..#.
|
||||
##..#.....
|
||||
#...##..#.
|
||||
####.#...#
|
||||
##.##.###.
|
||||
##...#.###
|
||||
.#.#.#..##
|
||||
..#....#..
|
||||
###...#.#.
|
||||
..###..###
|
||||
|
||||
Tile 1951:
|
||||
#.##...##.
|
||||
#.####...#
|
||||
.....#..##
|
||||
#...######
|
||||
.##.#....#
|
||||
.###.#####
|
||||
###.##.##.
|
||||
.###....#.
|
||||
..#.#..#.#
|
||||
#...##.#..
|
||||
|
||||
Tile 1171:
|
||||
####...##.
|
||||
#..##.#..#
|
||||
##.#..#.#.
|
||||
.###.####.
|
||||
..###.####
|
||||
.##....##.
|
||||
.#...####.
|
||||
#.##.####.
|
||||
####..#...
|
||||
.....##...
|
||||
|
||||
Tile 1427:
|
||||
###.##.#..
|
||||
.#..#.##..
|
||||
.#.##.#..#
|
||||
#.#.#.##.#
|
||||
....#...##
|
||||
...##..##.
|
||||
...#.#####
|
||||
.#.####.#.
|
||||
..#..###.#
|
||||
..##.#..#.
|
||||
|
||||
Tile 1489:
|
||||
##.#.#....
|
||||
..##...#..
|
||||
.##..##...
|
||||
..#...#...
|
||||
#####...#.
|
||||
#..#.#.#.#
|
||||
...#.#.#..
|
||||
##.#...##.
|
||||
..##.##.##
|
||||
###.##.#..
|
||||
|
||||
Tile 2473:
|
||||
#....####.
|
||||
#..#.##...
|
||||
#.##..#...
|
||||
######.#.#
|
||||
.#...#.#.#
|
||||
.#########
|
||||
.###.#..#.
|
||||
########.#
|
||||
##...##.#.
|
||||
..###.#.#.
|
||||
|
||||
Tile 2971:
|
||||
..#.#....#
|
||||
#...###...
|
||||
#.#.###...
|
||||
##.##..#..
|
||||
.#####..##
|
||||
.#..####.#
|
||||
#..#.#..#.
|
||||
..####.###
|
||||
..#.#.###.
|
||||
...#.#.#.#
|
||||
|
||||
Tile 2729:
|
||||
...#.#.#.#
|
||||
####.#....
|
||||
..#.#.....
|
||||
....#..#.#
|
||||
.##..##.#.
|
||||
.#.####...
|
||||
####.#.#..
|
||||
##.####...
|
||||
##..#.##..
|
||||
#.##...##.
|
||||
|
||||
Tile 3079:
|
||||
#.#.#####.
|
||||
.#..######
|
||||
..#.......
|
||||
######....
|
||||
####.#..#.
|
||||
.#...#.##.
|
||||
#.#####.##
|
||||
..#.###...
|
||||
..#.......
|
||||
..#.###...
|
||||
|
||||
By rotating, flipping, and rearranging them, you can find a square arrangement that causes all adjacent borders to line up:
|
||||
|
||||
#...##.#.. ..###..### #.#.#####.
|
||||
..#.#..#.# ###...#.#. .#..######
|
||||
.###....#. ..#....#.. ..#.......
|
||||
###.##.##. .#.#.#..## ######....
|
||||
.###.##### ##...#.### ####.#..#.
|
||||
.##.#....# ##.##.###. .#...#.##.
|
||||
#...###### ####.#...# #.#####.##
|
||||
.....#..## #...##..#. ..#.###...
|
||||
#.####...# ##..#..... ..#.......
|
||||
#.##...##. ..##.#..#. ..#.###...
|
||||
|
||||
#.##...##. ..##.#..#. ..#.###...
|
||||
##..#.##.. ..#..###.# ##.##....#
|
||||
##.####... .#.####.#. ..#.###..#
|
||||
####.#.#.. ...#.##### ###.#..###
|
||||
.#.####... ...##..##. .######.##
|
||||
.##..##.#. ....#...## #.#.#.#...
|
||||
....#..#.# #.#.#.##.# #.###.###.
|
||||
..#.#..... .#.##.#..# #.###.##..
|
||||
####.#.... .#..#.##.. .######...
|
||||
...#.#.#.# ###.##.#.. .##...####
|
||||
|
||||
...#.#.#.# ###.##.#.. .##...####
|
||||
..#.#.###. ..##.##.## #..#.##..#
|
||||
..####.### ##.#...##. .#.#..#.##
|
||||
#..#.#..#. ...#.#.#.. .####.###.
|
||||
.#..####.# #..#.#.#.# ####.###..
|
||||
.#####..## #####...#. .##....##.
|
||||
##.##..#.. ..#...#... .####...#.
|
||||
#.#.###... .##..##... .####.##.#
|
||||
#...###... ..##...#.. ...#..####
|
||||
..#.#....# ##.#.#.... ...##.....
|
||||
|
||||
For reference, the IDs of the above tiles are:
|
||||
|
||||
1951 2311 3079
|
||||
2729 1427 2473
|
||||
2971 1489 1171
|
||||
|
||||
To check that you've assembled the image correctly, multiply the IDs of the four corner tiles together. If you do this with the assembled tiles from the example above, you get 1951 * 3079 * 2971 * 1171 = 20899048083289.
|
||||
|
||||
Assemble the tiles into an image. What do you get if you multiply together the IDs of the four corner tiles?
|
||||
|
||||
Your puzzle answer was 5966506063747.
|
||||
|
||||
The first half of this puzzle is complete! It provides one gold star: *
|
||||
--- Part Two ---
|
||||
|
||||
Now, you're ready to check the image for sea monsters.
|
||||
|
||||
The borders of each tile are not part of the actual image; start by removing them.
|
||||
|
||||
In the example above, the tiles become:
|
||||
|
||||
.#.#..#. ##...#.# #..#####
|
||||
###....# .#....#. .#......
|
||||
##.##.## #.#.#..# #####...
|
||||
###.#### #...#.## ###.#..#
|
||||
##.#.... #.##.### #...#.##
|
||||
...##### ###.#... .#####.#
|
||||
....#..# ...##..# .#.###..
|
||||
.####... #..#.... .#......
|
||||
|
||||
#..#.##. .#..###. #.##....
|
||||
#.####.. #.####.# .#.###..
|
||||
###.#.#. ..#.#### ##.#..##
|
||||
#.####.. ..##..## ######.#
|
||||
##..##.# ...#...# .#.#.#..
|
||||
...#..#. .#.#.##. .###.###
|
||||
.#.#.... #.##.#.. .###.##.
|
||||
###.#... #..#.##. ######..
|
||||
|
||||
.#.#.### .##.##.# ..#.##..
|
||||
.####.## #.#...## #.#..#.#
|
||||
..#.#..# ..#.#.#. ####.###
|
||||
#..####. ..#.#.#. ###.###.
|
||||
#####..# ####...# ##....##
|
||||
#.##..#. .#...#.. ####...#
|
||||
.#.###.. ##..##.. ####.##.
|
||||
...###.. .##...#. ..#..###
|
||||
|
||||
Remove the gaps to form the actual image:
|
||||
|
||||
.#.#..#.##...#.##..#####
|
||||
###....#.#....#..#......
|
||||
##.##.###.#.#..######...
|
||||
###.#####...#.#####.#..#
|
||||
##.#....#.##.####...#.##
|
||||
...########.#....#####.#
|
||||
....#..#...##..#.#.###..
|
||||
.####...#..#.....#......
|
||||
#..#.##..#..###.#.##....
|
||||
#.####..#.####.#.#.###..
|
||||
###.#.#...#.######.#..##
|
||||
#.####....##..########.#
|
||||
##..##.#...#...#.#.#.#..
|
||||
...#..#..#.#.##..###.###
|
||||
.#.#....#.##.#...###.##.
|
||||
###.#...#..#.##.######..
|
||||
.#.#.###.##.##.#..#.##..
|
||||
.####.###.#...###.#..#.#
|
||||
..#.#..#..#.#.#.####.###
|
||||
#..####...#.#.#.###.###.
|
||||
#####..#####...###....##
|
||||
#.##..#..#...#..####...#
|
||||
.#.###..##..##..####.##.
|
||||
...###...##...#...#..###
|
||||
|
||||
Now, you're ready to search for sea monsters! Because your image is monochrome, a sea monster will look like this:
|
||||
|
||||
#
|
||||
# ## ## ###
|
||||
# # # # # #
|
||||
|
||||
When looking for this pattern in the image, the spaces can be anything; only the # need to match. Also, you might need to rotate or flip your image before it's oriented correctly to find sea monsters. In the above image, after flipping and rotating it to the appropriate orientation, there are two sea monsters (marked with O):
|
||||
|
||||
.####...#####..#...###..
|
||||
#####..#..#.#.####..#.#.
|
||||
.#.#...#.###...#.##.O#..
|
||||
#.O.##.OO#.#.OO.##.OOO##
|
||||
..#O.#O#.O##O..O.#O##.##
|
||||
...#.#..##.##...#..#..##
|
||||
#.##.#..#.#..#..##.#.#..
|
||||
.###.##.....#...###.#...
|
||||
#.####.#.#....##.#..#.#.
|
||||
##...#..#....#..#...####
|
||||
..#.##...###..#.#####..#
|
||||
....#.##.#.#####....#...
|
||||
..##.##.###.....#.##..#.
|
||||
#...#...###..####....##.
|
||||
.#.##...#.##.#.#.###...#
|
||||
#.###.#..####...##..#...
|
||||
#.###...#.##...#.##O###.
|
||||
.O##.#OO.###OO##..OOO##.
|
||||
..O#.O..O..O.#O##O##.###
|
||||
#.#..##.########..#..##.
|
||||
#.#####..#.#...##..#....
|
||||
#....##..#.#########..##
|
||||
#...#.....#..##...###.##
|
||||
#..###....##.#...##.##.#
|
||||
|
||||
Determine how rough the waters are in the sea monsters' habitat by counting the number of # that are not part of a sea monster. In the above example, the habitat's water roughness is 273.
|
||||
|
||||
How many # are not part of a sea monster?
|
||||
|
||||
Answer:
|
||||
|
||||
Although it hasn't changed, you can still get your puzzle input.
|
||||
|
||||
You can also [Share] this puzzle.
|
107
2020/day20/TEST.txt
Normal file
107
2020/day20/TEST.txt
Normal file
@@ -0,0 +1,107 @@
|
||||
Tile 2311:
|
||||
..##.#..#.
|
||||
##..#.....
|
||||
#...##..#.
|
||||
####.#...#
|
||||
##.##.###.
|
||||
##...#.###
|
||||
.#.#.#..##
|
||||
..#....#..
|
||||
###...#.#.
|
||||
..###..###
|
||||
|
||||
Tile 1951:
|
||||
#.##...##.
|
||||
#.####...#
|
||||
.....#..##
|
||||
#...######
|
||||
.##.#....#
|
||||
.###.#####
|
||||
###.##.##.
|
||||
.###....#.
|
||||
..#.#..#.#
|
||||
#...##.#..
|
||||
|
||||
Tile 1171:
|
||||
####...##.
|
||||
#..##.#..#
|
||||
##.#..#.#.
|
||||
.###.####.
|
||||
..###.####
|
||||
.##....##.
|
||||
.#...####.
|
||||
#.##.####.
|
||||
####..#...
|
||||
.....##...
|
||||
|
||||
Tile 1427:
|
||||
###.##.#..
|
||||
.#..#.##..
|
||||
.#.##.#..#
|
||||
#.#.#.##.#
|
||||
....#...##
|
||||
...##..##.
|
||||
...#.#####
|
||||
.#.####.#.
|
||||
..#..###.#
|
||||
..##.#..#.
|
||||
|
||||
Tile 1489:
|
||||
##.#.#....
|
||||
..##...#..
|
||||
.##..##...
|
||||
..#...#...
|
||||
#####...#.
|
||||
#..#.#.#.#
|
||||
...#.#.#..
|
||||
##.#...##.
|
||||
..##.##.##
|
||||
###.##.#..
|
||||
|
||||
Tile 2473:
|
||||
#....####.
|
||||
#..#.##...
|
||||
#.##..#...
|
||||
######.#.#
|
||||
.#...#.#.#
|
||||
.#########
|
||||
.###.#..#.
|
||||
########.#
|
||||
##...##.#.
|
||||
..###.#.#.
|
||||
|
||||
Tile 2971:
|
||||
..#.#....#
|
||||
#...###...
|
||||
#.#.###...
|
||||
##.##..#..
|
||||
.#####..##
|
||||
.#..####.#
|
||||
#..#.#..#.
|
||||
..####.###
|
||||
..#.#.###.
|
||||
...#.#.#.#
|
||||
|
||||
Tile 2729:
|
||||
...#.#.#.#
|
||||
####.#....
|
||||
..#.#.....
|
||||
....#..#.#
|
||||
.##..##.#.
|
||||
.#.####...
|
||||
####.#.#..
|
||||
##.####...
|
||||
##..#.##..
|
||||
#.##...##.
|
||||
|
||||
Tile 3079:
|
||||
#.#.#####.
|
||||
.#..######
|
||||
..#.......
|
||||
######....
|
||||
####.#..#.
|
||||
.#...#.##.
|
||||
#.#####.##
|
||||
..#.###...
|
||||
..#.......
|
||||
..#.###...
|
73
2020/day20/ex1.bash
Normal file
73
2020/day20/ex1.bash
Normal file
@@ -0,0 +1,73 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ex1.bash: Advent2020 game, day 20/game 1.
|
||||
|
||||
CMD=${0##*/}
|
||||
set -o noglob
|
||||
shopt -s extglob
|
||||
|
||||
#declare -A strings
|
||||
declare -a strings T R B L RT RR RB RL nums
|
||||
|
||||
declare -i count=-1
|
||||
while read -r line; do
|
||||
case ${line:0:1} in
|
||||
T*)
|
||||
((count++))
|
||||
num=${line##* }
|
||||
num=${num%%:}
|
||||
nums+=("$num")
|
||||
;;
|
||||
\#|.)
|
||||
strings[$count]="${strings[$count]} $line"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
((count--))
|
||||
|
||||
for key in "${!nums[@]}"; do
|
||||
# shellcheck disable=SC2206
|
||||
str=(${strings[$key]})
|
||||
top="${str[0]}"
|
||||
bottom="${str[9]}"
|
||||
T+=("$top")
|
||||
B+=("$bottom")
|
||||
# find out right and bottom
|
||||
unset left right
|
||||
for ((i=0; i<10; ++i)); do
|
||||
left+=${str[$i]:0:1}
|
||||
right+=${str[$i]: -1:1}
|
||||
done
|
||||
R+=("$right")
|
||||
L+=("$left")
|
||||
unset fliptop flipbottom flipleft flipright
|
||||
for ((i=9; i>=0; --i)); do
|
||||
fliptop+=${top:$i:1}
|
||||
flipbottom+=${bottom:$i:1}
|
||||
flipleft+=${left:$i:1}
|
||||
flipright+=${right:$i:1}
|
||||
done
|
||||
RT+=("$fliptop")
|
||||
RR+=("$flipright")
|
||||
RB+=("$flipbottom")
|
||||
RL+=("$flipleft")
|
||||
|
||||
done
|
||||
|
||||
ALL=("${T[@]}" "${R[@]}" "${B[@]}" "${L[@]}" "${RT[@]}" "${RR[@]}" "${RB[@]}" "${RL[@]}")
|
||||
declare -i res=1 count
|
||||
for ((i=0; i<${#nums[@]}; ++i)); do
|
||||
count=0
|
||||
|
||||
for t in ${T[$i]} ${R[$i]} ${B[$i]} ${L[$i]}; do
|
||||
for s in "${ALL[@]}"; do
|
||||
[[ $t == "$s" ]] && ((count++))
|
||||
done
|
||||
done
|
||||
|
||||
((count ==6)) && ((res*=${nums[$i]}))
|
||||
done
|
||||
|
||||
printf "%s : res=%d\n" "$CMD" "$res"
|
||||
|
||||
exit 0
|
Reference in New Issue
Block a user