Removed all puzzle descriptions, replaced by a link. Not deleting history though: People who want to get the descriptions will do so anyhow.
This commit is contained in:
parent
0876e5c92c
commit
8cdfdda1f4
@ -5,6 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
${description}
|
||||
${weblink}
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -5,22 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 1: Not Quite Lisp ---
|
||||
Santa was hoping for a white Christmas, but his weather machine's "snow" function is powered by stars, and he's fresh out! To save Christmas, he needs you to collect fifty stars by December 25th.
|
||||
Collect stars by helping Santa solve puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
|
||||
Here's an easy puzzle to warm you up.
|
||||
Santa is trying to deliver presents in a large apartment building, but he can't find the right floor - the directions he got are a little confusing. He starts on the ground floor (floor 0) and then follows the instructions one character at a time.
|
||||
An opening parenthesis, (, means he should go up one floor, and a closing parenthesis, ), means he should go down one floor.
|
||||
The apartment building is very tall, and the basement is very deep; he will never find the top or bottom floors.
|
||||
For example:
|
||||
|
||||
(()) and ()() both result in floor 0.
|
||||
((( and (()(()( both result in floor 3.
|
||||
))((((( also results in floor 3.
|
||||
()) and ))( both result in floor -1 (the first basement level).
|
||||
))) and )())()) both result in floor -3.
|
||||
|
||||
To what floor do the instructions take Santa?
|
||||
|
||||
https://adventofcode.com/2015/day/1
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -5,15 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 2: I Was Told There Would Be No Math ---
|
||||
The elves are running low on wrapping paper, and so they need to submit an order for more. They have a list of the dimensions (length l, width w, and height h) of each present, and only want to order exactly as much as they need.
|
||||
Fortunately, every present is a box (a perfect right rectangular prism), which makes calculating the required wrapping paper for each gift a little easier: find the surface area of the box, which is 2*l*w + 2*w*h + 2*h*l. The elves also need a little extra paper for each present: the area of the smallest side.
|
||||
For example:
|
||||
|
||||
A present with dimensions 2x3x4 requires 2*6 + 2*12 + 2*8 = 52 square feet of wrapping paper plus 6 square feet of slack, for a total of 58 square feet.
|
||||
A present with dimensions 1x1x10 requires 2*1 + 2*10 + 2*10 = 42 square feet of wrapping paper plus 1 square foot of slack, for a total of 43 square feet.
|
||||
|
||||
All numbers in the elves' list are in feet. How many total square feet of wrapping paper should they order?
|
||||
|
||||
https://adventofcode.com/2015/day/2
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -6,16 +6,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 3: Perfectly Spherical Houses in a Vacuum ---
|
||||
Santa is delivering presents to an infinite two-dimensional grid of houses.
|
||||
He begins by delivering a present to the house at his starting location, and then an elf at the North Pole calls him via radio and tells him where to move next. Moves are always exactly one house to the north (^), south (v), east (>), or west (<). After each move, he delivers another present to the house at his new location.
|
||||
However, the elf back at the north pole has had a little too much eggnog, and so his directions are a little off, and Santa ends up visiting some houses more than once. How many houses receive at least one present?
|
||||
For example:
|
||||
|
||||
> delivers presents to 2 houses: one at the starting location, and one to the east.
|
||||
^>v< delivers presents to 4 houses in a square, including twice to the house at his starting/ending location.
|
||||
^v^v^v^v^v delivers a bunch of presents to some very lucky children at only 2 houses.
|
||||
|
||||
|
||||
https://adventofcode.com/2015/day/3
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -6,14 +6,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 4: The Ideal Stocking Stuffer ---
|
||||
Santa needs help mining some AdventCoins (very similar to bitcoins) to use as gifts for all the economically forward-thinking little girls and boys.
|
||||
To do this, he needs to find MD5 hashes which, in hexadecimal, start with at least five zeroes. The input to the MD5 hash is some secret key (your puzzle input, given below) followed by a number in decimal. To mine AdventCoins, you must find Santa the lowest positive number (no leading zeroes: 1, 2, 3, ...) that produces such a hash.
|
||||
For example:
|
||||
|
||||
If your secret key is abcdef, the answer is 609043, because the MD5 hash of abcdef609043 starts with five zeroes (000001dbbfa...), and it is the lowest such number to do so.
|
||||
If your secret key is pqrstuv, the lowest number it combines with to make an MD5 hash starting with five zeroes is 1048970; that is, the MD5 hash of pqrstuv1048970 looks like 000006136ef....
|
||||
|
||||
|
||||
https://adventofcode.com/2015/day/4
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -5,23 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 5: Doesn't He Have Intern-Elves For This? ---
|
||||
Santa needs help figuring out which strings in his text file are naughty or nice.
|
||||
A nice string is one with all of the following properties:
|
||||
|
||||
It contains at least three vowels (aeiou only), like aei, xazegov, or aeiouaeiouaeiou.
|
||||
It contains at least one letter that appears twice in a row, like xx, abcdde (dd), or aabbccdd (aa, bb, cc, or dd).
|
||||
It does not contain the strings ab, cd, pq, or xy, even if they are part of one of the other requirements.
|
||||
|
||||
For example:
|
||||
|
||||
ugknbfddgicrmopn is nice because it has at least three vowels (u...i...o...), a double letter (...dd...), and none of the disallowed substrings.
|
||||
aaa is nice because it has at least three vowels and a double letter, even though the letters used by different rules overlap.
|
||||
jchzalrnumimnmhp is naughty because it has no double letter.
|
||||
haegwjzuvuyypxyu is naughty because it contains the string xy.
|
||||
dvszwmarrgswjxmb is naughty because it contains only one vowel.
|
||||
|
||||
How many strings are nice?
|
||||
|
||||
https://adventofcode.com/2015/day/5
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -6,43 +6,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 1: Calorie Counting ---
|
||||
Santa's reindeer typically eat regular reindeer food, but they need a lot of magical energy to deliver presents on Christmas. For that, their favorite snack is a special type of star fruit that only grows deep in the jungle. The Elves have brought you on their annual expedition to the grove where the fruit grows.
|
||||
To supply enough magical energy, the expedition needs to retrieve a minimum of fifty stars by December 25th. Although the Elves assure you that the grove has plenty of fruit, you decide to grab any fruit you see along the way, just in case.
|
||||
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
|
||||
The jungle must be too overgrown and difficult to navigate in vehicles or access from the air; the Elves' expedition traditionally goes on foot. As your boats approach land, the Elves begin taking inventory of their supplies. One important consideration is food - in particular, the number of Calories each Elf is carrying (your puzzle input).
|
||||
The Elves take turns writing down the number of Calories contained by the various meals, snacks, rations, etc. that they've brought with them, one item per line. Each Elf separates their own inventory from the previous Elf's inventory (if any) by a blank line.
|
||||
For example, suppose the Elves finish writing their items' Calories and end up with the following list:
|
||||
1000
|
||||
2000
|
||||
3000
|
||||
|
||||
4000
|
||||
|
||||
5000
|
||||
6000
|
||||
|
||||
7000
|
||||
8000
|
||||
9000
|
||||
|
||||
10000
|
||||
|
||||
This list represents the Calories of the food carried by five Elves:
|
||||
|
||||
The first Elf is carrying food with 1000, 2000, and 3000 Calories, a total of 6000 Calories.
|
||||
The second Elf is carrying one food item with 4000 Calories.
|
||||
The third Elf is carrying food with 5000 and 6000 Calories, a total of 11000 Calories.
|
||||
The fourth Elf is carrying food with 7000, 8000, and 9000 Calories, a total of 24000 Calories.
|
||||
The fifth Elf is carrying one food item with 10000 Calories.
|
||||
|
||||
In case the Elves get hungry and need extra snacks, they need to know which Elf to ask: they'd like to know how many Calories are being carried by the Elf carrying the most Calories. In the example above, this is 24000 (carried by the fourth Elf).
|
||||
Find the Elf carrying the most Calories. How many total Calories is that Elf carrying?
|
||||
--- Part Two ---
|
||||
By the time you calculate the answer to the Elves' question, they've already realized that the Elf carrying the most Calories of food might eventually run out of snacks.
|
||||
To avoid this unacceptable situation, the Elves would instead like to know the total Calories carried by the top three Elves carrying the most Calories. That way, even if one of those Elves runs out of snacks, they still have two backups.
|
||||
In the example above, the top three Elves are the fourth Elf (with 24000 Calories), then the third Elf (with 11000 Calories), then the fifth Elf (with 10000 Calories). The sum of the Calories carried by these three elves is 45000.
|
||||
Find the top three Elves carrying the most Calories. How many Calories are those Elves carrying in total?
|
||||
|
||||
https://adventofcode.com/2022/day/1
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -5,36 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 2: Rock Paper Scissors ---
|
||||
The Elves begin to set up camp on the beach. To decide whose tent gets to be closest to the snack storage, a giant Rock Paper Scissors tournament is already in progress.
|
||||
Rock Paper Scissors is a game between two players. Each game contains many rounds; in each round, the players each simultaneously choose one of Rock, Paper, or Scissors using a hand shape. Then, a winner for that round is selected: Rock defeats Scissors, Scissors defeats Paper, and Paper defeats Rock. If both players choose the same shape, the round instead ends in a draw.
|
||||
Appreciative of your help yesterday, one Elf gives you an encrypted strategy guide (your puzzle input) that they say will be sure to help you win. "The first column is what your opponent is going to play: A for Rock, B for Paper, and C for Scissors. The second column--" Suddenly, the Elf is called away to help with someone's tent.
|
||||
The second column, you reason, must be what you should play in response: X for Rock, Y for Paper, and Z for Scissors. Winning every time would be suspicious, so the responses must have been carefully chosen.
|
||||
The winner of the whole tournament is the player with the highest score. Your total score is the sum of your scores for each round. The score for a single round is the score for the shape you selected (1 for Rock, 2 for Paper, and 3 for Scissors) plus the score for the outcome of the round (0 if you lost, 3 if the round was a draw, and 6 if you won).
|
||||
Since you can't be sure if the Elf is trying to help you or trick you, you should calculate the score you would get if you were to follow the strategy guide.
|
||||
For example, suppose you were given the following strategy guide:
|
||||
A Y
|
||||
B X
|
||||
C Z
|
||||
|
||||
This strategy guide predicts and recommends the following:
|
||||
|
||||
In the first round, your opponent will choose Rock (A), and you should choose Paper (Y). This ends in a win for you with a score of 8 (2 because you chose Paper + 6 because you won).
|
||||
In the second round, your opponent will choose Paper (B), and you should choose Rock (X). This ends in a loss for you with a score of 1 (1 + 0).
|
||||
The third round is a draw with both players choosing Scissors, giving you a score of 3 + 3 = 6.
|
||||
|
||||
In this example, if you were to follow the strategy guide, you would get a total score of 15 (8 + 1 + 6).
|
||||
What would your total score be if everything goes exactly according to your strategy guide?
|
||||
--- Part Two ---
|
||||
The Elf finishes helping with the tent and sneaks back over to you. "Anyway, the second column says how the round needs to end: X means you need to lose, Y means you need to end the round in a draw, and Z means you need to win. Good luck!"
|
||||
The total score is still calculated in the same way, but now you need to figure out what shape to choose so the round ends as indicated. The example above now goes like this:
|
||||
|
||||
In the first round, your opponent will choose Rock (A), and you need the round to end in a draw (Y), so you also choose Rock. This gives you a score of 1 + 3 = 4.
|
||||
In the second round, your opponent will choose Paper (B), and you choose Rock so you lose (X) with a score of 1 + 0 = 1.
|
||||
In the third round, you will defeat your opponent's Scissors with Rock for a score of 1 + 6 = 7.
|
||||
|
||||
Now that you're correctly decrypting the ultra top secret strategy guide, you would get a total score of 12.
|
||||
Following the Elf's instructions for the second column, what would your total score be if everything goes exactly according to your strategy guide?
|
||||
|
||||
https://adventofcode.com/2022/day/2
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -5,52 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 3: Rucksack Reorganization ---
|
||||
One Elf has the important job of loading all of the rucksacks with supplies for the jungle journey. Unfortunately, that Elf didn't quite follow the packing instructions, and so a few items now need to be rearranged.
|
||||
Each rucksack has two large compartments. All items of a given type are meant to go into exactly one of the two compartments. The Elf that did the packing failed to follow this rule for exactly one item type per rucksack.
|
||||
The Elves have made a list of all of the items currently in each rucksack (your puzzle input), but they need your help finding the errors. Every item type is identified by a single lowercase or uppercase letter (that is, a and A refer to different types of items).
|
||||
The list of items for each rucksack is given as characters all on a single line. A given rucksack always has the same number of items in each of its two compartments, so the first half of the characters represent items in the first compartment, while the second half of the characters represent items in the second compartment.
|
||||
For example, suppose you have the following list of contents from six rucksacks:
|
||||
vJrwpWtwJgWrhcsFMMfFFhFp
|
||||
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
|
||||
PmmdzqPrVvPwwTWBwg
|
||||
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
|
||||
ttgJtRGJQctTZtZT
|
||||
CrZsJsPPZsGzwwsLwLmpwMDw
|
||||
|
||||
|
||||
The first rucksack contains the items vJrwpWtwJgWrhcsFMMfFFhFp, which means its first compartment contains the items vJrwpWtwJgWr, while the second compartment contains the items hcsFMMfFFhFp. The only item type that appears in both compartments is lowercase p.
|
||||
The second rucksack's compartments contain jqHRNqRjqzjGDLGL and rsFMfFZSrLrFZsSL. The only item type that appears in both compartments is uppercase L.
|
||||
The third rucksack's compartments contain PmmdzqPrV and vPwwTWBwg; the only common item type is uppercase P.
|
||||
The fourth rucksack's compartments only share item type v.
|
||||
The fifth rucksack's compartments only share item type t.
|
||||
The sixth rucksack's compartments only share item type s.
|
||||
|
||||
To help prioritize item rearrangement, every item type can be converted to a priority:
|
||||
|
||||
Lowercase item types a through z have priorities 1 through 26.
|
||||
Uppercase item types A through Z have priorities 27 through 52.
|
||||
|
||||
In the above example, the priority of the item type that appears in both compartments of each rucksack is 16 (p), 38 (L), 42 (P), 22 (v), 20 (t), and 19 (s); the sum of these is 157.
|
||||
Find the item type that appears in both compartments of each rucksack. What is the sum of the priorities of those item types?
|
||||
--- Part Two ---
|
||||
As you finish identifying the misplaced items, the Elves come to you with another issue.
|
||||
For safety, the Elves are divided into groups of three. Every Elf carries a badge that identifies their group. For efficiency, within each group of three Elves, the badge is the only item type carried by all three Elves. That is, if a group's badge is item type B, then all three Elves will have item type B somewhere in their rucksack, and at most two of the Elves will be carrying any other item type.
|
||||
The problem is that someone forgot to put this year's updated authenticity sticker on the badges. All of the badges need to be pulled out of the rucksacks so the new authenticity stickers can be attached.
|
||||
Additionally, nobody wrote down which item type corresponds to each group's badges. The only way to tell which item type is the right one is by finding the one item type that is common between all three Elves in each group.
|
||||
Every set of three lines in your list corresponds to a single group, but each group can have a different badge item type. So, in the above example, the first group's rucksacks are the first three lines:
|
||||
vJrwpWtwJgWrhcsFMMfFFhFp
|
||||
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
|
||||
PmmdzqPrVvPwwTWBwg
|
||||
|
||||
And the second group's rucksacks are the next three lines:
|
||||
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
|
||||
ttgJtRGJQctTZtZT
|
||||
CrZsJsPPZsGzwwsLwLmpwMDw
|
||||
|
||||
In the first group, the only item type that appears in all three rucksacks is lowercase r; this must be their badges. In the second group, their badge item type must be Z.
|
||||
Priorities for these items must still be found to organize the sticker attachment efforts: here, they are 18 (r) for the first group and 52 (Z) for the second group. The sum of these is 70.
|
||||
Find the item type that corresponds to the badges of each three-Elf group. What is the sum of the priorities of those item types?
|
||||
|
||||
https://adventofcode.com/2022/day/3
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -5,55 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 4: Camp Cleanup ---
|
||||
Space needs to be cleared before the last supplies can be unloaded from the ships, and so several Elves have been assigned the job of cleaning up sections of the camp. Every section has a unique ID number, and each Elf is assigned a range of section IDs.
|
||||
However, as some of the Elves compare their section assignments with each other, they've noticed that many of the assignments overlap. To try to quickly find overlaps and reduce duplicated effort, the Elves pair up and make a big list of the section assignments for each pair (your puzzle input).
|
||||
For example, consider the following list of section assignment pairs:
|
||||
2-4,6-8
|
||||
2-3,4-5
|
||||
5-7,7-9
|
||||
2-8,3-7
|
||||
6-6,4-6
|
||||
2-6,4-8
|
||||
|
||||
For the first few pairs, this list means:
|
||||
|
||||
Within the first pair of Elves, the first Elf was assigned sections 2-4 (sections 2, 3, and 4), while the second Elf was assigned sections 6-8 (sections 6, 7, 8).
|
||||
The Elves in the second pair were each assigned two sections.
|
||||
The Elves in the third pair were each assigned three sections: one got sections 5, 6, and 7, while the other also got 7, plus 8 and 9.
|
||||
|
||||
This example list uses single-digit section IDs to make it easier to draw; your actual list might contain larger numbers. Visually, these pairs of section assignments look like this:
|
||||
.234..... 2-4
|
||||
.....678. 6-8
|
||||
|
||||
.23...... 2-3
|
||||
...45.... 4-5
|
||||
|
||||
....567.. 5-7
|
||||
......789 7-9
|
||||
|
||||
.2345678. 2-8
|
||||
..34567.. 3-7
|
||||
|
||||
.....6... 6-6
|
||||
...456... 4-6
|
||||
|
||||
.23456... 2-6
|
||||
...45678. 4-8
|
||||
|
||||
Some of the pairs have noticed that one of their assignments fully contains the other. For example, 2-8 fully contains 3-7, and 6-6 is fully contained by 4-6. In pairs where one assignment fully contains the other, one Elf in the pair would be exclusively cleaning sections their partner will already be cleaning, so these seem like the most in need of reconsideration. In this example, there are 2 such pairs.
|
||||
In how many assignment pairs does one range fully contain the other?
|
||||
--- Part Two ---
|
||||
It seems like there is still quite a bit of duplicate work planned. Instead, the Elves would like to know the number of pairs that overlap at all.
|
||||
In the above example, the first two pairs (2-4,6-8 and 2-3,4-5) don't overlap, while the remaining four pairs (5-7,7-9, 2-8,3-7, 6-6,4-6, and 2-6,4-8) do overlap:
|
||||
|
||||
5-7,7-9 overlaps in a single section, 7.
|
||||
2-8,3-7 overlaps all of the sections 3 through 7.
|
||||
6-6,4-6 overlaps in a single section, 6.
|
||||
2-6,4-8 overlaps in sections 4, 5, and 6.
|
||||
|
||||
So, in this example, the number of overlapping assignment pairs is 4.
|
||||
In how many assignment pairs do the ranges overlap?
|
||||
|
||||
https://adventofcode.com/2022/day/4
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -6,90 +6,7 @@ import splitInts
|
||||
|
||||
/*
|
||||
--- Day 5: Supply Stacks ---
|
||||
The expedition can depart as soon as the final supplies have been unloaded from the ships. Supplies are stored in stacks of marked crates, but because the needed supplies are buried under many other crates, the crates need to be rearranged.
|
||||
The ship has a giant cargo crane capable of moving crates between stacks. To ensure none of the crates get crushed or fall over, the crane operator will rearrange them in a series of carefully-planned steps. After the crates are rearranged, the desired crates will be at the top of each stack.
|
||||
The Elves don't want to interrupt the crane operator during this delicate procedure, but they forgot to ask her which crate will end up where, and they want to be ready to unload them as soon as possible so they can embark.
|
||||
They do, however, have a drawing of the starting stacks of crates and the rearrangement procedure (your puzzle input). For example:
|
||||
[D]
|
||||
[N] [C]
|
||||
[Z] [M] [P]
|
||||
1 2 3
|
||||
|
||||
move 1 from 2 to 1
|
||||
move 3 from 1 to 3
|
||||
move 2 from 2 to 1
|
||||
move 1 from 1 to 2
|
||||
|
||||
In this example, there are three stacks of crates. Stack 1 contains two crates: crate Z is on the bottom, and crate N is on top. Stack 2 contains three crates; from bottom to top, they are crates M, C, and D. Finally, stack 3 contains a single crate, P.
|
||||
Then, the rearrangement procedure is given. In each step of the procedure, a quantity of crates is moved from one stack to a different stack. In the first step of the above rearrangement procedure, one crate is moved from stack 2 to stack 1, resulting in this configuration:
|
||||
[D]
|
||||
[N] [C]
|
||||
[Z] [M] [P]
|
||||
1 2 3
|
||||
|
||||
In the second step, three crates are moved from stack 1 to stack 3. Crates are moved one at a time, so the first crate to be moved (D) ends up below the second and third crates:
|
||||
[Z]
|
||||
[N]
|
||||
[C] [D]
|
||||
[M] [P]
|
||||
1 2 3
|
||||
|
||||
Then, both crates are moved from stack 2 to stack 1. Again, because crates are moved one at a time, crate C ends up below crate M:
|
||||
[Z]
|
||||
[N]
|
||||
[M] [D]
|
||||
[C] [P]
|
||||
1 2 3
|
||||
|
||||
Finally, one crate is moved from stack 1 to stack 2:
|
||||
[Z]
|
||||
[N]
|
||||
[D]
|
||||
[C] [M] [P]
|
||||
1 2 3
|
||||
|
||||
The Elves just need to know which crate will end up on top of each stack; in this example, the top crates are C in stack 1, M in stack 2, and Z in stack 3, so you should combine these together and give the Elves the message CMZ.
|
||||
After the rearrangement procedure completes, what crate ends up on top of each stack?
|
||||
--- Part Two ---
|
||||
As you watch the crane operator expertly rearrange the crates, you notice the process isn't following your prediction.
|
||||
Some mud was covering the writing on the side of the crane, and you quickly wipe it away. The crane isn't a CrateMover 9000 - it's a CrateMover 9001.
|
||||
The CrateMover 9001 is notable for many new and exciting features: air conditioning, leather seats, an extra cup holder, and the ability to pick up and move multiple crates at once.
|
||||
Again considering the example above, the crates begin in the same configuration:
|
||||
[D]
|
||||
[N] [C]
|
||||
[Z] [M] [P]
|
||||
1 2 3
|
||||
|
||||
Moving a single crate from stack 2 to stack 1 behaves the same as before:
|
||||
[D]
|
||||
[N] [C]
|
||||
[Z] [M] [P]
|
||||
1 2 3
|
||||
|
||||
However, the action of moving three crates from stack 1 to stack 3 means that those three moved crates stay in the same order, resulting in this new configuration:
|
||||
[D]
|
||||
[N]
|
||||
[C] [Z]
|
||||
[M] [P]
|
||||
1 2 3
|
||||
|
||||
Next, as both crates are moved from stack 2 to stack 1, they retain their order as well:
|
||||
[D]
|
||||
[N]
|
||||
[C] [Z]
|
||||
[M] [P]
|
||||
1 2 3
|
||||
|
||||
Finally, a single crate is still moved from stack 1 to stack 2, but now it's crate C that gets moved:
|
||||
[D]
|
||||
[N]
|
||||
[Z]
|
||||
[M] [C] [P]
|
||||
1 2 3
|
||||
|
||||
In this example, the CrateMover 9001 has put the crates in a totally different order: MCD.
|
||||
Before the rearrangement process finishes, update your simulation so that the Elves know where they should stand to be ready to unload the final supplies. After the rearrangement procedure completes, what crate ends up on top of each stack?
|
||||
|
||||
https://adventofcode.com/2022/day/5
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -5,40 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 6: Tuning Trouble ---
|
||||
The preparations are finally complete; you and the Elves leave camp on foot and begin to make your way toward the star fruit grove.
|
||||
As you move through the dense undergrowth, one of the Elves gives you a handheld device. He says that it has many fancy features, but the most important one to set up right now is the communication system.
|
||||
However, because he's heard you have significant experience dealing with signal-based systems, he convinced the other Elves that it would be okay to give you their one malfunctioning device - surely you'll have no problem fixing it.
|
||||
As if inspired by comedic timing, the device emits a few colorful sparks.
|
||||
To be able to communicate with the Elves, the device needs to lock on to their signal. The signal is a series of seemingly-random characters that the device receives one at a time.
|
||||
To fix the communication system, you need to add a subroutine to the device that detects a start-of-packet marker in the datastream. In the protocol being used by the Elves, the start of a packet is indicated by a sequence of four characters that are all different.
|
||||
The device will send your subroutine a datastream buffer (your puzzle input); your subroutine needs to identify the first position where the four most recently received characters were all different. Specifically, it needs to report the number of characters from the beginning of the buffer to the end of the first such four-character marker.
|
||||
For example, suppose you receive the following datastream buffer:
|
||||
mjqjpqmgbljsphdztnvjfqwrcgsmlb
|
||||
After the first three characters (mjq) have been received, there haven't been enough characters received yet to find the marker. The first time a marker could occur is after the fourth character is received, making the most recent four characters mjqj. Because j is repeated, this isn't a marker.
|
||||
The first time a marker appears is after the seventh character arrives. Once it does, the last four characters received are jpqm, which are all different. In this case, your subroutine should report the value 7, because the first start-of-packet marker is complete after 7 characters have been processed.
|
||||
Here are a few more examples:
|
||||
|
||||
bvwbjplbgvbhsrlpgdmjqwftvncz: first marker after character 5
|
||||
nppdvjthqldpwncqszvftbrmjlhg: first marker after character 6
|
||||
nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg: first marker after character 10
|
||||
zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw: first marker after character 11
|
||||
|
||||
How many characters need to be processed before the first start-of-packet marker is detected?
|
||||
|
||||
--- Part Two ---
|
||||
Your device's communication system is correctly detecting packets, but still isn't working. It looks like it also needs to look for messages.
|
||||
|
||||
A start-of-message marker is just like a start-of-packet marker, except it consists of 14 distinct characters rather than 4.
|
||||
|
||||
Here are the first positions of start-of-message markers for all of the above examples:
|
||||
|
||||
mjqjpqmgbljsphdztnvjfqwrcgsmlb: first marker after character 19
|
||||
bvwbjplbgvbhsrlpgdmjqwftvncz: first marker after character 23
|
||||
nppdvjthqldpwncqszvftbrmjlhg: first marker after character 23
|
||||
nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg: first marker after character 29
|
||||
zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw: first marker after character 26
|
||||
How many characters need to be processed before the first start-of-message marker is detected?
|
||||
|
||||
https://adventofcode.com/2022/day/6
|
||||
*/
|
||||
fun main() {
|
||||
val inlineTestInput = """
|
||||
|
@ -5,98 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 7: No Space Left On Device ---
|
||||
You can hear birds chirping and raindrops hitting leaves as the expedition proceeds. Occasionally, you can even hear much louder sounds in the distance; how big do the animals get out here, anyway?
|
||||
The device the Elves gave you has problems with more than just its communication system. You try to run a system update:
|
||||
$ system-update --please --pretty-please-with-sugar-on-top
|
||||
Error: No space left on device
|
||||
|
||||
Perhaps you can delete some files to make space for the update?
|
||||
You browse around the filesystem to assess the situation and save the resulting terminal output (your puzzle input). For example:
|
||||
$ cd /
|
||||
$ ls
|
||||
dir a
|
||||
14848514 b.txt
|
||||
8504156 c.dat
|
||||
dir d
|
||||
$ cd a
|
||||
$ ls
|
||||
dir e
|
||||
29116 f
|
||||
2557 g
|
||||
62596 h.lst
|
||||
$ cd e
|
||||
$ ls
|
||||
584 i
|
||||
$ cd ..
|
||||
$ cd ..
|
||||
$ cd d
|
||||
$ ls
|
||||
4060174 j
|
||||
8033020 d.log
|
||||
5626152 d.ext
|
||||
7214296 k
|
||||
|
||||
The filesystem consists of a tree of files (plain data) and directories (which can contain other directories or files). The outermost directory is called /. You can navigate around the filesystem, moving into or out of directories and listing the contents of the directory you're currently in.
|
||||
Within the terminal output, lines that begin with $ are commands you executed, very much like some modern computers:
|
||||
|
||||
cd means change directory. This changes which directory is the current directory, but the specific result depends on the argument:
|
||||
|
||||
cd x moves in one level: it looks in the current directory for the directory named x and makes it the current directory.
|
||||
cd .. moves out one level: it finds the directory that contains the current directory, then makes that directory the current directory.
|
||||
cd / switches the current directory to the outermost directory, /.
|
||||
|
||||
|
||||
ls means list. It prints out all of the files and directories immediately contained by the current directory:
|
||||
|
||||
123 abc means that the current directory contains a file named abc with size 123.
|
||||
dir xyz means that the current directory contains a directory named xyz.
|
||||
|
||||
|
||||
|
||||
Given the commands and output in the example above, you can determine that the filesystem looks visually like this:
|
||||
- / (dir)
|
||||
- a (dir)
|
||||
- e (dir)
|
||||
- i (file, size=584)
|
||||
- f (file, size=29116)
|
||||
- g (file, size=2557)
|
||||
- h.lst (file, size=62596)
|
||||
- b.txt (file, size=14848514)
|
||||
- c.dat (file, size=8504156)
|
||||
- d (dir)
|
||||
- j (file, size=4060174)
|
||||
- d.log (file, size=8033020)
|
||||
- d.ext (file, size=5626152)
|
||||
- k (file, size=7214296)
|
||||
|
||||
Here, there are four directories: / (the outermost directory), a and d (which are in /), and e (which is in a). These directories also contain files of various sizes.
|
||||
Since the disk is full, your first step should probably be to find directories that are good candidates for deletion. To do this, you need to determine the total size of each directory. The total size of a directory is the sum of the sizes of the files it contains, directly or indirectly. (Directories themselves do not count as having any intrinsic size.)
|
||||
The total sizes of the directories above can be found as follows:
|
||||
|
||||
The total size of directory e is 584 because it contains a single file i of size 584 and no other directories.
|
||||
The directory a has total size 94853 because it contains files f (size 29116), g (size 2557), and h.lst (size 62596), plus file i indirectly (a contains e which contains i).
|
||||
Directory d has total size 24933642.
|
||||
As the outermost directory, / contains every file. Its total size is 48381165, the sum of the size of every file.
|
||||
|
||||
To begin, find all of the directories with a total size of at most 100000, then calculate the sum of their total sizes. In the example above, these directories are a and e; the sum of their total sizes is 95437 (94853 + 584). (As in this example, this process can count files more than once!)
|
||||
Find all of the directories with a total size of at most 100000. What is the sum of the total sizes of those directories?
|
||||
|
||||
--- Part Two ---
|
||||
Now, you're ready to choose a directory to delete.
|
||||
|
||||
The total disk space available to the filesystem is 70000000. To run the update, you need unused space of at least 30000000. You need to find a directory you can delete that will free up enough space to run the update.
|
||||
|
||||
In the example above, the total size of the outermost directory (and thus the total amount of used space) is 48381165; this means that the size of the unused space must currently be 21618835, which isn't quite the 30000000 required by the update. Therefore, the update still requires a directory with total size of at least 8381165 to be deleted before it can run.
|
||||
|
||||
To achieve this, you have the following options:
|
||||
|
||||
Delete directory e, which would increase unused space by 584.
|
||||
Delete directory a, which would increase unused space by 94853.
|
||||
Delete directory d, which would increase unused space by 24933642.
|
||||
Delete directory /, which would increase unused space by 48381165.
|
||||
Directories e and a are both too small; deleting them would not free up enough space. However, directories d and / are both big enough! Between these, choose the smallest: d, increasing unused space by 24933642.
|
||||
|
||||
Find the smallest directory that, if deleted, would free up enough space on the filesystem to run the update. What is the total size of that directory?
|
||||
https://adventofcode.com/2022/day/7
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -7,65 +7,7 @@ import kotlin.math.min
|
||||
|
||||
/*
|
||||
--- Day 8: Treetop Tree House ---
|
||||
The expedition comes across a peculiar patch of tall trees all planted carefully in a grid. The Elves explain that a previous expedition planted these trees as a reforestation effort. Now, they're curious if this would be a good location for a tree house.
|
||||
First, determine whether there is enough tree cover here to keep a tree house hidden. To do this, you need to count the number of trees that are visible from outside the grid when looking directly along a row or column.
|
||||
The Elves have already launched a quadcopter to generate a map with the height of each tree (your puzzle input). For example:
|
||||
30373
|
||||
25512
|
||||
65332
|
||||
33549
|
||||
35390
|
||||
|
||||
Each tree is represented as a single digit whose value is its height, where 0 is the shortest and 9 is the tallest.
|
||||
A tree is visible if all of the other trees between it and an edge of the grid are shorter than it. Only consider trees in the same row or column; that is, only look up, down, left, or right from any given tree.
|
||||
All of the trees around the edge of the grid are visible - since they are already on the edge, there are no trees to block the view. In this example, that only leaves the interior nine trees to consider:
|
||||
|
||||
The top-left 5 is visible from the left and top. (It isn't visible from the right or bottom since other trees of height 5 are in the way.)
|
||||
The top-middle 5 is visible from the top and right.
|
||||
The top-right 1 is not visible from any direction; for it to be visible, there would need to only be trees of height 0 between it and an edge.
|
||||
The left-middle 5 is visible, but only from the right.
|
||||
The center 3 is not visible from any direction; for it to be visible, there would need to be only trees of at most height 2 between it and an edge.
|
||||
The right-middle 3 is visible from the right.
|
||||
In the bottom row, the middle 5 is visible, but the 3 and 4 are not.
|
||||
|
||||
With 16 trees visible on the edge and another 5 visible in the interior, a total of 21 trees are visible in this arrangement.
|
||||
Consider your map; how many trees are visible from outside the grid?
|
||||
|
||||
--- Part Two ---
|
||||
Content with the amount of tree cover available, the Elves just need to know the best spot to build their tree house: they would like to be able to see a lot of trees.
|
||||
|
||||
To measure the viewing distance from a given tree, look up, down, left, and right from that tree; stop if you reach an edge or at the first tree that is the same height or taller than the tree under consideration. (If a tree is right on the edge, at least one of its viewing distances will be zero.)
|
||||
|
||||
The Elves don't care about distant trees taller than those found by the rules above; the proposed tree house has large eaves to keep it dry, so they wouldn't be able to see higher than the tree house anyway.
|
||||
|
||||
In the example above, consider the middle 5 in the second row:
|
||||
|
||||
30373
|
||||
25512
|
||||
65332
|
||||
33549
|
||||
35390
|
||||
Looking up, its view is not blocked; it can see 1 tree (of height 3).
|
||||
Looking left, its view is blocked immediately; it can see only 1 tree (of height 5, right next to it).
|
||||
Looking right, its view is not blocked; it can see 2 trees.
|
||||
Looking down, its view is blocked eventually; it can see 2 trees (one of height 3, then the tree of height 5 that blocks its view).
|
||||
A tree's scenic score is found by multiplying together its viewing distance in each of the four directions. For this tree, this is 4 (found by multiplying 1 * 1 * 2 * 2).
|
||||
|
||||
However, you can do even better: consider the tree of height 5 in the middle of the fourth row:
|
||||
|
||||
30373
|
||||
25512
|
||||
65332
|
||||
33549
|
||||
35390
|
||||
Looking up, its view is blocked at 2 trees (by another tree with a height of 5).
|
||||
Looking left, its view is not blocked; it can see 2 trees.
|
||||
Looking down, its view is also not blocked; it can see 1 tree.
|
||||
Looking right, its view is blocked at 2 trees (by a massive tree of height 9).
|
||||
This tree's scenic score is 8 (2 * 2 * 1 * 2); this is the ideal spot for the tree house.
|
||||
|
||||
Consider each tree on your map. What is the highest scenic score possible for any tree?
|
||||
|
||||
https://adventofcode.com/2022/day/8
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -5,39 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 1: Trebuchet?! ---
|
||||
Something is wrong with global snow production, and you've been selected to take a look. The Elves have even given you a map; on it, they've used stars to mark the top fifty locations that are likely to be having problems.
|
||||
You've been doing this long enough to know that to restore snow operations, you need to check all fifty stars by December 25th.
|
||||
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
|
||||
You try to ask why they can't just use a weather machine ("not powerful enough") and where they're even sending you ("the sky") and why your map looks mostly blank ("you sure ask a lot of questions") and hang on did you just say the sky ("of course, where do you think snow comes from") when you realize that the Elves are already loading you into a trebuchet ("please hold still, we need to strap you in").
|
||||
As they're making the final adjustments, they discover that their calibration document (your puzzle input) has been amended by a very young Elf who was apparently just excited to show off her art skills. Consequently, the Elves are having trouble reading the values on the document.
|
||||
The newly-improved calibration document consists of lines of text; each line originally contained a specific calibration value that the Elves now need to recover. On each line, the calibration value can be found by combining the first digit and the last digit (in that order) to form a single two-digit number.
|
||||
For example:
|
||||
1abc2
|
||||
pqr3stu8vwx
|
||||
a1b2c3d4e5f
|
||||
treb7uchet
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
In this example, the calibration values of these four lines are 12, 38, 15, and 77. Adding these together produces 142.
|
||||
Consider your entire calibration document. What is the sum of all of the calibration values?
|
||||
|
||||
Your calculation isn't quite right. It looks like some of the digits are actually spelled out with letters: one, two, three, four, five, six, seven, eight, and nine also count as valid "digits".
|
||||
|
||||
Equipped with this new information, you now need to find the real first and last digit on each line. For example:
|
||||
|
||||
two1nine
|
||||
eightwothree
|
||||
abcone2threexyz
|
||||
xtwone3four
|
||||
4nineeightseven2
|
||||
zoneight234
|
||||
7pqrstsixteen
|
||||
|
||||
In this example, the calibration values are 29, 83, 13, 24, 42, 14, and 76. Adding these together produces 281.
|
||||
|
||||
What is the sum of all of the calibration values?
|
||||
|
||||
https://adventofcode.com/2023/day/1
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -6,43 +6,7 @@ import kotlin.math.max
|
||||
|
||||
/*
|
||||
--- Day 2: Cube Conundrum ---
|
||||
You're launched high into the atmosphere! The apex of your trajectory just barely reaches the surface of a large island floating in the sky. You gently land in a fluffy pile of leaves. It's quite cold, but you don't see much snow. An Elf runs over to greet you.
|
||||
The Elf explains that you've arrived at Snow Island and apologizes for the lack of snow. He'll be happy to explain the situation, but it's a bit of a walk, so you have some time. They don't get many visitors up here; would you like to play a game in the meantime?
|
||||
As you walk, the Elf shows you a small bag and some cubes which are either red, green, or blue. Each time you play this game, he will hide a secret number of cubes of each color in the bag, and your goal is to figure out information about the number of cubes.
|
||||
To get information, once a bag has been loaded with cubes, the Elf will reach into the bag, grab a handful of random cubes, show them to you, and then put them back in the bag. He'll do this a few times per game.
|
||||
You play several games and record the information from each game (your puzzle input). Each game is listed with its ID number (like the 11 in Game 11: ...) followed by a semicolon-separated list of subsets of cubes that were revealed from the bag (like 3 red, 5 green, 4 blue).
|
||||
For example, the record of a few games might look like this:
|
||||
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
||||
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|
||||
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
||||
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
||||
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
|
||||
|
||||
In game 1, three sets of cubes are revealed from the bag (and then put back again). The first set is 3 blue cubes and 4 red cubes; the second set is 1 red cube, 2 green cubes, and 6 blue cubes; the third set is only 2 green cubes.
|
||||
The Elf would first like to know which games would have been possible if the bag contained only 12 red cubes, 13 green cubes, and 14 blue cubes?
|
||||
In the example above, games 1, 2, and 5 would have been possible if the bag had been loaded with that configuration. However, game 3 would have been impossible because at one point the Elf showed you 20 red cubes at once; similarly, game 4 would also have been impossible because the Elf showed you 15 blue cubes at once. If you add up the IDs of the games that would have been possible, you get 8.
|
||||
Determine which games would have been possible if the bag had been loaded with only 12 red cubes, 13 green cubes, and 14 blue cubes. What is the sum of the IDs of those games?
|
||||
|
||||
--- Part Two ---
|
||||
The Elf says they've stopped producing snow because they aren't getting any water! He isn't sure why the water stopped; however, he can show you how to get to the water source to check it out for yourself. It's just up ahead!
|
||||
|
||||
As you continue your walk, the Elf poses a second question: in each game you played, what is the fewest number of cubes of each color that could have been in the bag to make the game possible?
|
||||
|
||||
Again consider the example games from earlier:
|
||||
|
||||
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
||||
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|
||||
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
||||
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
||||
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
|
||||
In game 1, the game could have been played with as few as 4 red, 2 green, and 6 blue cubes. If any color had even one fewer cube, the game would have been impossible.
|
||||
Game 2 could have been played with a minimum of 1 red, 3 green, and 4 blue cubes.
|
||||
Game 3 must have been played with at least 20 red, 13 green, and 6 blue cubes.
|
||||
Game 4 required at least 14 red, 3 green, and 15 blue cubes.
|
||||
Game 5 needed no fewer than 6 red, 3 green, and 2 blue cubes in the bag.
|
||||
The power of a set of cubes is equal to the numbers of red, green, and blue cubes multiplied together. The power of the minimum set of cubes in game 1 is 48. In games 2-5 it was 12, 1560, 630, and 36, respectively. Adding up these five powers produces the sum 2286.
|
||||
|
||||
For each game, find the minimum set of cubes that must have been present. What is the sum of the power of these sets?
|
||||
https://adventofcode.com/2023/day/2
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -6,47 +6,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 3: Gear Ratios ---
|
||||
You and the Elf eventually reach a gondola lift station; he says the gondola lift will take you up to the water source, but this is as far as he can bring you. You go inside.
|
||||
It doesn't take long to find the gondolas, but there seems to be a problem: they're not moving.
|
||||
"Aaah!"
|
||||
You turn around to see a slightly-greasy Elf with a wrench and a look of surprise. "Sorry, I wasn't expecting anyone! The gondola lift isn't working right now; it'll still be a while before I can fix it." You offer to help.
|
||||
The engineer explains that an engine part seems to be missing from the engine, but nobody can figure out which one. If you can add up all the part numbers in the engine schematic, it should be easy to work out which part is missing.
|
||||
The engine schematic (your puzzle input) consists of a visual representation of the engine. There are lots of numbers and symbols you don't really understand, but apparently any number adjacent to a symbol, even diagonally, is a "part number" and should be included in your sum. (Periods (.) do not count as a symbol.)
|
||||
Here is an example engine schematic:
|
||||
467..114..
|
||||
...*......
|
||||
..35..633.
|
||||
......#...
|
||||
617*......
|
||||
.....+.58.
|
||||
..592.....
|
||||
......755.
|
||||
...$.*....
|
||||
.664.598..
|
||||
|
||||
In this schematic, two numbers are not part numbers because they are not adjacent to a symbol: 114 (top right) and 58 (middle right). Every other number is adjacent to a symbol and so is a part number; their sum is 4361.
|
||||
Of course, the actual engine schematic is much larger. What is the sum of all of the part numbers in the engine schematic?
|
||||
--- Part Two ---
|
||||
The engineer finds the missing part and installs it in the engine! As the engine springs to life, you jump in the closest gondola, finally ready to ascend to the water source.
|
||||
You don't seem to be going very fast, though. Maybe something is still wrong? Fortunately, the gondola has a phone labeled "help", so you pick it up and the engineer answers.
|
||||
Before you can explain the situation, she suggests that you look out the window. There stands the engineer, holding a phone in one hand and waving with the other. You're going so slowly that you haven't even left the station. You exit the gondola.
|
||||
The missing part wasn't the only issue - one of the gears in the engine is wrong. A gear is any * symbol that is adjacent to exactly two part numbers. Its gear ratio is the result of multiplying those two numbers together.
|
||||
This time, you need to find the gear ratio of every gear and add them all up so that the engineer can figure out which gear needs to be replaced.
|
||||
Consider the same engine schematic again:
|
||||
467..114..
|
||||
...*......
|
||||
..35..633.
|
||||
......#...
|
||||
617*......
|
||||
.....+.58.
|
||||
..592.....
|
||||
......755.
|
||||
...$.*....
|
||||
.664.598..
|
||||
|
||||
In this schematic, there are two gears. The first is in the top left; it has part numbers 467 and 35, so its gear ratio is 16345. The second gear is in the lower right; its gear ratio is 451490. (The * adjacent to 617 is not a gear because it is only adjacent to one part number.) Adding up all of the gear ratios produces 467835.
|
||||
What is the sum of all of the gear ratios in your engine schematic?
|
||||
|
||||
https://adventofcode.com/2023/day/3
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -6,32 +6,7 @@ import splitInts
|
||||
|
||||
/*
|
||||
--- Day 4: Scratchcards ---
|
||||
The gondola takes you up. Strangely, though, the ground doesn't seem to be coming with you; you're not climbing a mountain. As the circle of Snow Island recedes below you, an entire new landmass suddenly appears above you! The gondola carries you to the surface of the new island and lurches into the station.
|
||||
As you exit the gondola, the first thing you notice is that the air here is much warmer than it was on Snow Island. It's also quite humid. Is this where the water source is?
|
||||
The next thing you notice is an Elf sitting on the floor across the station in what seems to be a pile of colorful square cards.
|
||||
"Oh! Hello!" The Elf excitedly runs over to you. "How may I be of service?" You ask about water sources.
|
||||
"I'm not sure; I just operate the gondola lift. That does sound like something we'd have, though - this is Island Island, after all! I bet the gardener would know. He's on a different island, though - er, the small kind surrounded by water, not the floating kind. We really need to come up with a better naming scheme. Tell you what: if you can help me with something quick, I'll let you borrow my boat and you can go visit the gardener. I got all these scratchcards as a gift, but I can't figure out what I've won."
|
||||
The Elf leads you over to the pile of colorful cards. There, you discover dozens of scratchcards, all with their opaque covering already scratched off. Picking one up, it looks like each card has two lists of numbers separated by a vertical bar (|): a list of winning numbers and then a list of numbers you have. You organize the information into a table (your puzzle input).
|
||||
As far as the Elf has been able to figure out, you have to figure out which of the numbers you have appear in the list of winning numbers. The first match makes the card worth one point and each match after the first doubles the point value of that card.
|
||||
For example:
|
||||
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
|
||||
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
|
||||
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
|
||||
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
|
||||
Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
|
||||
Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11
|
||||
|
||||
In the above example, card 1 has five winning numbers (41, 48, 83, 86, and 17) and eight numbers you have (83, 86, 6, 31, 17, 9, 48, and 53). Of the numbers you have, four of them (48, 83, 17, and 86) are winning numbers! That means card 1 is worth 8 points (1 for the first match, then doubled three times for each of the three matches after the first).
|
||||
|
||||
Card 2 has two winning numbers (32 and 61), so it is worth 2 points.
|
||||
Card 3 has two winning numbers (1 and 21), so it is worth 2 points.
|
||||
Card 4 has one winning number (84), so it is worth 1 point.
|
||||
Card 5 has no winning numbers, so it is worth no points.
|
||||
Card 6 has no winning numbers, so it is worth no points.
|
||||
|
||||
So, in this example, the Elf's pile of scratchcards is worth 13 points.
|
||||
Take a seat in the large pile of colorful cards. How many points are they worth in total?
|
||||
|
||||
https://adventofcode.com/2023/day/4
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -6,89 +6,7 @@ import splitLongs
|
||||
|
||||
/*
|
||||
--- Day 5: If You Give A Seed A Fertilizer ---
|
||||
You take the boat and find the gardener right where you were told he would be: managing a giant "garden" that looks more to you like a farm.
|
||||
"A water source? Island Island is the water source!" You point out that Snow Island isn't receiving any water.
|
||||
"Oh, we had to stop the water because we ran out of sand to filter it with! Can't make snow with dirty water. Don't worry, I'm sure we'll get more sand soon; we only turned off the water a few days... weeks... oh no." His face sinks into a look of horrified realization.
|
||||
"I've been so busy making sure everyone here has food that I completely forgot to check why we stopped getting more sand! There's a ferry leaving soon that is headed over in that direction - it's much faster than your boat. Could you please go check it out?"
|
||||
You barely have time to agree to this request when he brings up another. "While you wait for the ferry, maybe you can help us with our food production problem. The latest Island Island Almanac just arrived and we're having trouble making sense of it."
|
||||
The almanac (your puzzle input) lists all of the seeds that need to be planted. It also lists what type of soil to use with each kind of seed, what type of fertilizer to use with each kind of soil, what type of water to use with each kind of fertilizer, and so on. Every type of seed, soil, fertilizer and so on is identified with a number, but numbers are reused by each category - that is, soil 123 and fertilizer 123 aren't necessarily related to each other.
|
||||
For example:
|
||||
seeds: 79 14 55 13
|
||||
|
||||
seed-to-soil map:
|
||||
50 98 2
|
||||
52 50 48
|
||||
|
||||
soil-to-fertilizer map:
|
||||
0 15 37
|
||||
37 52 2
|
||||
39 0 15
|
||||
|
||||
fertilizer-to-water map:
|
||||
49 53 8
|
||||
0 11 42
|
||||
42 0 7
|
||||
57 7 4
|
||||
|
||||
water-to-light map:
|
||||
88 18 7
|
||||
18 25 70
|
||||
|
||||
light-to-temperature map:
|
||||
45 77 23
|
||||
81 45 19
|
||||
68 64 13
|
||||
|
||||
temperature-to-humidity map:
|
||||
0 69 1
|
||||
1 0 69
|
||||
|
||||
humidity-to-location map:
|
||||
60 56 37
|
||||
56 93 4
|
||||
|
||||
The almanac starts by listing which seeds need to be planted: seeds 79, 14, 55, and 13.
|
||||
The rest of the almanac contains a list of maps which describe how to convert numbers from a source category into numbers in a destination category. That is, the section that starts with seed-to-soil map: describes how to convert a seed number (the source) to a soil number (the destination). This lets the gardener and his team know which soil to use with which seeds, which water to use with which fertilizer, and so on.
|
||||
Rather than list every source number and its corresponding destination number one by one, the maps describe entire ranges of numbers that can be converted. Each line within a map contains three numbers: the destination range start, the source range start, and the range length.
|
||||
Consider again the example seed-to-soil map:
|
||||
50 98 2
|
||||
52 50 48
|
||||
|
||||
The first line has a destination range start of 50, a source range start of 98, and a range length of 2. This line means that the source range starts at 98 and contains two values: 98 and 99. The destination range is the same length, but it starts at 50, so its two values are 50 and 51. With this information, you know that seed number 98 corresponds to soil number 50 and that seed number 99 corresponds to soil number 51.
|
||||
The second line means that the source range starts at 50 and contains 48 values: 50, 51, ..., 96, 97. This corresponds to a destination range starting at 52 and also containing 48 values: 52, 53, ..., 98, 99. So, seed number 53 corresponds to soil number 55.
|
||||
Any source numbers that aren't mapped correspond to the same destination number. So, seed number 10 corresponds to soil number 10.
|
||||
So, the entire list of seed numbers and their corresponding soil numbers looks like this:
|
||||
seed soil
|
||||
0 0
|
||||
1 1
|
||||
... ...
|
||||
48 48
|
||||
49 49
|
||||
50 52
|
||||
51 53
|
||||
... ...
|
||||
96 98
|
||||
97 99
|
||||
98 50
|
||||
99 51
|
||||
|
||||
With this map, you can look up the soil number required for each initial seed number:
|
||||
|
||||
Seed number 79 corresponds to soil number 81.
|
||||
Seed number 14 corresponds to soil number 14.
|
||||
Seed number 55 corresponds to soil number 57.
|
||||
Seed number 13 corresponds to soil number 13.
|
||||
|
||||
The gardener and his team want to get started as soon as possible, so they'd like to know the closest location that needs a seed. Using these maps, find the lowest location number that corresponds to any of the initial seeds. To do this, you'll need to convert each seed number through other categories until you can find its corresponding location number. In this example, the corresponding types are:
|
||||
|
||||
Seed 79, soil 81, fertilizer 81, water 81, light 74, temperature 78, humidity 78, location 82.
|
||||
Seed 14, soil 14, fertilizer 53, water 49, light 42, temperature 42, humidity 43, location 43.
|
||||
Seed 55, soil 57, fertilizer 57, water 53, light 46, temperature 82, humidity 82, location 86.
|
||||
Seed 13, soil 13, fertilizer 52, water 41, light 34, temperature 34, humidity 35, location 35.
|
||||
|
||||
So, the lowest location number in this example is 35.
|
||||
What is the lowest location number that corresponds to any of the initial seed numbers?
|
||||
|
||||
https://adventofcode.com/2023/day/5
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -6,39 +6,7 @@ import splitInts
|
||||
|
||||
/*
|
||||
--- Day 6: Wait For It ---
|
||||
The ferry quickly brings you across Island Island. After asking around, you discover that there is indeed normally a large pile of sand somewhere near here, but you don't see anything besides lots of water and the small island where the ferry has docked.
|
||||
As you try to figure out what to do next, you notice a poster on a wall near the ferry dock. "Boat races! Open to the public! Grand prize is an all-expenses-paid trip to Desert Island!" That must be where the sand comes from! Best of all, the boat races are starting in just a few minutes.
|
||||
You manage to sign up as a competitor in the boat races just in time. The organizer explains that it's not really a traditional race - instead, you will get a fixed amount of time during which your boat has to travel as far as it can, and you win if your boat goes the farthest.
|
||||
As part of signing up, you get a sheet of paper (your puzzle input) that lists the time allowed for each race and also the best distance ever recorded in that race. To guarantee you win the grand prize, you need to make sure you go farther in each race than the current record holder.
|
||||
The organizer brings you over to the area where the boat races are held. The boats are much smaller than you expected - they're actually toy boats, each with a big button on top. Holding down the button charges the boat, and releasing the button allows the boat to move. Boats move faster if their button was held longer, but time spent holding the button counts against the total race time. You can only hold the button at the start of the race, and boats don't move until the button is released.
|
||||
For example:
|
||||
Time: 7 15 30
|
||||
Distance: 9 40 200
|
||||
|
||||
This document describes three races:
|
||||
|
||||
The first race lasts 7 milliseconds. The record distance in this race is 9 millimeters.
|
||||
The second race lasts 15 milliseconds. The record distance in this race is 40 millimeters.
|
||||
The third race lasts 30 milliseconds. The record distance in this race is 200 millimeters.
|
||||
|
||||
Your toy boat has a starting speed of zero millimeters per millisecond. For each whole millisecond you spend at the beginning of the race holding down the button, the boat's speed increases by one millimeter per millisecond.
|
||||
So, because the first race lasts 7 milliseconds, you only have a few options:
|
||||
|
||||
Don't hold the button at all (that is, hold it for 0 milliseconds) at the start of the race. The boat won't move; it will have traveled 0 millimeters by the end of the race.
|
||||
Hold the button for 1 millisecond at the start of the race. Then, the boat will travel at a speed of 1 millimeter per millisecond for 6 milliseconds, reaching a total distance traveled of 6 millimeters.
|
||||
Hold the button for 2 milliseconds, giving the boat a speed of 2 millimeters per millisecond. It will then get 5 milliseconds to move, reaching a total distance of 10 millimeters.
|
||||
Hold the button for 3 milliseconds. After its remaining 4 milliseconds of travel time, the boat will have gone 12 millimeters.
|
||||
Hold the button for 4 milliseconds. After its remaining 3 milliseconds of travel time, the boat will have gone 12 millimeters.
|
||||
Hold the button for 5 milliseconds, causing the boat to travel a total of 10 millimeters.
|
||||
Hold the button for 6 milliseconds, causing the boat to travel a total of 6 millimeters.
|
||||
Hold the button for 7 milliseconds. That's the entire duration of the race. You never let go of the button. The boat can't move until you let you of the button. Please make sure you let go of the button so the boat gets to move. 0 millimeters.
|
||||
|
||||
Since the current record for this race is 9 millimeters, there are actually 4 different ways you could win: you could hold the button for 2, 3, 4, or 5 milliseconds at the start of the race.
|
||||
In the second race, you could hold the button for at least 4 milliseconds and at most 11 milliseconds and beat the record, a total of 8 different ways to win.
|
||||
In the third race, you could hold the button for at least 11 milliseconds and no more than 19 milliseconds and still beat the record, a total of 9 ways you could win.
|
||||
To see how much margin of error you have, determine the number of ways you can beat the record in each race; in this example, if you multiply these values together, you get 288 (4 * 8 * 9).
|
||||
Determine the number of ways you could beat the record in each race. What do you get if you multiply these numbers together?
|
||||
|
||||
https://adventofcode.com/2023/day/6
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -5,45 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 7: Camel Cards ---
|
||||
Your all-expenses-paid trip turns out to be a one-way, five-minute ride in an airship. (At least it's a cool airship!) It drops you off at the edge of a vast desert and descends back to Island Island.
|
||||
"Did you bring the parts?"
|
||||
You turn around to see an Elf completely covered in white clothing, wearing goggles, and riding a large camel.
|
||||
"Did you bring the parts?" she asks again, louder this time. You aren't sure what parts she's looking for; you're here to figure out why the sand stopped.
|
||||
"The parts! For the sand, yes! Come with me; I will show you." She beckons you onto the camel.
|
||||
After riding a bit across the sands of Desert Island, you can see what look like very large rocks covering half of the horizon. The Elf explains that the rocks are all along the part of Desert Island that is directly above Island Island, making it hard to even get there. Normally, they use big machines to move the rocks and filter the sand, but the machines have broken down because Desert Island recently stopped receiving the parts they need to fix the machines.
|
||||
You've already assumed it'll be your job to figure out why the parts stopped when she asks if you can help. You agree automatically.
|
||||
Because the journey will take a few days, she offers to teach you the game of Camel Cards. Camel Cards is sort of similar to poker except it's designed to be easier to play while riding a camel.
|
||||
In Camel Cards, you get a list of hands, and your goal is to order them based on the strength of each hand. A hand consists of five cards labeled one of A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, or 2. The relative strength of each card follows this order, where A is the highest and 2 is the lowest.
|
||||
Every hand is exactly one type. From strongest to weakest, they are:
|
||||
|
||||
Five of a kind, where all five cards have the same label: AAAAA
|
||||
Four of a kind, where four cards have the same label and one card has a different label: AA8AA
|
||||
Full house, where three cards have the same label, and the remaining two cards share a different label: 23332
|
||||
Three of a kind, where three cards have the same label, and the remaining two cards are each different from any other card in the hand: TTT98
|
||||
Two pair, where two cards share one label, two other cards share a second label, and the remaining card has a third label: 23432
|
||||
One pair, where two cards share one label, and the other three cards have a different label from the pair and each other: A23A4
|
||||
High card, where all cards' labels are distinct: 23456
|
||||
|
||||
Hands are primarily ordered based on type; for example, every full house is stronger than any three of a kind.
|
||||
If two hands have the same type, a second ordering rule takes effect. Start by comparing the first card in each hand. If these cards are different, the hand with the stronger first card is considered stronger. If the first card in each hand have the same label, however, then move on to considering the second card in each hand. If they differ, the hand with the higher second card wins; otherwise, continue with the third card in each hand, then the fourth, then the fifth.
|
||||
So, 33332 and 2AAAA are both four of a kind hands, but 33332 is stronger because its first card is stronger. Similarly, 77888 and 77788 are both a full house, but 77888 is stronger because its third card is stronger (and both hands have the same first and second card).
|
||||
To play Camel Cards, you are given a list of hands and their corresponding bid (your puzzle input). For example:
|
||||
32T3K 765
|
||||
T55J5 684
|
||||
KK677 28
|
||||
KTJJT 220
|
||||
QQQJA 483
|
||||
|
||||
This example shows five hands; each hand is followed by its bid amount. Each hand wins an amount equal to its bid multiplied by its rank, where the weakest hand gets rank 1, the second-weakest hand gets rank 2, and so on up to the strongest hand. Because there are five hands in this example, the strongest hand will have rank 5 and its bid will be multiplied by 5.
|
||||
So, the first step is to put the hands in order of strength:
|
||||
|
||||
32T3K is the only one pair and the other hands are all a stronger type, so it gets rank 1.
|
||||
KK677 and KTJJT are both two pair. Their first cards both have the same label, but the second card of KK677 is stronger (K vs T), so KTJJT gets rank 2 and KK677 gets rank 3.
|
||||
T55J5 and QQQJA are both three of a kind. QQQJA has a stronger first card, so it gets rank 5 and T55J5 gets rank 4.
|
||||
|
||||
Now, you can determine the total winnings of this set of hands by adding up the result of multiplying each hand's bid with its rank (765 * 1 + 220 * 2 + 28 * 3 + 684 * 4 + 483 * 5). So the total winnings in this example are 6440.
|
||||
Find the rank of every hand in your set. What are the total winnings?
|
||||
|
||||
https://adventofcode.com/2023/day/7
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -6,31 +6,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 8: Haunted Wasteland ---
|
||||
You're still riding a camel across Desert Island when you spot a sandstorm quickly approaching. When you turn to warn the Elf, she disappears before your eyes! To be fair, she had just finished warning you about ghosts a few minutes ago.
|
||||
One of the camel's pouches is labeled "maps" - sure enough, it's full of documents (your puzzle input) about how to navigate the desert. At least, you're pretty sure that's what they are; one of the documents contains a list of left/right instructions, and the rest of the documents seem to describe some kind of network of labeled nodes.
|
||||
It seems like you're meant to use the left/right instructions to navigate the network. Perhaps if you have the camel follow the same instructions, you can escape the haunted wasteland!
|
||||
After examining the maps for a bit, two nodes stick out: AAA and ZZZ. You feel like AAA is where you are now, and you have to follow the left/right instructions until you reach ZZZ.
|
||||
This format defines each node of the network individually. For example:
|
||||
RL
|
||||
|
||||
AAA = (BBB, CCC)
|
||||
BBB = (DDD, EEE)
|
||||
CCC = (ZZZ, GGG)
|
||||
DDD = (DDD, DDD)
|
||||
EEE = (EEE, EEE)
|
||||
GGG = (GGG, GGG)
|
||||
ZZZ = (ZZZ, ZZZ)
|
||||
|
||||
Starting with AAA, you need to look up the next element based on the next left/right instruction in your input. In this example, start with AAA and go right (R) by choosing the right element of AAA, CCC. Then, L means to choose the left element of CCC, ZZZ. By following the left/right instructions, you reach ZZZ in 2 steps.
|
||||
Of course, you might not find ZZZ right away. If you run out of left/right instructions, repeat the whole sequence of instructions as necessary: RL really means RLRLRLRLRLRLRLRL... and so on. For example, here is a situation that takes 6 steps to reach ZZZ:
|
||||
LLR
|
||||
|
||||
AAA = (BBB, BBB)
|
||||
BBB = (AAA, ZZZ)
|
||||
ZZZ = (ZZZ, ZZZ)
|
||||
|
||||
Starting at AAA, follow the left/right instructions. How many steps are required to reach ZZZ?
|
||||
|
||||
https://adventofcode.com/2023/day/8
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -6,61 +6,7 @@ import splitInts
|
||||
|
||||
/*
|
||||
--- Day 9: Mirage Maintenance ---
|
||||
You ride the camel through the sandstorm and stop where the ghost's maps told you to stop. The sandstorm subsequently subsides, somehow seeing you standing at an oasis!
|
||||
The camel goes to get some water and you stretch your neck. As you look up, you discover what must be yet another giant floating island, this one made of metal! That must be where the parts to fix the sand machines come from.
|
||||
There's even a hang glider partially buried in the sand here; once the sun rises and heats up the sand, you might be able to use the glider and the hot air to get all the way up to the metal island!
|
||||
While you wait for the sun to rise, you admire the oasis hidden here in the middle of Desert Island. It must have a delicate ecosystem; you might as well take some ecological readings while you wait. Maybe you can report any environmental instabilities you find to someone so the oasis can be around for the next sandstorm-worn traveler.
|
||||
You pull out your handy Oasis And Sand Instability Sensor and analyze your surroundings. The OASIS produces a report of many values and how they are changing over time (your puzzle input). Each line in the report contains the history of a single value. For example:
|
||||
0 3 6 9 12 15
|
||||
1 3 6 10 15 21
|
||||
10 13 16 21 30 45
|
||||
|
||||
To best protect the oasis, your environmental report should include a prediction of the next value in each history. To do this, start by making a new sequence from the difference at each step of your history. If that sequence is not all zeroes, repeat this process, using the sequence you just generated as the input sequence. Once all of the values in your latest sequence are zeroes, you can extrapolate what the next value of the original history should be.
|
||||
In the above dataset, the first history is 0 3 6 9 12 15. Because the values increase by 3 each step, the first sequence of differences that you generate will be 3 3 3 3 3. Note that this sequence has one fewer value than the input sequence because at each step it considers two numbers from the input. Since these values aren't all zero, repeat the process: the values differ by 0 at each step, so the next sequence is 0 0 0 0. This means you have enough information to extrapolate the history! Visually, these sequences can be arranged like this:
|
||||
0 3 6 9 12 15
|
||||
3 3 3 3 3
|
||||
0 0 0 0
|
||||
|
||||
To extrapolate, start by adding a new zero to the end of your list of zeroes; because the zeroes represent differences between the two values above them, this also means there is now a placeholder in every sequence above it:
|
||||
0 3 6 9 12 15 B
|
||||
3 3 3 3 3 A
|
||||
0 0 0 0 0
|
||||
|
||||
You can then start filling in placeholders from the bottom up. A needs to be the result of increasing 3 (the value to its left) by 0 (the value below it); this means A must be 3:
|
||||
0 3 6 9 12 15 B
|
||||
3 3 3 3 3 3
|
||||
0 0 0 0 0
|
||||
|
||||
Finally, you can fill in B, which needs to be the result of increasing 15 (the value to its left) by 3 (the value below it), or 18:
|
||||
0 3 6 9 12 15 18
|
||||
3 3 3 3 3 3
|
||||
0 0 0 0 0
|
||||
|
||||
So, the next value of the first history is 18.
|
||||
Finding all-zero differences for the second history requires an additional sequence:
|
||||
1 3 6 10 15 21
|
||||
2 3 4 5 6
|
||||
1 1 1 1
|
||||
0 0 0
|
||||
|
||||
Then, following the same process as before, work out the next value in each sequence from the bottom up:
|
||||
1 3 6 10 15 21 28
|
||||
2 3 4 5 6 7
|
||||
1 1 1 1 1
|
||||
0 0 0 0
|
||||
|
||||
So, the next value of the second history is 28.
|
||||
The third history requires even more sequences, but its next value can be found the same way:
|
||||
10 13 16 21 30 45 68
|
||||
3 3 5 9 15 23
|
||||
0 2 4 6 8
|
||||
2 2 2 2
|
||||
0 0 0
|
||||
|
||||
So, the next value of the third history is 68.
|
||||
If you find the next value for each history in this example and add them together, you get 114.
|
||||
Analyze your OASIS report and extrapolate the next value for each history. What is the sum of these extrapolated values?
|
||||
|
||||
https://adventofcode.com/2023/day/9
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -6,91 +6,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 10: Pipe Maze ---
|
||||
You use the hang glider to ride the hot air from Desert Island all the way up to the floating metal island. This island is surprisingly cold and there definitely aren't any thermals to glide on, so you leave your hang glider behind.
|
||||
You wander around for a while, but you don't find any people or animals. However, you do occasionally find signposts labeled "Hot Springs" pointing in a seemingly consistent direction; maybe you can find someone at the hot springs and ask them where the desert-machine parts are made.
|
||||
The landscape here is alien; even the flowers and trees are made of metal. As you stop to admire some metal grass, you notice something metallic scurry away in your peripheral vision and jump into a big pipe! It didn't look like any animal you've ever seen; if you want a better look, you'll need to get ahead of it.
|
||||
Scanning the area, you discover that the entire field you're standing on is densely packed with pipes; it was hard to tell at first because they're the same metallic silver color as the "ground". You make a quick sketch of all of the surface pipes you can see (your puzzle input).
|
||||
The pipes are arranged in a two-dimensional grid of tiles:
|
||||
|
||||
| is a vertical pipe connecting north and south.
|
||||
- is a horizontal pipe connecting east and west.
|
||||
L is a 90-degree bend connecting north and east.
|
||||
J is a 90-degree bend connecting north and west.
|
||||
7 is a 90-degree bend connecting south and west.
|
||||
F is a 90-degree bend connecting south and east.
|
||||
. is ground; there is no pipe in this tile.
|
||||
S is the starting position of the animal; there is a pipe on this tile, but your sketch doesn't show what shape the pipe has.
|
||||
|
||||
Based on the acoustics of the animal's scurrying, you're confident the pipe that contains the animal is one large, continuous loop.
|
||||
For example, here is a square loop of pipe:
|
||||
.....
|
||||
.F-7.
|
||||
.|.|.
|
||||
.L-J.
|
||||
.....
|
||||
|
||||
If the animal had entered this loop in the northwest corner, the sketch would instead look like this:
|
||||
.....
|
||||
.S-7.
|
||||
.|.|.
|
||||
.L-J.
|
||||
.....
|
||||
|
||||
In the above diagram, the S tile is still a 90-degree F bend: you can tell because of how the adjacent pipes connect to it.
|
||||
Unfortunately, there are also many pipes that aren't connected to the loop! This sketch shows the same loop as above:
|
||||
-L|F7
|
||||
7S-7|
|
||||
L|7||
|
||||
-L-J|
|
||||
L|-JF
|
||||
|
||||
In the above diagram, you can still figure out which pipes form the main loop: they're the ones connected to S, pipes those pipes connect to, pipes those pipes connect to, and so on. Every pipe in the main loop connects to its two neighbors (including S, which will have exactly two pipes connecting to it, and which is assumed to connect back to those two pipes).
|
||||
Here is a sketch that contains a slightly more complex main loop:
|
||||
..F7.
|
||||
.FJ|.
|
||||
SJ.L7
|
||||
|F--J
|
||||
LJ...
|
||||
|
||||
Here's the same example sketch with the extra, non-main-loop pipe tiles also shown:
|
||||
7-F7-
|
||||
.FJ|7
|
||||
SJLL7
|
||||
|F--J
|
||||
LJ.LJ
|
||||
|
||||
If you want to get out ahead of the animal, you should find the tile in the loop that is farthest from the starting position. Because the animal is in the pipe, it doesn't make sense to measure this by direct distance. Instead, you need to find the tile that would take the longest number of steps along the loop to reach from the starting point - regardless of which way around the loop the animal went.
|
||||
In the first example with the square loop:
|
||||
.....
|
||||
.S-7.
|
||||
.|.|.
|
||||
.L-J.
|
||||
.....
|
||||
|
||||
You can count the distance each tile in the loop is from the starting point like this:
|
||||
.....
|
||||
.012.
|
||||
.1.3.
|
||||
.234.
|
||||
.....
|
||||
|
||||
In this example, the farthest point from the start is 4 steps away.
|
||||
Here's the more complex loop again:
|
||||
..F7.
|
||||
.FJ|.
|
||||
SJ.L7
|
||||
|F--J
|
||||
LJ...
|
||||
|
||||
Here are the distances for each tile on that loop:
|
||||
..45.
|
||||
.236.
|
||||
01.78
|
||||
14567
|
||||
23...
|
||||
|
||||
Find the single giant loop starting at S. How many steps along the loop does it take to get from the starting position to the point farthest from the starting position?
|
||||
|
||||
https://adventofcode.com/2023/day/10
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -7,89 +7,7 @@ import kotlin.math.abs
|
||||
|
||||
/*
|
||||
--- Day 11: Cosmic Expansion ---
|
||||
You continue following signs for "Hot Springs" and eventually come across an observatory. The Elf within turns out to be a researcher studying cosmic expansion using the giant telescope here.
|
||||
He doesn't know anything about the missing machine parts; he's only visiting for this research project. However, he confirms that the hot springs are the next-closest area likely to have people; he'll even take you straight there once he's done with today's observation analysis.
|
||||
Maybe you can help him with the analysis to speed things up?
|
||||
The researcher has collected a bunch of data and compiled the data into a single giant image (your puzzle input). The image includes empty space (.) and galaxies (#). For example:
|
||||
...#......
|
||||
.......#..
|
||||
#.........
|
||||
..........
|
||||
......#...
|
||||
.#........
|
||||
.........#
|
||||
..........
|
||||
.......#..
|
||||
#...#.....
|
||||
|
||||
The researcher is trying to figure out the sum of the lengths of the shortest path between every pair of galaxies. However, there's a catch: the universe expanded in the time it took the light from those galaxies to reach the observatory.
|
||||
Due to something involving gravitational effects, only some space expands. In fact, the result is that any rows or columns that contain no galaxies should all actually be twice as big.
|
||||
In the above example, three columns and two rows contain no galaxies:
|
||||
v v v
|
||||
...#......
|
||||
.......#..
|
||||
#.........
|
||||
>..........<
|
||||
......#...
|
||||
.#........
|
||||
.........#
|
||||
>..........<
|
||||
.......#..
|
||||
#...#.....
|
||||
^ ^ ^
|
||||
|
||||
These rows and columns need to be twice as big; the result of cosmic expansion therefore looks like this:
|
||||
....#........
|
||||
.........#...
|
||||
#............
|
||||
.............
|
||||
.............
|
||||
........#....
|
||||
.#...........
|
||||
............#
|
||||
.............
|
||||
.............
|
||||
.........#...
|
||||
#....#.......
|
||||
|
||||
Equipped with this expanded universe, the shortest path between every pair of galaxies can be found. It can help to assign every galaxy a unique number:
|
||||
....1........
|
||||
.........2...
|
||||
3............
|
||||
.............
|
||||
.............
|
||||
........4....
|
||||
.5...........
|
||||
............6
|
||||
.............
|
||||
.............
|
||||
.........7...
|
||||
8....9.......
|
||||
|
||||
In these 9 galaxies, there are 36 pairs. Only count each pair once; order within the pair doesn't matter. For each pair, find any shortest path between the two galaxies using only steps that move up, down, left, or right exactly one . or # at a time. (The shortest path between two galaxies is allowed to pass through another galaxy.)
|
||||
For example, here is one of the shortest paths between galaxies 5 and 9:
|
||||
....1........
|
||||
.........2...
|
||||
3............
|
||||
.............
|
||||
.............
|
||||
........4....
|
||||
.5...........
|
||||
.##.........6
|
||||
..##.........
|
||||
...##........
|
||||
....##...7...
|
||||
8....9.......
|
||||
|
||||
This path has length 9 because it takes a minimum of nine steps to get from galaxy 5 to galaxy 9 (the eight locations marked # plus the step onto galaxy 9 itself). Here are some other example shortest path lengths:
|
||||
|
||||
Between galaxy 1 and galaxy 7: 15
|
||||
Between galaxy 3 and galaxy 6: 17
|
||||
Between galaxy 8 and galaxy 9: 5
|
||||
|
||||
In this example, after expanding the universe, the sum of the shortest path between all 36 pairs of galaxies is 374.
|
||||
Expand the universe, then find the length of the shortest path between every pair of galaxies. What is the sum of these lengths?
|
||||
|
||||
https://adventofcode.com/2023/day/11
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -5,61 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 12: Hot Springs ---
|
||||
You finally reach the hot springs! You can see steam rising from secluded areas attached to the primary, ornate building.
|
||||
As you turn to enter, the researcher stops you. "Wait - I thought you were looking for the hot springs, weren't you?" You indicate that this definitely looks like hot springs to you.
|
||||
"Oh, sorry, common mistake! This is actually the onsen! The hot springs are next door."
|
||||
You look in the direction the researcher is pointing and suddenly notice the massive metal helixes towering overhead. "This way!"
|
||||
It only takes you a few more steps to reach the main gate of the massive fenced-off area containing the springs. You go through the gate and into a small administrative building.
|
||||
"Hello! What brings you to the hot springs today? Sorry they're not very hot right now; we're having a lava shortage at the moment." You ask about the missing machine parts for Desert Island.
|
||||
"Oh, all of Gear Island is currently offline! Nothing is being manufactured at the moment, not until we get more lava to heat our forges. And our springs. The springs aren't very springy unless they're hot!"
|
||||
"Say, could you go up and see why the lava stopped flowing? The springs are too cold for normal operation, but we should be able to find one springy enough to launch you up there!"
|
||||
There's just one problem - many of the springs have fallen into disrepair, so they're not actually sure which springs would even be safe to use! Worse yet, their condition records of which springs are damaged (your puzzle input) are also damaged! You'll need to help them repair the damaged records.
|
||||
In the giant field just outside, the springs are arranged into rows. For each row, the condition records show every spring and whether it is operational (.) or damaged (#). This is the part of the condition records that is itself damaged; for some springs, it is simply unknown (?) whether the spring is operational or damaged.
|
||||
However, the engineer that produced the condition records also duplicated some of this information in a different format! After the list of springs for a given row, the size of each contiguous group of damaged springs is listed in the order those groups appear in the row. This list always accounts for every damaged spring, and each number is the entire size of its contiguous group (that is, groups are always separated by at least one operational spring: #### would always be 4, never 2,2).
|
||||
So, condition records with no unknown spring conditions might look like this:
|
||||
#.#.### 1,1,3
|
||||
.#...#....###. 1,1,3
|
||||
.#.###.#.###### 1,3,1,6
|
||||
####.#...#... 4,1,1
|
||||
#....######..#####. 1,6,5
|
||||
.###.##....# 3,2,1
|
||||
|
||||
However, the condition records are partially damaged; some of the springs' conditions are actually unknown (?). For example:
|
||||
???.### 1,1,3
|
||||
.??..??...?##. 1,1,3
|
||||
?#?#?#?#?#?#?#? 1,3,1,6
|
||||
????.#...#... 4,1,1
|
||||
????.######..#####. 1,6,5
|
||||
?###???????? 3,2,1
|
||||
|
||||
Equipped with this information, it is your job to figure out how many different arrangements of operational and broken springs fit the given criteria in each row.
|
||||
In the first line (???.### 1,1,3), there is exactly one way separate groups of one, one, and three broken springs (in that order) can appear in that row: the first three unknown springs must be broken, then operational, then broken (#.#), making the whole row #.#.###.
|
||||
The second line is more interesting: .??..??...?##. 1,1,3 could be a total of four different arrangements. The last ? must always be broken (to satisfy the final contiguous group of three broken springs), and each ?? must hide exactly one of the two broken springs. (Neither ?? could be both broken springs or they would form a single contiguous group of two; if that were true, the numbers afterward would have been 2,3 instead.) Since each ?? can either be #. or .#, there are four possible arrangements of springs.
|
||||
The last line is actually consistent with ten different arrangements! Because the first number is 3, the first and second ? must both be . (if either were #, the first number would have to be 4 or higher). However, the remaining run of unknown spring conditions have many different ways they could hold groups of two and one broken springs:
|
||||
?###???????? 3,2,1
|
||||
.###.##.#...
|
||||
.###.##..#..
|
||||
.###.##...#.
|
||||
.###.##....#
|
||||
.###..##.#..
|
||||
.###..##..#.
|
||||
.###..##...#
|
||||
.###...##.#.
|
||||
.###...##..#
|
||||
.###....##.#
|
||||
|
||||
In this example, the number of possible arrangements for each row is:
|
||||
|
||||
???.### 1,1,3 - 1 arrangement
|
||||
.??..??...?##. 1,1,3 - 4 arrangements
|
||||
?#?#?#?#?#?#?#? 1,3,1,6 - 1 arrangement
|
||||
????.#...#... 4,1,1 - 1 arrangement
|
||||
????.######..#####. 1,6,5 - 4 arrangements
|
||||
?###???????? 3,2,1 - 10 arrangements
|
||||
|
||||
Adding all of the possible arrangement counts together produces a total of 21 arrangements.
|
||||
For each row, count all of the different arrangements of operational and broken springs that meet the given criteria. What is the sum of those counts?
|
||||
|
||||
https://adventofcode.com/2023/day/12
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -6,56 +6,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 13: Point of Incidence ---
|
||||
With your help, the hot springs team locates an appropriate spring which launches you neatly and precisely up to the edge of Lava Island.
|
||||
There's just one problem: you don't see any lava.
|
||||
You do see a lot of ash and igneous rock; there are even what look like gray mountains scattered around. After a while, you make your way to a nearby cluster of mountains only to discover that the valley between them is completely full of large mirrors. Most of the mirrors seem to be aligned in a consistent way; perhaps you should head in that direction?
|
||||
As you move through the valley of mirrors, you find that several of them have fallen from the large metal frames keeping them in place. The mirrors are extremely flat and shiny, and many of the fallen mirrors have lodged into the ash at strange angles. Because the terrain is all one color, it's hard to tell where it's safe to walk or where you're about to run into a mirror.
|
||||
You note down the patterns of ash (.) and rocks (#) that you see as you walk (your puzzle input); perhaps by carefully analyzing these patterns, you can figure out where the mirrors are!
|
||||
For example:
|
||||
#.##..##.
|
||||
..#.##.#.
|
||||
##......#
|
||||
##......#
|
||||
..#.##.#.
|
||||
..##..##.
|
||||
#.#.##.#.
|
||||
|
||||
#...##..#
|
||||
#....#..#
|
||||
..##..###
|
||||
#####.##.
|
||||
#####.##.
|
||||
..##..###
|
||||
#....#..#
|
||||
|
||||
To find the reflection in each pattern, you need to find a perfect reflection across either a horizontal line between two rows or across a vertical line between two columns.
|
||||
In the first pattern, the reflection is across a vertical line between two columns; arrows on each of the two columns point at the line between the columns:
|
||||
123456789
|
||||
><
|
||||
#.##..##.
|
||||
..#.##.#.
|
||||
##......#
|
||||
##......#
|
||||
..#.##.#.
|
||||
..##..##.
|
||||
#.#.##.#.
|
||||
><
|
||||
123456789
|
||||
|
||||
In this pattern, the line of reflection is the vertical line between columns 5 and 6. Because the vertical line is not perfectly in the middle of the pattern, part of the pattern (column 1) has nowhere to reflect onto and can be ignored; every other column has a reflected column within the pattern and must match exactly: column 2 matches column 9, column 3 matches 8, 4 matches 7, and 5 matches 6.
|
||||
The second pattern reflects across a horizontal line instead:
|
||||
1 #...##..# 1
|
||||
2 #....#..# 2
|
||||
3 ..##..### 3
|
||||
4v#####.##.v4
|
||||
5^#####.##.^5
|
||||
6 ..##..### 6
|
||||
7 #....#..# 7
|
||||
|
||||
This pattern reflects across the horizontal line between rows 4 and 5. Row 1 would reflect with a hypothetical row 8, but since that's not in the pattern, row 1 doesn't need to match anything. The remaining rows match: row 2 matches row 7, row 3 matches row 6, and row 4 matches row 5.
|
||||
To summarize your pattern notes, add up the number of columns to the left of each vertical line of reflection; to that, also add 100 multiplied by the number of rows above each horizontal line of reflection. In the above example, the first pattern's vertical line has 5 columns to its left and the second pattern's horizontal line has 4 rows above it, a total of 405.
|
||||
Find the line of reflection in each of the patterns in your notes. What number do you get after summarizing all of your notes?
|
||||
|
||||
https://adventofcode.com/2023/day/13
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -6,50 +6,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 14: Parabolic Reflector Dish ---
|
||||
You reach the place where all of the mirrors were pointing: a massive parabolic reflector dish attached to the side of another large mountain.
|
||||
The dish is made up of many small mirrors, but while the mirrors themselves are roughly in the shape of a parabolic reflector dish, each individual mirror seems to be pointing in slightly the wrong direction. If the dish is meant to focus light, all it's doing right now is sending it in a vague direction.
|
||||
This system must be what provides the energy for the lava! If you focus the reflector dish, maybe you can go where it's pointing and use the light to fix the lava production.
|
||||
Upon closer inspection, the individual mirrors each appear to be connected via an elaborate system of ropes and pulleys to a large metal platform below the dish. The platform is covered in large rocks of various shapes. Depending on their position, the weight of the rocks deforms the platform, and the shape of the platform controls which ropes move and ultimately the focus of the dish.
|
||||
In short: if you move the rocks, you can focus the dish. The platform even has a control panel on the side that lets you tilt it in one of four directions! The rounded rocks (O) will roll when the platform is tilted, while the cube-shaped rocks (#) will stay in place. You note the positions of all of the empty spaces (.) and rocks (your puzzle input). For example:
|
||||
O....#....
|
||||
O.OO#....#
|
||||
.....##...
|
||||
OO.#O....O
|
||||
.O.....O#.
|
||||
O.#..O.#.#
|
||||
..O..#O..O
|
||||
.......O..
|
||||
#....###..
|
||||
#OO..#....
|
||||
|
||||
Start by tilting the lever so all of the rocks will slide north as far as they will go:
|
||||
OOOO.#.O..
|
||||
OO..#....#
|
||||
OO..O##..O
|
||||
O..#.OO...
|
||||
........#.
|
||||
..#....#.#
|
||||
..O..#.O.O
|
||||
..O.......
|
||||
#....###..
|
||||
#....#....
|
||||
|
||||
You notice that the support beams along the north side of the platform are damaged; to ensure the platform doesn't collapse, you should calculate the total load on the north support beams.
|
||||
The amount of load caused by a single rounded rock (O) is equal to the number of rows from the rock to the south edge of the platform, including the row the rock is on. (Cube-shaped rocks (#) don't contribute to load.) So, the amount of load caused by each rock in each row is as follows:
|
||||
OOOO.#.O.. 10
|
||||
OO..#....# 9
|
||||
OO..O##..O 8
|
||||
O..#.OO... 7
|
||||
........#. 6
|
||||
..#....#.# 5
|
||||
..O..#.O.O 4
|
||||
..O....... 3
|
||||
#....###.. 2
|
||||
#....#.... 1
|
||||
|
||||
The total load is the sum of the load caused by all of the rounded rocks. In this example, the total load is 136.
|
||||
Tilt the platform so that the rounded rocks all roll north. Afterward, what is the total load on the north support beams?
|
||||
|
||||
https://adventofcode.com/2023/day/14
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -5,61 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 15: Lens Library ---
|
||||
The newly-focused parabolic reflector dish is sending all of the collected light to a point on the side of yet another mountain - the largest mountain on Lava Island. As you approach the mountain, you find that the light is being collected by the wall of a large facility embedded in the mountainside.
|
||||
You find a door under a large sign that says "Lava Production Facility" and next to a smaller sign that says "Danger - Personal Protective Equipment required beyond this point".
|
||||
As you step inside, you are immediately greeted by a somewhat panicked reindeer wearing goggles and a loose-fitting hard hat. The reindeer leads you to a shelf of goggles and hard hats (you quickly find some that fit) and then further into the facility. At one point, you pass a button with a faint snout mark and the label "PUSH FOR HELP". No wonder you were loaded into that trebuchet so quickly!
|
||||
You pass through a final set of doors surrounded with even more warning signs and into what must be the room that collects all of the light from outside. As you admire the large assortment of lenses available to further focus the light, the reindeer brings you a book titled "Initialization Manual".
|
||||
"Hello!", the book cheerfully begins, apparently unaware of the concerned reindeer reading over your shoulder. "This procedure will let you bring the Lava Production Facility online - all without burning or melting anything unintended!"
|
||||
"Before you begin, please be prepared to use the Holiday ASCII String Helper algorithm (appendix 1A)." You turn to appendix 1A. The reindeer leans closer with interest.
|
||||
The HASH algorithm is a way to turn any string of characters into a single number in the range 0 to 255. To run the HASH algorithm on a string, start with a current value of 0. Then, for each character in the string starting from the beginning:
|
||||
|
||||
Determine the ASCII code for the current character of the string.
|
||||
Increase the current value by the ASCII code you just determined.
|
||||
Set the current value to itself multiplied by 17.
|
||||
Set the current value to the remainder of dividing itself by 256.
|
||||
|
||||
After following these steps for each character in the string in order, the current value is the output of the HASH algorithm.
|
||||
So, to find the result of running the HASH algorithm on the string HASH:
|
||||
|
||||
The current value starts at 0.
|
||||
The first character is H; its ASCII code is 72.
|
||||
The current value increases to 72.
|
||||
The current value is multiplied by 17 to become 1224.
|
||||
The current value becomes 200 (the remainder of 1224 divided by 256).
|
||||
The next character is A; its ASCII code is 65.
|
||||
The current value increases to 265.
|
||||
The current value is multiplied by 17 to become 4505.
|
||||
The current value becomes 153 (the remainder of 4505 divided by 256).
|
||||
The next character is S; its ASCII code is 83.
|
||||
The current value increases to 236.
|
||||
The current value is multiplied by 17 to become 4012.
|
||||
The current value becomes 172 (the remainder of 4012 divided by 256).
|
||||
The next character is H; its ASCII code is 72.
|
||||
The current value increases to 244.
|
||||
The current value is multiplied by 17 to become 4148.
|
||||
The current value becomes 52 (the remainder of 4148 divided by 256).
|
||||
|
||||
So, the result of running the HASH algorithm on the string HASH is 52.
|
||||
The initialization sequence (your puzzle input) is a comma-separated list of steps to start the Lava Production Facility. Ignore newline characters when parsing the initialization sequence. To verify that your HASH algorithm is working, the book offers the sum of the result of running the HASH algorithm on each step in the initialization sequence.
|
||||
For example:
|
||||
rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7
|
||||
This initialization sequence specifies 11 individual steps; the result of running the HASH algorithm on each of the steps is as follows:
|
||||
|
||||
rn=1 becomes 30.
|
||||
cm- becomes 253.
|
||||
qp=3 becomes 97.
|
||||
cm=2 becomes 47.
|
||||
qp- becomes 14.
|
||||
pc=4 becomes 180.
|
||||
ot=9 becomes 9.
|
||||
ab=5 becomes 197.
|
||||
pc- becomes 48.
|
||||
pc=6 becomes 214.
|
||||
ot=7 becomes 231.
|
||||
|
||||
In this example, the sum of these results is 1320. Unfortunately, the reindeer has stolen the page containing the expected verification number and is currently running around the facility with it excitedly.
|
||||
Run the HASH algorithm on each step in the initialization sequence. What is the sum of the results? (The initialization sequence is one long line; be careful when copy-pasting it.)
|
||||
|
||||
https://adventofcode.com/2023/day/15
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -7,57 +7,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 16: The Floor Will Be Lava ---
|
||||
With the beam of light completely focused somewhere, the reindeer leads you deeper still into the Lava Production Facility. At some point, you realize that the steel facility walls have been replaced with cave, and the doorways are just cave, and the floor is cave, and you're pretty sure this is actually just a giant cave.
|
||||
Finally, as you approach what must be the heart of the mountain, you see a bright light in a cavern up ahead. There, you discover that the beam of light you so carefully focused is emerging from the cavern wall closest to the facility and pouring all of its energy into a contraption on the opposite side.
|
||||
Upon closer inspection, the contraption appears to be a flat, two-dimensional square grid containing empty space (.), mirrors (/ and \), and splitters (| and -).
|
||||
The contraption is aligned so that most of the beam bounces around the grid, but each tile on the grid converts some of the beam's light into heat to melt the rock in the cavern.
|
||||
You note the layout of the contraption (your puzzle input). For example:
|
||||
.|...\....
|
||||
|.-.\.....
|
||||
.....|-...
|
||||
........|.
|
||||
..........
|
||||
.........\
|
||||
..../.\\..
|
||||
.-.-/..|..
|
||||
.|....-|.\
|
||||
..//.|....
|
||||
|
||||
The beam enters in the top-left corner from the left and heading to the right. Then, its behavior depends on what it encounters as it moves:
|
||||
|
||||
If the beam encounters empty space (.), it continues in the same direction.
|
||||
If the beam encounters a mirror (/ or \), the beam is reflected 90 degrees depending on the angle of the mirror. For instance, a rightward-moving beam that encounters a / mirror would continue upward in the mirror's column, while a rightward-moving beam that encounters a \ mirror would continue downward from the mirror's column.
|
||||
If the beam encounters the pointy end of a splitter (| or -), the beam passes through the splitter as if the splitter were empty space. For instance, a rightward-moving beam that encounters a - splitter would continue in the same direction.
|
||||
If the beam encounters the flat side of a splitter (| or -), the beam is split into two beams going in each of the two directions the splitter's pointy ends are pointing. For instance, a rightward-moving beam that encounters a | splitter would split into two beams: one that continues upward from the splitter's column and one that continues downward from the splitter's column.
|
||||
|
||||
Beams do not interact with other beams; a tile can have many beams passing through it at the same time. A tile is energized if that tile has at least one beam pass through it, reflect in it, or split in it.
|
||||
In the above example, here is how the beam of light bounces around the contraption:
|
||||
>|<<<\....
|
||||
|v-.\^....
|
||||
.v...|->>>
|
||||
.v...v^.|.
|
||||
.v...v^...
|
||||
.v...v^..\
|
||||
.v../2\\..
|
||||
<->-/vv|..
|
||||
.|<<<2-|.\
|
||||
.v//.|.v..
|
||||
|
||||
Beams are only shown on empty tiles; arrows indicate the direction of the beams. If a tile contains beams moving in multiple directions, the number of distinct directions is shown instead. Here is the same diagram but instead only showing whether a tile is energized (#) or not (.):
|
||||
######....
|
||||
.#...#....
|
||||
.#...#####
|
||||
.#...##...
|
||||
.#...##...
|
||||
.#...##...
|
||||
.#..####..
|
||||
########..
|
||||
.#######..
|
||||
.#...#.#..
|
||||
|
||||
Ultimately, in this example, 46 tiles become energized.
|
||||
The light isn't energizing enough tiles to produce lava; to debug the contraption, you need to start by analyzing the current situation. With the beam starting in the top-left heading right, how many tiles end up being energized?
|
||||
|
||||
https://adventofcode.com/2023/day/16
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -9,47 +9,7 @@ import kotlin.math.min
|
||||
|
||||
/*
|
||||
--- Day 17: Clumsy Crucible ---
|
||||
The lava starts flowing rapidly once the Lava Production Facility is operational. As you leave, the reindeer offers you a parachute, allowing you to quickly reach Gear Island.
|
||||
As you descend, your bird's-eye view of Gear Island reveals why you had trouble finding anyone on your way up: half of Gear Island is empty, but the half below you is a giant factory city!
|
||||
You land near the gradually-filling pool of lava at the base of your new lavafall. Lavaducts will eventually carry the lava throughout the city, but to make use of it immediately, Elves are loading it into large crucibles on wheels.
|
||||
The crucibles are top-heavy and pushed by hand. Unfortunately, the crucibles become very difficult to steer at high speeds, and so it can be hard to go in a straight line for very long.
|
||||
To get Desert Island the machine parts it needs as soon as possible, you'll need to find the best way to get the crucible from the lava pool to the machine parts factory. To do this, you need to minimize heat loss while choosing a route that doesn't require the crucible to go in a straight line for too long.
|
||||
Fortunately, the Elves here have a map (your puzzle input) that uses traffic patterns, ambient temperature, and hundreds of other parameters to calculate exactly how much heat loss can be expected for a crucible entering any particular city block.
|
||||
For example:
|
||||
2413432311323
|
||||
3215453535623
|
||||
3255245654254
|
||||
3446585845452
|
||||
4546657867536
|
||||
1438598798454
|
||||
4457876987766
|
||||
3637877979653
|
||||
4654967986887
|
||||
4564679986453
|
||||
1224686865563
|
||||
2546548887735
|
||||
4322674655533
|
||||
|
||||
Each city block is marked by a single digit that represents the amount of heat loss if the crucible enters that block. The starting point, the lava pool, is the top-left city block; the destination, the machine parts factory, is the bottom-right city block. (Because you already start in the top-left block, you don't incur that block's heat loss unless you leave that block and then return to it.)
|
||||
Because it is difficult to keep the top-heavy crucible going in a straight line for very long, it can move at most three blocks in a single direction before it must turn 90 degrees left or right. The crucible also can't reverse direction; after entering each city block, it may only turn left, continue straight, or turn right.
|
||||
One way to minimize heat loss is this path:
|
||||
2>>34^>>>1323
|
||||
32v>>>35v5623
|
||||
32552456v>>54
|
||||
3446585845v52
|
||||
4546657867v>6
|
||||
14385987984v4
|
||||
44578769877v6
|
||||
36378779796v>
|
||||
465496798688v
|
||||
456467998645v
|
||||
12246868655<v
|
||||
25465488877v5
|
||||
43226746555v>
|
||||
|
||||
This path never moves more than three consecutive blocks in the same direction and incurs a heat loss of only 102.
|
||||
Directing the crucible from the lava pool to the machine parts factory, but not moving more than three consecutive blocks in the same direction, what is the least heat loss it can incur?
|
||||
|
||||
https://adventofcode.com/2023/day/17
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -5,51 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 18: Lavaduct Lagoon ---
|
||||
Thanks to your efforts, the machine parts factory is one of the first factories up and running since the lavafall came back. However, to catch up with the large backlog of parts requests, the factory will also need a large supply of lava for a while; the Elves have already started creating a large lagoon nearby for this purpose.
|
||||
However, they aren't sure the lagoon will be big enough; they've asked you to take a look at the dig plan (your puzzle input). For example:
|
||||
R 6 (#70c710)
|
||||
D 5 (#0dc571)
|
||||
L 2 (#5713f0)
|
||||
D 2 (#d2c081)
|
||||
R 2 (#59c680)
|
||||
D 2 (#411b91)
|
||||
L 5 (#8ceee2)
|
||||
U 2 (#caa173)
|
||||
L 1 (#1b58a2)
|
||||
U 2 (#caa171)
|
||||
R 2 (#7807d2)
|
||||
U 3 (#a77fa3)
|
||||
L 2 (#015232)
|
||||
U 2 (#7a21e3)
|
||||
|
||||
The digger starts in a 1 meter cube hole in the ground. They then dig the specified number of meters up (U), down (D), left (L), or right (R), clearing full 1 meter cubes as they go. The directions are given as seen from above, so if "up" were north, then "right" would be east, and so on. Each trench is also listed with the color that the edge of the trench should be painted as an RGB hexadecimal color code.
|
||||
When viewed from above, the above example dig plan would result in the following loop of trench (#) having been dug out from otherwise ground-level terrain (.):
|
||||
#######
|
||||
#.....#
|
||||
###...#
|
||||
..#...#
|
||||
..#...#
|
||||
###.###
|
||||
#...#..
|
||||
##..###
|
||||
.#....#
|
||||
.######
|
||||
|
||||
At this point, the trench could contain 38 cubic meters of lava. However, this is just the edge of the lagoon; the next step is to dig out the interior so that it is one meter deep as well:
|
||||
#######
|
||||
#######
|
||||
#######
|
||||
..#####
|
||||
..#####
|
||||
#######
|
||||
#####..
|
||||
#######
|
||||
.######
|
||||
.######
|
||||
|
||||
Now, the lagoon can contain a much more respectable 62 cubic meters of lava. While the interior is dug out, the edges are also painted according to the color codes in the dig plan.
|
||||
The Elves are concerned the lagoon won't be large enough; if they follow their dig plan, how many cubic meters of lava could it hold?
|
||||
|
||||
https://adventofcode.com/2023/day/18
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -5,54 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 19: Aplenty ---
|
||||
The Elves of Gear Island are thankful for your help and send you on your way. They even have a hang glider that someone stole from Desert Island; since you're already going that direction, it would help them a lot if you would use it to get down there and return it to them.
|
||||
As you reach the bottom of the relentless avalanche of machine parts, you discover that they're already forming a formidable heap. Don't worry, though - a group of Elves is already here organizing the parts, and they have a system.
|
||||
To start, each part is rated in each of four categories:
|
||||
|
||||
x: Extremely cool looking
|
||||
m: Musical (it makes a noise when you hit it)
|
||||
a: Aerodynamic
|
||||
s: Shiny
|
||||
|
||||
Then, each part is sent through a series of workflows that will ultimately accept or reject the part. Each workflow has a name and contains a list of rules; each rule specifies a condition and where to send the part if the condition is true. The first rule that matches the part being considered is applied immediately, and the part moves on to the destination described by the rule. (The last rule in each workflow has no condition and always applies if reached.)
|
||||
Consider the workflow ex{x>10:one,m<20:two,a>30:R,A}. This workflow is named ex and contains four rules. If workflow ex were considering a specific part, it would perform the following steps in order:
|
||||
|
||||
Rule "x>10:one": If the part's x is more than 10, send the part to the workflow named one.
|
||||
Rule "m<20:two": Otherwise, if the part's m is less than 20, send the part to the workflow named two.
|
||||
Rule "a>30:R": Otherwise, if the part's a is more than 30, the part is immediately rejected (R).
|
||||
Rule "A": Otherwise, because no other rules matched the part, the part is immediately accepted (A).
|
||||
|
||||
If a part is sent to another workflow, it immediately switches to the start of that workflow instead and never returns. If a part is accepted (sent to A) or rejected (sent to R), the part immediately stops any further processing.
|
||||
The system works, but it's not keeping up with the torrent of weird metal shapes. The Elves ask if you can help sort a few parts and give you the list of workflows and some part ratings (your puzzle input). For example:
|
||||
px{a<2006:qkq,m>2090:A,rfg}
|
||||
pv{a>1716:R,A}
|
||||
lnx{m>1548:A,A}
|
||||
rfg{s<537:gd,x>2440:R,A}
|
||||
qs{s>3448:A,lnx}
|
||||
qkq{x<1416:A,crn}
|
||||
crn{x>2662:A,R}
|
||||
in{s<1351:px,qqz}
|
||||
qqz{s>2770:qs,m<1801:hdj,R}
|
||||
gd{a>3333:R,R}
|
||||
hdj{m>838:A,pv}
|
||||
|
||||
{x=787,m=2655,a=1222,s=2876}
|
||||
{x=1679,m=44,a=2067,s=496}
|
||||
{x=2036,m=264,a=79,s=2244}
|
||||
{x=2461,m=1339,a=466,s=291}
|
||||
{x=2127,m=1623,a=2188,s=1013}
|
||||
|
||||
The workflows are listed first, followed by a blank line, then the ratings of the parts the Elves would like you to sort. All parts begin in the workflow named in. In this example, the five listed parts go through the following workflows:
|
||||
|
||||
{x=787,m=2655,a=1222,s=2876}: in -> qqz -> qs -> lnx -> A
|
||||
{x=1679,m=44,a=2067,s=496}: in -> px -> rfg -> gd -> R
|
||||
{x=2036,m=264,a=79,s=2244}: in -> qqz -> hdj -> pv -> A
|
||||
{x=2461,m=1339,a=466,s=291}: in -> px -> qkq -> crn -> R
|
||||
{x=2127,m=1623,a=2188,s=1013}: in -> px -> rfg -> A
|
||||
|
||||
Ultimately, three parts are accepted. Adding up the x, m, a, and s rating for each of the accepted parts gives 7540 for the part with x=787, 4623 for the part with x=2036, and 6951 for the part with x=2127. Adding all of the ratings for all of the accepted parts gives the sum total of 19114.
|
||||
Sort through all of the parts you've been given; what do you get if you add together all of the rating numbers for all of the parts that ultimately get accepted?
|
||||
|
||||
https://adventofcode.com/2023/day/19
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -6,91 +6,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 20: Pulse Propagation ---
|
||||
With your help, the Elves manage to find the right parts and fix all of the machines. Now, they just need to send the command to boot up the machines and get the sand flowing again.
|
||||
The machines are far apart and wired together with long cables. The cables don't connect to the machines directly, but rather to communication modules attached to the machines that perform various initialization tasks and also act as communication relays.
|
||||
Modules communicate using pulses. Each pulse is either a high pulse or a low pulse. When a module sends a pulse, it sends that type of pulse to each module in its list of destination modules.
|
||||
There are several different types of modules:
|
||||
Flip-flop modules (prefix %) are either on or off; they are initially off. If a flip-flop module receives a high pulse, it is ignored and nothing happens. However, if a flip-flop module receives a low pulse, it flips between on and off. If it was off, it turns on and sends a high pulse. If it was on, it turns off and sends a low pulse.
|
||||
Conjunction modules (prefix &) remember the type of the most recent pulse received from each of their connected input modules; they initially default to remembering a low pulse for each input. When a pulse is received, the conjunction module first updates its memory for that input. Then, if it remembers high pulses for all inputs, it sends a low pulse; otherwise, it sends a high pulse.
|
||||
There is a single broadcast module (named broadcaster). When it receives a pulse, it sends the same pulse to all of its destination modules.
|
||||
Here at Desert Machine Headquarters, there is a module with a single button on it called, aptly, the button module. When you push the button, a single low pulse is sent directly to the broadcaster module.
|
||||
After pushing the button, you must wait until all pulses have been delivered and fully handled before pushing it again. Never push the button if modules are still processing pulses.
|
||||
Pulses are always processed in the order they are sent. So, if a pulse is sent to modules a, b, and c, and then module a processes its pulse and sends more pulses, the pulses sent to modules b and c would have to be handled first.
|
||||
The module configuration (your puzzle input) lists each module. The name of the module is preceded by a symbol identifying its type, if any. The name is then followed by an arrow and a list of its destination modules. For example:
|
||||
broadcaster -> a, b, c
|
||||
%a -> b
|
||||
%b -> c
|
||||
%c -> inv
|
||||
&inv -> a
|
||||
|
||||
In this module configuration, the broadcaster has three destination modules named a, b, and c. Each of these modules is a flip-flop module (as indicated by the % prefix). a outputs to b which outputs to c which outputs to another module named inv. inv is a conjunction module (as indicated by the & prefix) which, because it has only one input, acts like an inverter (it sends the opposite of the pulse type it receives); it outputs to a.
|
||||
By pushing the button once, the following pulses are sent:
|
||||
button -low-> broadcaster
|
||||
broadcaster -low-> a
|
||||
broadcaster -low-> b
|
||||
broadcaster -low-> c
|
||||
a -high-> b
|
||||
b -high-> c
|
||||
c -high-> inv
|
||||
inv -low-> a
|
||||
a -low-> b
|
||||
b -low-> c
|
||||
c -low-> inv
|
||||
inv -high-> a
|
||||
|
||||
After this sequence, the flip-flop modules all end up off, so pushing the button again repeats the same sequence.
|
||||
Here's a more interesting example:
|
||||
broadcaster -> a
|
||||
%a -> inv, con
|
||||
&inv -> b
|
||||
%b -> con
|
||||
&con -> output
|
||||
|
||||
This module configuration includes the broadcaster, two flip-flops (named a and b), a single-input conjunction module (inv), a multi-input conjunction module (con), and an untyped module named output (for testing purposes). The multi-input conjunction module con watches the two flip-flop modules and, if they're both on, sends a low pulse to the output module.
|
||||
Here's what happens if you push the button once:
|
||||
button -low-> broadcaster
|
||||
broadcaster -low-> a
|
||||
a -high-> inv
|
||||
a -high-> con
|
||||
inv -low-> b
|
||||
con -high-> output
|
||||
b -high-> con
|
||||
con -low-> output
|
||||
|
||||
Both flip-flops turn on and a low pulse is sent to output! However, now that both flip-flops are on and con remembers a high pulse from each of its two inputs, pushing the button a second time does something different:
|
||||
button -low-> broadcaster
|
||||
broadcaster -low-> a
|
||||
a -low-> inv
|
||||
a -low-> con
|
||||
inv -high-> b
|
||||
con -high-> output
|
||||
|
||||
Flip-flop a turns off! Now, con remembers a low pulse from module a, and so it sends only a high pulse to output.
|
||||
Push the button a third time:
|
||||
button -low-> broadcaster
|
||||
broadcaster -low-> a
|
||||
a -high-> inv
|
||||
a -high-> con
|
||||
inv -low-> b
|
||||
con -low-> output
|
||||
b -low-> con
|
||||
con -high-> output
|
||||
|
||||
This time, flip-flop a turns on, then flip-flop b turns off. However, before b can turn off, the pulse sent to con is handled first, so it briefly remembers all high pulses for its inputs and sends a low pulse to output. After that, flip-flop b turns off, which causes con to update its state and send a high pulse to output.
|
||||
Finally, with a on and b off, push the button a fourth time:
|
||||
button -low-> broadcaster
|
||||
broadcaster -low-> a
|
||||
a -low-> inv
|
||||
a -low-> con
|
||||
inv -high-> b
|
||||
con -high-> output
|
||||
|
||||
This completes the cycle: a turns off, causing con to remember only low pulses and restoring all modules to their original states.
|
||||
To get the cables warmed up, the Elves have pushed the button 1000 times. How many pulses got sent as a result (including the pulses sent by the button itself)?
|
||||
In the first example, the same thing happens every time the button is pushed: 8 low pulses and 4 high pulses are sent. So, after pushing the button 1000 times, 8000 low pulses and 4000 high pulses are sent. Multiplying these together gives 32000000.
|
||||
In the second example, after pushing the button 1000 times, 4250 low pulses and 2750 high pulses are sent. Multiplying these together gives 11687500.
|
||||
Consult your module configuration; determine the number of low pulses and high pulses that would be sent after pushing the button 1000 times, waiting for all pulses to be fully handled after each push of the button. What do you get if you multiply the total number of low pulses sent by the total number of high pulses sent?
|
||||
|
||||
https://adventofcode.com/2023/day/20
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -7,79 +7,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 21: Step Counter ---
|
||||
You manage to catch the airship right as it's dropping someone else off on their all-expenses-paid trip to Desert Island! It even helpfully drops you off near the gardener and his massive farm.
|
||||
"You got the sand flowing again! Great work! Now we just need to wait until we have enough sand to filter the water for Snow Island and we'll have snow again in no time."
|
||||
While you wait, one of the Elves that works with the gardener heard how good you are at solving problems and would like your help. He needs to get his steps in for the day, and so he'd like to know which garden plots he can reach with exactly his remaining 64 steps.
|
||||
He gives you an up-to-date map (your puzzle input) of his starting position (S), garden plots (.), and rocks (#). For example:
|
||||
...........
|
||||
.....###.#.
|
||||
.###.##..#.
|
||||
..#.#...#..
|
||||
....#.#....
|
||||
.##..S####.
|
||||
.##..#...#.
|
||||
.......##..
|
||||
.##.#.####.
|
||||
.##..##.##.
|
||||
...........
|
||||
|
||||
The Elf starts at the starting position (S) which also counts as a garden plot. Then, he can take one step north, south, east, or west, but only onto tiles that are garden plots. This would allow him to reach any of the tiles marked O:
|
||||
...........
|
||||
.....###.#.
|
||||
.###.##..#.
|
||||
..#.#...#..
|
||||
....#O#....
|
||||
.##.OS####.
|
||||
.##..#...#.
|
||||
.......##..
|
||||
.##.#.####.
|
||||
.##..##.##.
|
||||
...........
|
||||
|
||||
Then, he takes a second step. Since at this point he could be at either tile marked O, his second step would allow him to reach any garden plot that is one step north, south, east, or west of any tile that he could have reached after the first step:
|
||||
...........
|
||||
.....###.#.
|
||||
.###.##..#.
|
||||
..#.#O..#..
|
||||
....#.#....
|
||||
.##O.O####.
|
||||
.##.O#...#.
|
||||
.......##..
|
||||
.##.#.####.
|
||||
.##..##.##.
|
||||
...........
|
||||
|
||||
After two steps, he could be at any of the tiles marked O above, including the starting position (either by going north-then-south or by going west-then-east).
|
||||
A single third step leads to even more possibilities:
|
||||
...........
|
||||
.....###.#.
|
||||
.###.##..#.
|
||||
..#.#.O.#..
|
||||
...O#O#....
|
||||
.##.OS####.
|
||||
.##O.#...#.
|
||||
....O..##..
|
||||
.##.#.####.
|
||||
.##..##.##.
|
||||
...........
|
||||
|
||||
He will continue like this until his steps for the day have been exhausted. After a total of 6 steps, he could reach any of the garden plots marked O:
|
||||
...........
|
||||
.....###.#.
|
||||
.###.##.O#.
|
||||
.O#O#O.O#..
|
||||
O.O.#.#.O..
|
||||
.##O.O####.
|
||||
.##.O#O..#.
|
||||
.O.O.O.##..
|
||||
.##.#.####.
|
||||
.##O.##.##.
|
||||
...........
|
||||
|
||||
In this example, if the Elf's goal was to get exactly 6 more steps today, he could use them to reach any of 16 garden plots.
|
||||
However, the Elf actually needs to get 64 steps today, and the map he's handed you is much larger than the example map.
|
||||
Starting from the garden plot marked S on your map, how many garden plots could the Elf reach in exactly 64 steps?
|
||||
|
||||
https://adventofcode.com/2023/day/21
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -5,108 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 22: Sand Slabs ---
|
||||
Enough sand has fallen; it can finally filter water for Snow Island.
|
||||
Well, almost.
|
||||
The sand has been falling as large compacted bricks of sand, piling up to form an impressive stack here near the edge of Island Island. In order to make use of the sand to filter water, some of the bricks will need to be broken apart - nay, disintegrated - back into freely flowing sand.
|
||||
The stack is tall enough that you'll have to be careful about choosing which bricks to disintegrate; if you disintegrate the wrong brick, large portions of the stack could topple, which sounds pretty dangerous.
|
||||
The Elves responsible for water filtering operations took a snapshot of the bricks while they were still falling (your puzzle input) which should let you work out which bricks are safe to disintegrate. For example:
|
||||
1,0,1~1,2,1
|
||||
0,0,2~2,0,2
|
||||
0,2,3~2,2,3
|
||||
0,0,4~0,2,4
|
||||
2,0,5~2,2,5
|
||||
0,1,6~2,1,6
|
||||
1,1,8~1,1,9
|
||||
|
||||
Each line of text in the snapshot represents the position of a single brick at the time the snapshot was taken. The position is given as two x,y,z coordinates - one for each end of the brick - separated by a tilde (~). Each brick is made up of a single straight line of cubes, and the Elves were even careful to choose a time for the snapshot that had all of the free-falling bricks at integer positions above the ground, so the whole snapshot is aligned to a three-dimensional cube grid.
|
||||
A line like 2,2,2~2,2,2 means that both ends of the brick are at the same coordinate - in other words, that the brick is a single cube.
|
||||
Lines like 0,0,10~1,0,10 or 0,0,10~0,1,10 both represent bricks that are two cubes in volume, both oriented horizontally. The first brick extends in the x direction, while the second brick extends in the y direction.
|
||||
A line like 0,0,1~0,0,10 represents a ten-cube brick which is oriented vertically. One end of the brick is the cube located at 0,0,1, while the other end of the brick is located directly above it at 0,0,10.
|
||||
The ground is at z=0 and is perfectly flat; the lowest z value a brick can have is therefore 1. So, 5,5,1~5,6,1 and 0,2,1~0,2,5 are both resting on the ground, but 3,3,2~3,3,3 was above the ground at the time of the snapshot.
|
||||
Because the snapshot was taken while the bricks were still falling, some bricks will still be in the air; you'll need to start by figuring out where they will end up. Bricks are magically stabilized, so they never rotate, even in weird situations like where a long horizontal brick is only supported on one end. Two bricks cannot occupy the same position, so a falling brick will come to rest upon the first other brick it encounters.
|
||||
Here is the same example again, this time with each brick given a letter so it can be marked in diagrams:
|
||||
1,0,1~1,2,1 <- A
|
||||
0,0,2~2,0,2 <- B
|
||||
0,2,3~2,2,3 <- C
|
||||
0,0,4~0,2,4 <- D
|
||||
2,0,5~2,2,5 <- E
|
||||
0,1,6~2,1,6 <- F
|
||||
1,1,8~1,1,9 <- G
|
||||
|
||||
At the time of the snapshot, from the side so the x axis goes left to right, these bricks are arranged like this:
|
||||
x
|
||||
012
|
||||
.G. 9
|
||||
.G. 8
|
||||
... 7
|
||||
FFF 6
|
||||
..E 5 z
|
||||
D.. 4
|
||||
CCC 3
|
||||
BBB 2
|
||||
.A. 1
|
||||
--- 0
|
||||
|
||||
Rotating the perspective 90 degrees so the y axis now goes left to right, the same bricks are arranged like this:
|
||||
y
|
||||
012
|
||||
.G. 9
|
||||
.G. 8
|
||||
... 7
|
||||
.F. 6
|
||||
EEE 5 z
|
||||
DDD 4
|
||||
..C 3
|
||||
B.. 2
|
||||
AAA 1
|
||||
--- 0
|
||||
|
||||
Once all of the bricks fall downward as far as they can go, the stack looks like this, where ? means bricks are hidden behind other bricks at that location:
|
||||
x
|
||||
012
|
||||
.G. 6
|
||||
.G. 5
|
||||
FFF 4
|
||||
D.E 3 z
|
||||
??? 2
|
||||
.A. 1
|
||||
--- 0
|
||||
|
||||
Again from the side:
|
||||
y
|
||||
012
|
||||
.G. 6
|
||||
.G. 5
|
||||
.F. 4
|
||||
??? 3 z
|
||||
B.C 2
|
||||
AAA 1
|
||||
--- 0
|
||||
|
||||
Now that all of the bricks have settled, it becomes easier to tell which bricks are supporting which other bricks:
|
||||
|
||||
Brick A is the only brick supporting bricks B and C.
|
||||
Brick B is one of two bricks supporting brick D and brick E.
|
||||
Brick C is the other brick supporting brick D and brick E.
|
||||
Brick D supports brick F.
|
||||
Brick E also supports brick F.
|
||||
Brick F supports brick G.
|
||||
Brick G isn't supporting any bricks.
|
||||
|
||||
Your first task is to figure out which bricks are safe to disintegrate. A brick can be safely disintegrated if, after removing it, no other bricks would fall further directly downward. Don't actually disintegrate any bricks - just determine what would happen if, for each brick, only that brick were disintegrated. Bricks can be disintegrated even if they're completely surrounded by other bricks; you can squeeze between bricks if you need to.
|
||||
In this example, the bricks can be disintegrated as follows:
|
||||
|
||||
Brick A cannot be disintegrated safely; if it were disintegrated, bricks B and C would both fall.
|
||||
Brick B can be disintegrated; the bricks above it (D and E) would still be supported by brick C.
|
||||
Brick C can be disintegrated; the bricks above it (D and E) would still be supported by brick B.
|
||||
Brick D can be disintegrated; the brick above it (F) would still be supported by brick E.
|
||||
Brick E can be disintegrated; the brick above it (F) would still be supported by brick D.
|
||||
Brick F cannot be disintegrated; the brick above it (G) would fall.
|
||||
Brick G can be disintegrated; it does not support any other bricks.
|
||||
|
||||
So, in this example, 5 bricks can be safely disintegrated.
|
||||
Figure how the blocks will settle based on the snapshot. Once they've settled, consider disintegrating a single brick; how many bricks could be safely chosen as the one to get disintegrated?
|
||||
|
||||
https://adventofcode.com/2023/day/22
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -7,64 +7,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 23: A Long Walk ---
|
||||
The Elves resume water filtering operations! Clean water starts flowing over the edge of Island Island.
|
||||
They offer to help you go over the edge of Island Island, too! Just hold on tight to one end of this impossibly long rope and they'll lower you down a safe distance from the massive waterfall you just created.
|
||||
As you finally reach Snow Island, you see that the water isn't really reaching the ground: it's being absorbed by the air itself. It looks like you'll finally have a little downtime while the moisture builds up to snow-producing levels. Snow Island is pretty scenic, even without any snow; why not take a walk?
|
||||
There's a map of nearby hiking trails (your puzzle input) that indicates paths (.), forest (#), and steep slopes (^, >, v, and <).
|
||||
For example:
|
||||
#.#####################
|
||||
#.......#########...###
|
||||
#######.#########.#.###
|
||||
###.....#.>.>.###.#.###
|
||||
###v#####.#v#.###.#.###
|
||||
###.>...#.#.#.....#...#
|
||||
###v###.#.#.#########.#
|
||||
###...#.#.#.......#...#
|
||||
#####.#.#.#######.#.###
|
||||
#.....#.#.#.......#...#
|
||||
#.#####.#.#.#########v#
|
||||
#.#...#...#...###...>.#
|
||||
#.#.#v#######v###.###v#
|
||||
#...#.>.#...>.>.#.###.#
|
||||
#####v#.#.###v#.#.###.#
|
||||
#.....#...#...#.#.#...#
|
||||
#.#########.###.#.#.###
|
||||
#...###...#...#...#.###
|
||||
###.###.#.###v#####v###
|
||||
#...#...#.#.>.>.#.>.###
|
||||
#.###.###.#.###.#.#v###
|
||||
#.....###...###...#...#
|
||||
#####################.#
|
||||
|
||||
You're currently on the single path tile in the top row; your goal is to reach the single path tile in the bottom row. Because of all the mist from the waterfall, the slopes are probably quite icy; if you step onto a slope tile, your next step must be downhill (in the direction the arrow is pointing). To make sure you have the most scenic hike possible, never step onto the same tile twice. What is the longest hike you can take?
|
||||
In the example above, the longest hike you can take is marked with O, and your starting position is marked S:
|
||||
#S#####################
|
||||
#OOOOOOO#########...###
|
||||
#######O#########.#.###
|
||||
###OOOOO#OOO>.###.#.###
|
||||
###O#####O#O#.###.#.###
|
||||
###OOOOO#O#O#.....#...#
|
||||
###v###O#O#O#########.#
|
||||
###...#O#O#OOOOOOO#...#
|
||||
#####.#O#O#######O#.###
|
||||
#.....#O#O#OOOOOOO#...#
|
||||
#.#####O#O#O#########v#
|
||||
#.#...#OOO#OOO###OOOOO#
|
||||
#.#.#v#######O###O###O#
|
||||
#...#.>.#...>OOO#O###O#
|
||||
#####v#.#.###v#O#O###O#
|
||||
#.....#...#...#O#O#OOO#
|
||||
#.#########.###O#O#O###
|
||||
#...###...#...#OOO#O###
|
||||
###.###.#.###v#####O###
|
||||
#...#...#.#.>.>.#.>O###
|
||||
#.###.###.#.###.#.#O###
|
||||
#.....###...###...#OOO#
|
||||
#####################O#
|
||||
|
||||
This hike contains 94 steps. (The other possible hikes you could have taken were 90, 86, 82, 82, and 74 steps long.)
|
||||
Find the longest hike you can take through the hiking trails listed on your map. How many steps long is the longest hike?
|
||||
|
||||
https://adventofcode.com/2023/day/23
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -10,64 +10,7 @@ import kotlin.math.sign
|
||||
|
||||
/*
|
||||
--- Day 24: Never Tell Me The Odds ---
|
||||
It seems like something is going wrong with the snow-making process. Instead of forming snow, the water that's been absorbed into the air seems to be forming hail!
|
||||
Maybe there's something you can do to break up the hailstones?
|
||||
Due to strong, probably-magical winds, the hailstones are all flying through the air in perfectly linear trajectories. You make a note of each hailstone's position and velocity (your puzzle input). For example:
|
||||
19, 13, 30 @ -2, 1, -2
|
||||
18, 19, 22 @ -1, -1, -2
|
||||
20, 25, 34 @ -2, -2, -4
|
||||
12, 31, 28 @ -1, -2, -1
|
||||
20, 19, 15 @ 1, -5, -3
|
||||
|
||||
Each line of text corresponds to the position and velocity of a single hailstone. The positions indicate where the hailstones are right now (at time 0). The velocities are constant and indicate exactly how far each hailstone will move in one nanosecond.
|
||||
Each line of text uses the format px py pz @ vx vy vz. For instance, the hailstone specified by 20, 19, 15 @ 1, -5, -3 has initial X position 20, Y position 19, Z position 15, X velocity 1, Y velocity -5, and Z velocity -3. After one nanosecond, the hailstone would be at 21, 14, 12.
|
||||
Perhaps you won't have to do anything. How likely are the hailstones to collide with each other and smash into tiny ice crystals?
|
||||
To estimate this, consider only the X and Y axes; ignore the Z axis. Looking forward in time, how many of the hailstones' paths will intersect within a test area? (The hailstones themselves don't have to collide, just test for intersections between the paths they will trace.)
|
||||
In this example, look for intersections that happen with an X and Y position each at least 7 and at most 27; in your actual data, you'll need to check a much larger test area. Comparing all pairs of hailstones' future paths produces the following results:
|
||||
Hailstone A: 19, 13, 30 @ -2, 1, -2
|
||||
Hailstone B: 18, 19, 22 @ -1, -1, -2
|
||||
Hailstones' paths will cross inside the test area (at x=14.333, y=15.333).
|
||||
|
||||
Hailstone A: 19, 13, 30 @ -2, 1, -2
|
||||
Hailstone B: 20, 25, 34 @ -2, -2, -4
|
||||
Hailstones' paths will cross inside the test area (at x=11.667, y=16.667).
|
||||
|
||||
Hailstone A: 19, 13, 30 @ -2, 1, -2
|
||||
Hailstone B: 12, 31, 28 @ -1, -2, -1
|
||||
Hailstones' paths will cross outside the test area (at x=6.2, y=19.4).
|
||||
|
||||
Hailstone A: 19, 13, 30 @ -2, 1, -2
|
||||
Hailstone B: 20, 19, 15 @ 1, -5, -3
|
||||
Hailstones' paths crossed in the past for hailstone A.
|
||||
|
||||
Hailstone A: 18, 19, 22 @ -1, -1, -2
|
||||
Hailstone B: 20, 25, 34 @ -2, -2, -4
|
||||
Hailstones' paths are parallel; they never intersect.
|
||||
|
||||
Hailstone A: 18, 19, 22 @ -1, -1, -2
|
||||
Hailstone B: 12, 31, 28 @ -1, -2, -1
|
||||
Hailstones' paths will cross outside the test area (at x=-6, y=-5).
|
||||
|
||||
Hailstone A: 18, 19, 22 @ -1, -1, -2
|
||||
Hailstone B: 20, 19, 15 @ 1, -5, -3
|
||||
Hailstones' paths crossed in the past for both hailstones.
|
||||
|
||||
Hailstone A: 20, 25, 34 @ -2, -2, -4
|
||||
Hailstone B: 12, 31, 28 @ -1, -2, -1
|
||||
Hailstones' paths will cross outside the test area (at x=-2, y=3).
|
||||
|
||||
Hailstone A: 20, 25, 34 @ -2, -2, -4
|
||||
Hailstone B: 20, 19, 15 @ 1, -5, -3
|
||||
Hailstones' paths crossed in the past for hailstone B.
|
||||
|
||||
Hailstone A: 12, 31, 28 @ -1, -2, -1
|
||||
Hailstone B: 20, 19, 15 @ 1, -5, -3
|
||||
Hailstones' paths crossed in the past for both hailstones.
|
||||
|
||||
So, in this example, 2 hailstones' future paths cross inside the boundaries of the test area.
|
||||
However, you'll need to search a much larger test area if you want to see if any hailstones might collide. Look for intersections that happen with an X and Y position each at least 200000000000000 and at most 400000000000000. Disregard the Z axis entirely.
|
||||
Considering only the X and Y axes, check all pairs of hailstones' future paths for intersections. How many of these intersections occur within the test area?
|
||||
|
||||
https://adventofcode.com/2023/day/24
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -5,43 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 25: Snowverload ---
|
||||
Still somehow without snow, you go to the last place you haven't checked: the center of Snow Island, directly below the waterfall.
|
||||
Here, someone has clearly been trying to fix the problem. Scattered everywhere are hundreds of weather machines, almanacs, communication modules, hoof prints, machine parts, mirrors, lenses, and so on.
|
||||
Somehow, everything has been wired together into a massive snow-producing apparatus, but nothing seems to be running. You check a tiny screen on one of the communication modules: Error 2023. It doesn't say what Error 2023 means, but it does have the phone number for a support line printed on it.
|
||||
"Hi, you've reached Weather Machines And So On, Inc. How can I help you?" You explain the situation.
|
||||
"Error 2023, you say? Why, that's a power overload error, of course! It means you have too many components plugged in. Try unplugging some components and--" You explain that there are hundreds of components here and you're in a bit of a hurry.
|
||||
"Well, let's see how bad it is; do you see a big red reset button somewhere? It should be on its own module. If you push it, it probably won't fix anything, but it'll report how overloaded things are." After a minute or two, you find the reset button; it's so big that it takes two hands just to get enough leverage to push it. Its screen then displays:
|
||||
SYSTEM OVERLOAD!
|
||||
|
||||
Connected components would require
|
||||
power equal to at least 100 stars!
|
||||
|
||||
"Wait, how many components did you say are plugged in? With that much equipment, you could produce snow for an entire--" You disconnect the call.
|
||||
You have nowhere near that many stars - you need to find a way to disconnect at least half of the equipment here, but it's already Christmas! You only have time to disconnect three wires.
|
||||
Fortunately, someone left a wiring diagram (your puzzle input) that shows how the components are connected. For example:
|
||||
jqt: rhn xhk nvd
|
||||
rsh: frs pzl lsr
|
||||
xhk: hfx
|
||||
cmg: qnr nvd lhk bvb
|
||||
rhn: xhk bvb hfx
|
||||
bvb: xhk hfx
|
||||
pzl: lsr hfx nvd
|
||||
qnr: nvd
|
||||
ntq: jqt hfx bvb xhk
|
||||
nvd: lhk
|
||||
lsr: lhk
|
||||
rzs: qnr cmg lsr rsh
|
||||
frs: qnr lhk lsr
|
||||
|
||||
Each line shows the name of a component, a colon, and then a list of other components to which that component is connected. Connections aren't directional; abc: xyz and xyz: abc both represent the same configuration. Each connection between two components is represented only once, so some components might only ever appear on the left or right side of a colon.
|
||||
In this example, if you disconnect the wire between hfx/pzl, the wire between bvb/cmg, and the wire between nvd/jqt, you will divide the components into two separate, disconnected groups:
|
||||
|
||||
9 components: cmg, frs, lhk, lsr, nvd, pzl, qnr, rsh, and rzs.
|
||||
6 components: bvb, hfx, jqt, ntq, rhn, and xhk.
|
||||
|
||||
Multiplying the sizes of these groups together produces 54.
|
||||
Find the three wires you need to disconnect in order to divide the components into two separate groups. What do you get if you multiply the sizes of these two groups together?
|
||||
|
||||
https://adventofcode.com/2023/day/25
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -7,35 +7,7 @@ import kotlin.math.abs
|
||||
|
||||
/*
|
||||
--- Day 1: Historian Hysteria ---
|
||||
The Chief Historian is always present for the big Christmas sleigh launch, but nobody has seen him in months! Last anyone heard, he was visiting locations that are historically significant to the North Pole; a group of Senior Historians has asked you to accompany them as they check the places they think he was most likely to visit.
|
||||
As each location is checked, they will mark it on their list with a star. They figure the Chief Historian must be in one of the first fifty places they'll look, so in order to save Christmas, you need to help them get fifty stars on their list before Santa takes off on December 25th.
|
||||
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
|
||||
You haven't even left yet and the group of Elvish Senior Historians has already hit a problem: their list of locations to check is currently empty. Eventually, someone decides that the best place to check first would be the Chief Historian's office.
|
||||
Upon pouring into the office, everyone confirms that the Chief Historian is indeed nowhere to be found. Instead, the Elves discover an assortment of notes and lists of historically significant locations! This seems to be the planning the Chief Historian was doing before he left. Perhaps these notes can be used to determine which locations to search?
|
||||
Throughout the Chief's office, the historically significant locations are listed not by name but by a unique number called the location ID. To make sure they don't miss anything, The Historians split into two groups, each searching the office and trying to create their own complete list of location IDs.
|
||||
There's just one problem: by holding the two lists up side by side (your puzzle input), it quickly becomes clear that the lists aren't very similar. Maybe you can help The Historians reconcile their lists?
|
||||
For example:
|
||||
3 4
|
||||
4 3
|
||||
2 5
|
||||
1 3
|
||||
3 9
|
||||
3 3
|
||||
|
||||
Maybe the lists are only off by a small amount! To find out, pair up the numbers and measure how far apart they are. Pair up the smallest number in the left list with the smallest number in the right list, then the second-smallest left number with the second-smallest right number, and so on.
|
||||
Within each pair, figure out how far apart the two numbers are; you'll need to add up all of those distances. For example, if you pair up a 3 from the left list with a 7 from the right list, the distance apart is 4; if you pair up a 9 with a 3, the distance apart is 6.
|
||||
In the example list above, the pairs and distances would be as follows:
|
||||
|
||||
The smallest number in the left list is 1, and the smallest number in the right list is 3. The distance between them is 2.
|
||||
The second-smallest number in the left list is 2, and the second-smallest number in the right list is another 3. The distance between them is 1.
|
||||
The third-smallest number in both lists is 3, so the distance between them is 0.
|
||||
The next numbers to pair up are 3 and 4, a distance of 1.
|
||||
The fifth-smallest numbers in each list are 3 and 5, a distance of 2.
|
||||
Finally, the largest number in the left list is 4, while the largest number in the right list is 9; these are a distance 5 apart.
|
||||
|
||||
To find the total distance between the left list and the right list, add up the distances between all of the pairs you found. In the example above, this is 2 + 1 + 0 + 1 + 2 + 5, a total distance of 11!
|
||||
Your actual left and right lists contain many location IDs. What is the total distance between your lists?
|
||||
|
||||
https://adventofcode.com/2024/day/1
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -6,35 +6,7 @@ import splitInts
|
||||
|
||||
/*
|
||||
--- Day 2: Red-Nosed Reports ---
|
||||
Fortunately, the first location The Historians want to search isn't a long walk from the Chief Historian's office.
|
||||
While the Red-Nosed Reindeer nuclear fusion/fission plant appears to contain no sign of the Chief Historian, the engineers there run up to you as soon as they see you. Apparently, they still talk about the time Rudolph was saved through molecular synthesis from a single electron.
|
||||
They're quick to add that - since you're already here - they'd really appreciate your help analyzing some unusual data from the Red-Nosed reactor. You turn to check if The Historians are waiting for you, but they seem to have already divided into groups that are currently searching every corner of the facility. You offer to help with the unusual data.
|
||||
The unusual data (your puzzle input) consists of many reports, one report per line. Each report is a list of numbers called levels that are separated by spaces. For example:
|
||||
7 6 4 2 1
|
||||
1 2 7 8 9
|
||||
9 7 6 2 1
|
||||
1 3 2 4 5
|
||||
8 6 4 4 1
|
||||
1 3 6 7 9
|
||||
|
||||
This example data contains six reports each containing five levels.
|
||||
The engineers are trying to figure out which reports are safe. The Red-Nosed reactor safety systems can only tolerate levels that are either gradually increasing or gradually decreasing. So, a report only counts as safe if both of the following are true:
|
||||
|
||||
The levels are either all increasing or all decreasing.
|
||||
Any two adjacent levels differ by at least one and at most three.
|
||||
|
||||
In the example above, the reports can be found safe or unsafe by checking those rules:
|
||||
|
||||
7 6 4 2 1: Safe because the levels are all decreasing by 1 or 2.
|
||||
1 2 7 8 9: Unsafe because 2 7 is an increase of 5.
|
||||
9 7 6 2 1: Unsafe because 6 2 is a decrease of 4.
|
||||
1 3 2 4 5: Unsafe because 1 3 is increasing but 3 2 is decreasing.
|
||||
8 6 4 4 1: Unsafe because 4 4 is neither an increase or a decrease.
|
||||
1 3 6 7 9: Safe because the levels are all increasing by 1, 2, or 3.
|
||||
|
||||
So, in this example, 2 reports are safe.
|
||||
Analyze the unusual data from the engineers. How many reports are safe?
|
||||
|
||||
https://adventofcode.com/2024/day/2
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -5,16 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 3: Mull It Over ---
|
||||
"Our computers are having issues, so I have no idea if we have any Chief Historians in stock! You're welcome to check the warehouse, though," says the mildly flustered shopkeeper at the North Pole Toboggan Rental Shop. The Historians head out to take a look.
|
||||
The shopkeeper turns to you. "Any chance you can see why our computers are having issues again?"
|
||||
The computer appears to be trying to run a program, but its memory (your puzzle input) is corrupted. All of the instructions have been jumbled up!
|
||||
It seems like the goal of the program is just to multiply some numbers. It does that with instructions like mul(X,Y), where X and Y are each 1-3 digit numbers. For instance, mul(44,46) multiplies 44 by 46 to get a result of 2024. Similarly, mul(123,4) would multiply 123 by 4.
|
||||
However, because the program's memory has been corrupted, there are also many invalid characters that should be ignored, even if they look like part of a mul instruction. Sequences like mul(4*, mul(6,9!, ?(12,34), or mul ( 2 , 4 ) do nothing.
|
||||
For example, consider the following section of corrupted memory:
|
||||
xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))
|
||||
Only the four highlighted sections are real mul instructions. Adding up the result of each instruction produces 161 (2*4 + 5*5 + 11*8 + 8*5).
|
||||
Scan the corrupted memory for uncorrupted mul instructions. What do you get if you add up all of the results of the multiplications?
|
||||
|
||||
https://adventofcode.com/2024/day/3
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -7,41 +7,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 4: Ceres Search ---
|
||||
"Looks like the Chief's not here. Next!" One of The Historians pulls out a device and pushes the only button on it. After a brief flash, you recognize the interior of the Ceres monitoring station!
|
||||
As the search for the Chief continues, a small Elf who lives on the station tugs on your shirt; she'd like to know if you could help her with her word search (your puzzle input). She only has to find one word: XMAS.
|
||||
This word search allows words to be horizontal, vertical, diagonal, written backwards, or even overlapping other words. It's a little unusual, though, as you don't merely need to find one instance of XMAS - you need to find all of them. Here are a few ways XMAS might appear, where irrelevant characters have been replaced with .:
|
||||
..X...
|
||||
.SAMX.
|
||||
.A..A.
|
||||
XMAS.S
|
||||
.X....
|
||||
|
||||
The actual word search will be full of letters instead. For example:
|
||||
MMMSXXMASM
|
||||
MSAMXMSMSA
|
||||
AMXSXMAAMM
|
||||
MSAMASMSMX
|
||||
XMASAMXAMM
|
||||
XXAMMXXAMA
|
||||
SMSMSASXSS
|
||||
SAXAMASAAA
|
||||
MAMMMXMMMM
|
||||
MXMXAXMASX
|
||||
|
||||
In this word search, XMAS occurs a total of 18 times; here's the same word search again, but where letters not involved in any XMAS have been replaced with .:
|
||||
....XXMAS.
|
||||
.SAMXMS...
|
||||
...S..A...
|
||||
..A.A.MS.X
|
||||
XMASAMX.MM
|
||||
X.....XA.A
|
||||
S.S.S.S.SS
|
||||
.A.A.A.A.A
|
||||
..M.M.M.MM
|
||||
.X.X.XMASX
|
||||
|
||||
Take a look at the little Elf's word search. How many times does XMAS appear?
|
||||
|
||||
https://adventofcode.com/2024/day/4
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -5,66 +5,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 5: Print Queue ---
|
||||
Satisfied with their search on Ceres, the squadron of scholars suggests subsequently scanning the stationery stacks of sub-basement 17.
|
||||
The North Pole printing department is busier than ever this close to Christmas, and while The Historians continue their search of this historically significant facility, an Elf operating a very familiar printer beckons you over.
|
||||
The Elf must recognize you, because they waste no time explaining that the new sleigh launch safety manual updates won't print correctly. Failure to update the safety manuals would be dire indeed, so you offer your services.
|
||||
Safety protocols clearly indicate that new pages for the safety manuals must be printed in a very specific order. The notation X|Y means that if both page number X and page number Y are to be produced as part of an update, page number X must be printed at some point before page number Y.
|
||||
The Elf has for you both the page ordering rules and the pages to produce in each update (your puzzle input), but can't figure out whether each update has the pages in the right order.
|
||||
For example:
|
||||
47|53
|
||||
97|13
|
||||
97|61
|
||||
97|47
|
||||
75|29
|
||||
61|13
|
||||
75|53
|
||||
29|13
|
||||
97|29
|
||||
53|29
|
||||
61|53
|
||||
97|53
|
||||
61|29
|
||||
47|13
|
||||
75|47
|
||||
97|75
|
||||
47|61
|
||||
75|61
|
||||
47|29
|
||||
75|13
|
||||
53|13
|
||||
|
||||
75,47,61,53,29
|
||||
97,61,53,29,13
|
||||
75,29,13
|
||||
75,97,47,61,53
|
||||
61,13,29
|
||||
97,13,75,29,47
|
||||
|
||||
The first section specifies the page ordering rules, one per line. The first rule, 47|53, means that if an update includes both page number 47 and page number 53, then page number 47 must be printed at some point before page number 53. (47 doesn't necessarily need to be immediately before 53; other pages are allowed to be between them.)
|
||||
The second section specifies the page numbers of each update. Because most safety manuals are different, the pages needed in the updates are different too. The first update, 75,47,61,53,29, means that the update consists of page numbers 75, 47, 61, 53, and 29.
|
||||
To get the printers going as soon as possible, start by identifying which updates are already in the right order.
|
||||
In the above example, the first update (75,47,61,53,29) is in the right order:
|
||||
|
||||
75 is correctly first because there are rules that put each other page after it: 75|47, 75|61, 75|53, and 75|29.
|
||||
47 is correctly second because 75 must be before it (75|47) and every other page must be after it according to 47|61, 47|53, and 47|29.
|
||||
61 is correctly in the middle because 75 and 47 are before it (75|61 and 47|61) and 53 and 29 are after it (61|53 and 61|29).
|
||||
53 is correctly fourth because it is before page number 29 (53|29).
|
||||
29 is the only page left and so is correctly last.
|
||||
|
||||
Because the first update does not include some page numbers, the ordering rules involving those missing page numbers are ignored.
|
||||
The second and third updates are also in the correct order according to the rules. Like the first update, they also do not include every page number, and so only some of the ordering rules apply - within each update, the ordering rules that involve missing page numbers are not used.
|
||||
The fourth update, 75,97,47,61,53, is not in the correct order: it would print 75 before 97, which violates the rule 97|75.
|
||||
The fifth update, 61,13,29, is also not in the correct order, since it breaks the rule 29|13.
|
||||
The last update, 97,13,75,29,47, is not in the correct order due to breaking several rules.
|
||||
For some reason, the Elves also need to know the middle page number of each update being printed. Because you are currently only printing the correctly-ordered updates, you will need to find the middle page number of each correctly-ordered update. In the above example, the correctly-ordered updates are:
|
||||
75,47,61,53,29
|
||||
97,61,53,29,13
|
||||
75,29,13
|
||||
|
||||
These have middle page numbers of 61, 53, and 29 respectively. Adding these page numbers together gives 143.
|
||||
Of course, you'll need to be careful: the actual list of page ordering rules is bigger and more complicated than the above example.
|
||||
Determine which updates are already in the correct order. What do you get if you add up the middle page number from those correctly-ordered updates?
|
||||
|
||||
https://adventofcode.com/2024/day/5
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -7,90 +7,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 6: Guard Gallivant ---
|
||||
The Historians use their fancy device again, this time to whisk you all away to the North Pole prototype suit manufacturing lab... in the year 1518! It turns out that having direct access to history is very convenient for a group of historians.
|
||||
You still have to be careful of time paradoxes, and so it will be important to avoid anyone from 1518 while The Historians search for the Chief. Unfortunately, a single guard is patrolling this part of the lab.
|
||||
Maybe you can work out where the guard will go ahead of time so that The Historians can search safely?
|
||||
You start by making a map (your puzzle input) of the situation. For example:
|
||||
....#.....
|
||||
.........#
|
||||
..........
|
||||
..#.......
|
||||
.......#..
|
||||
..........
|
||||
.#..^.....
|
||||
........#.
|
||||
#.........
|
||||
......#...
|
||||
|
||||
The map shows the current position of the guard with ^ (to indicate the guard is currently facing up from the perspective of the map). Any obstructions - crates, desks, alchemical reactors, etc. - are shown as #.
|
||||
Lab guards in 1518 follow a very strict patrol protocol which involves repeatedly following these steps:
|
||||
|
||||
If there is something directly in front of you, turn right 90 degrees.
|
||||
Otherwise, take a step forward.
|
||||
|
||||
Following the above protocol, the guard moves up several times until she reaches an obstacle (in this case, a pile of failed suit prototypes):
|
||||
....#.....
|
||||
....^....#
|
||||
..........
|
||||
..#.......
|
||||
.......#..
|
||||
..........
|
||||
.#........
|
||||
........#.
|
||||
#.........
|
||||
......#...
|
||||
|
||||
Because there is now an obstacle in front of the guard, she turns right before continuing straight in her new facing direction:
|
||||
....#.....
|
||||
........>#
|
||||
..........
|
||||
..#.......
|
||||
.......#..
|
||||
..........
|
||||
.#........
|
||||
........#.
|
||||
#.........
|
||||
......#...
|
||||
|
||||
Reaching another obstacle (a spool of several very long polymers), she turns right again and continues downward:
|
||||
....#.....
|
||||
.........#
|
||||
..........
|
||||
..#.......
|
||||
.......#..
|
||||
..........
|
||||
.#......v.
|
||||
........#.
|
||||
#.........
|
||||
......#...
|
||||
|
||||
This process continues for a while, but the guard eventually leaves the mapped area (after walking past a tank of universal solvent):
|
||||
....#.....
|
||||
.........#
|
||||
..........
|
||||
..#.......
|
||||
.......#..
|
||||
..........
|
||||
.#........
|
||||
........#.
|
||||
#.........
|
||||
......#v..
|
||||
|
||||
By predicting the guard's route, you can determine which specific positions in the lab will be in the patrol path. Including the guard's starting position, the positions visited by the guard before leaving the area are marked with an X:
|
||||
....#.....
|
||||
....XXXXX#
|
||||
....X...X.
|
||||
..#.X...X.
|
||||
..XXXXX#X.
|
||||
..X.X.X.X.
|
||||
.#XXXXXXX.
|
||||
.XXXXXXX#.
|
||||
#XXXXXXX..
|
||||
......#X..
|
||||
|
||||
In this example, the guard will visit 41 distinct positions on your map.
|
||||
Predict the path of the guard. How many distinct positions will the guard visit before leaving the mapped area?
|
||||
|
||||
https://adventofcode.com/2024/day/6
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -6,31 +6,7 @@ import splitLongs
|
||||
|
||||
/*
|
||||
--- Day 7: Bridge Repair ---
|
||||
The Historians take you to a familiar rope bridge over a river in the middle of a jungle. The Chief isn't on this side of the bridge, though; maybe he's on the other side?
|
||||
When you go to cross the bridge, you notice a group of engineers trying to repair it. (Apparently, it breaks pretty frequently.) You won't be able to cross until it's fixed.
|
||||
You ask how long it'll take; the engineers tell you that it only needs final calibrations, but some young elephants were playing nearby and stole all the operators from their calibration equations! They could finish the calibrations if only someone could determine which test values could possibly be produced by placing any combination of operators into their calibration equations (your puzzle input).
|
||||
For example:
|
||||
190: 10 19
|
||||
3267: 81 40 27
|
||||
83: 17 5
|
||||
156: 15 6
|
||||
7290: 6 8 6 15
|
||||
161011: 16 10 13
|
||||
192: 17 8 14
|
||||
21037: 9 7 18 13
|
||||
292: 11 6 16 20
|
||||
|
||||
Each line represents a single equation. The test value appears before the colon on each line; it is your job to determine whether the remaining numbers can be combined with operators to produce the test value.
|
||||
Operators are always evaluated left-to-right, not according to precedence rules. Furthermore, numbers in the equations cannot be rearranged. Glancing into the jungle, you can see elephants holding two different types of operators: add (+) and multiply (*).
|
||||
Only three of the above equations can be made true by inserting operators:
|
||||
|
||||
190: 10 19 has only one position that accepts an operator: between 10 and 19. Choosing + would give 29, but choosing * would give the test value (10 * 19 = 190).
|
||||
3267: 81 40 27 has two positions for operators. Of the four possible configurations of the operators, two cause the right side to match the test value: 81 + 40 * 27 and 81 * 40 + 27 both equal 3267 (when evaluated left-to-right)!
|
||||
292: 11 6 16 20 can be solved in exactly one way: 11 + 6 * 16 + 20.
|
||||
|
||||
The engineers just need the total calibration result, which is the sum of the test values from just the equations that could possibly be true. In the above example, the sum of the test values for the three equations listed above is 3749.
|
||||
Determine which equations could possibly be true. What is their total calibration result?
|
||||
|
||||
https://adventofcode.com/2024/day/7
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -7,76 +7,7 @@ import readInput
|
||||
|
||||
/*
|
||||
--- Day 8: Resonant Collinearity ---
|
||||
You find yourselves on the roof of a top-secret Easter Bunny installation.
|
||||
While The Historians do their thing, you take a look at the familiar huge antenna. Much to your surprise, it seems to have been reconfigured to emit a signal that makes people 0.1% more likely to buy Easter Bunny brand Imitation Mediocre Chocolate as a Christmas gift! Unthinkable!
|
||||
Scanning across the city, you find that there are actually many such antennas. Each antenna is tuned to a specific frequency indicated by a single lowercase letter, uppercase letter, or digit. You create a map (your puzzle input) of these antennas. For example:
|
||||
............
|
||||
........0...
|
||||
.....0......
|
||||
.......0....
|
||||
....0.......
|
||||
......A.....
|
||||
............
|
||||
............
|
||||
........A...
|
||||
.........A..
|
||||
............
|
||||
............
|
||||
|
||||
The signal only applies its nefarious effect at specific antinodes based on the resonant frequencies of the antennas. In particular, an antinode occurs at any point that is perfectly in line with two antennas of the same frequency - but only when one of the antennas is twice as far away as the other. This means that for any pair of antennas with the same frequency, there are two antinodes, one on either side of them.
|
||||
So, for these two antennas with frequency a, they create the two antinodes marked with #:
|
||||
..........
|
||||
...#......
|
||||
..........
|
||||
....a.....
|
||||
..........
|
||||
.....a....
|
||||
..........
|
||||
......#...
|
||||
..........
|
||||
..........
|
||||
|
||||
Adding a third antenna with the same frequency creates several more antinodes. It would ideally add four antinodes, but two are off the right side of the map, so instead it adds only two:
|
||||
..........
|
||||
...#......
|
||||
#.........
|
||||
....a.....
|
||||
........a.
|
||||
.....a....
|
||||
..#.......
|
||||
......#...
|
||||
..........
|
||||
..........
|
||||
|
||||
Antennas with different frequencies don't create antinodes; A and a count as different frequencies. However, antinodes can occur at locations that contain antennas. In this diagram, the lone antenna with frequency capital A creates no antinodes but has a lowercase-a-frequency antinode at its location:
|
||||
..........
|
||||
...#......
|
||||
#.........
|
||||
....a.....
|
||||
........a.
|
||||
.....a....
|
||||
..#.......
|
||||
......A...
|
||||
..........
|
||||
..........
|
||||
|
||||
The first example has antennas with two different frequencies, so the antinodes they create look like this, plus an antinode overlapping the topmost A-frequency antenna:
|
||||
......#....#
|
||||
...#....0...
|
||||
....#0....#.
|
||||
..#....0....
|
||||
....0....#..
|
||||
.#....A.....
|
||||
...#........
|
||||
#......#....
|
||||
........A...
|
||||
.........A..
|
||||
..........#.
|
||||
..........#.
|
||||
|
||||
Because the topmost A-frequency antenna overlaps with a 0-frequency antinode, there are 14 total unique locations that contain an antinode within the bounds of the map.
|
||||
Calculate the impact of the signal. How many unique locations within the bounds of the map contain an antinode?
|
||||
|
||||
https://adventofcode.com/2024/day/8
|
||||
*/
|
||||
fun main() {
|
||||
|
||||
|
@ -135,7 +135,8 @@ class Downloader(val year: Int, val packageName: String, val sessionCookie: Stri
|
||||
template = template.replace("\${package}", packageName)
|
||||
template = template.replace("\${day}", "%02d".format(day))
|
||||
template = template.replace("\${testinput}", testInput)
|
||||
template = template.replace("\${description}", description)
|
||||
template = template.replace("\${description}", description.substringBefore("\n"))
|
||||
template = template.replace("\${weblink}", "https://adventofcode.com/$year/day/$day")
|
||||
Files.writeString(genClassFile, template)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user