2025 Day 1 Complete! 🎅
This commit is contained in:
4145
2025/day01/input
Normal file
4145
2025/day01/input
Normal file
File diff suppressed because it is too large
Load Diff
57
2025/day01/main.go
Normal file
57
2025/day01/main.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
h "git.bullercodeworks.com/brian/adventofcode/helpers"
|
||||
)
|
||||
|
||||
func main() {
|
||||
inp := h.StdinToStringSlice()
|
||||
part1(inp)
|
||||
part2(inp)
|
||||
}
|
||||
|
||||
func part1(inp []string) {
|
||||
var hit int
|
||||
dial := 50
|
||||
for i := range inp {
|
||||
dir, snum := inp[i][0], inp[i][1:]
|
||||
num := h.Atoi(snum)
|
||||
switch dir {
|
||||
case 'R':
|
||||
dial += num
|
||||
case 'L':
|
||||
dial -= num
|
||||
}
|
||||
dial = (dial + 100) % 100
|
||||
if dial == 0 {
|
||||
hit++
|
||||
}
|
||||
}
|
||||
fmt.Println("# Part 1")
|
||||
fmt.Println(hit)
|
||||
}
|
||||
|
||||
func part2(inp []string) {
|
||||
var hit int
|
||||
dial := 50
|
||||
for i := range inp {
|
||||
dir, snum := inp[i][0], inp[i][1:]
|
||||
num := h.Atoi(snum)
|
||||
for j := 0; j < num; j++ {
|
||||
switch dir {
|
||||
case 'R':
|
||||
dial = (dial + 1) % 100
|
||||
case 'L':
|
||||
dial = (dial - 1 + 100) % 100
|
||||
}
|
||||
if dial == 0 {
|
||||
hit++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("# Part 2")
|
||||
fmt.Println(hit)
|
||||
}
|
||||
171
2025/day01/problem
Normal file
171
2025/day01/problem
Normal file
@@ -0,0 +1,171 @@
|
||||
Advent of Code
|
||||
|
||||
br0xen [7](AoC++) 2*
|
||||
|
||||
/^[8]2025$/
|
||||
|
||||
--- Day 1: Secret Entrance ---
|
||||
|
||||
The Elves have good news and bad news.
|
||||
|
||||
The good news is that they've discovered [16]project management! This has
|
||||
given them the tools they need to prevent their usual Christmas emergency.
|
||||
For example, they now know that the North Pole decorations need to be
|
||||
finished soon so that other critical tasks can start on time.
|
||||
|
||||
The bad news is that they've realized they have a different emergency:
|
||||
according to their resource planning, none of them have any time left to
|
||||
decorate the North Pole!
|
||||
|
||||
To save Christmas, the Elves need you to finish decorating the North Pole
|
||||
by December 12th.
|
||||
|
||||
Collect stars by solving puzzles. Two puzzles will be made available on
|
||||
each day; the second puzzle is unlocked when you complete the first. Each
|
||||
puzzle grants one star. Good luck!
|
||||
|
||||
You arrive at the secret entrance to the North Pole base ready to start
|
||||
decorating. Unfortunately, the password seems to have been changed, so you
|
||||
can't get in. A document taped to the wall helpfully explains:
|
||||
|
||||
"Due to new security protocols, the password is locked in the safe below.
|
||||
Please see the attached document for the new combination."
|
||||
|
||||
The safe has a dial with only an arrow on it; around the dial are the
|
||||
numbers 0 through 99 in order. As you turn the dial, it makes a small
|
||||
click noise as it reaches each number.
|
||||
|
||||
The attached document (your puzzle input) contains a sequence of
|
||||
rotations, one per line, which tell you how to open the safe. A rotation
|
||||
starts with an L or R which indicates whether the rotation should be to
|
||||
the left (toward lower numbers) or to the right (toward higher numbers).
|
||||
Then, the rotation has a distance value which indicates how many clicks
|
||||
the dial should be rotated in that direction.
|
||||
|
||||
So, if the dial were pointing at 11, a rotation of R8 would cause the dial
|
||||
to point at 19. After that, a rotation of L19 would cause it to point at
|
||||
0.
|
||||
|
||||
Because the dial is a circle, turning the dial left from 0 one click makes
|
||||
it point at 99. Similarly, turning the dial right from 99 one click makes
|
||||
it point at 0.
|
||||
|
||||
So, if the dial were pointing at 5, a rotation of L10 would cause it to
|
||||
point at 95. After that, a rotation of R5 could cause it to point at 0.
|
||||
|
||||
The dial starts by pointing at 50.
|
||||
|
||||
You could follow the instructions, but your recent required official North
|
||||
Pole secret entrance security training seminar taught you that the safe is
|
||||
actually a decoy. The actual password is the number of times the dial is
|
||||
left pointing at 0 after any rotation in the sequence.
|
||||
|
||||
For example, suppose the attached document contained the following
|
||||
rotations:
|
||||
|
||||
L68
|
||||
L30
|
||||
R48
|
||||
L5
|
||||
R60
|
||||
L55
|
||||
L1
|
||||
L99
|
||||
R14
|
||||
L82
|
||||
|
||||
Following these rotations would cause the dial to move as follows:
|
||||
|
||||
• The dial starts by pointing at 50.
|
||||
• The dial is rotated L68 to point at 82.
|
||||
• The dial is rotated L30 to point at 52.
|
||||
• The dial is rotated R48 to point at 0.
|
||||
• The dial is rotated L5 to point at 95.
|
||||
• The dial is rotated R60 to point at 55.
|
||||
• The dial is rotated L55 to point at 0.
|
||||
• The dial is rotated L1 to point at 99.
|
||||
• The dial is rotated L99 to point at 0.
|
||||
• The dial is rotated R14 to point at 14.
|
||||
• The dial is rotated L82 to point at 32.
|
||||
|
||||
Because the dial points at 0 a total of three times during this process,
|
||||
the password in this example is 3.
|
||||
|
||||
Analyze the rotations in your attached document. What's the actual
|
||||
password to open the door?
|
||||
|
||||
Your puzzle answer was 1026.
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
You're sure that's the right password, but the door won't open. You knock,
|
||||
but nobody answers. You build a snowman while you think.
|
||||
|
||||
As you're rolling the snowballs for your snowman, you find another
|
||||
security document that must have fallen into the snow:
|
||||
|
||||
"Due to newer security protocols, please use password method 0x434C49434B
|
||||
until further notice."
|
||||
|
||||
You remember from the training seminar that "method 0x434C49434B" means
|
||||
you're actually supposed to count the number of times any click causes the
|
||||
dial to point at 0, regardless of whether it happens during a rotation or
|
||||
at the end of one.
|
||||
|
||||
Following the same rotations as in the above example, the dial points at
|
||||
zero a few extra times during its rotations:
|
||||
|
||||
• The dial starts by pointing at 50.
|
||||
• The dial is rotated L68 to point at 82; during this rotation, it
|
||||
points at 0 once.
|
||||
• The dial is rotated L30 to point at 52.
|
||||
• The dial is rotated R48 to point at 0.
|
||||
• The dial is rotated L5 to point at 95.
|
||||
• The dial is rotated R60 to point at 55; during this rotation, it
|
||||
points at 0 once.
|
||||
• The dial is rotated L55 to point at 0.
|
||||
• The dial is rotated L1 to point at 99.
|
||||
• The dial is rotated L99 to point at 0.
|
||||
• The dial is rotated R14 to point at 14.
|
||||
• The dial is rotated L82 to point at 32; during this rotation, it
|
||||
points at 0 once.
|
||||
|
||||
In this example, the dial points at 0 three times at the end of a
|
||||
rotation, plus three more times during a rotation. So, in this example,
|
||||
the new password would be 6.
|
||||
|
||||
Be careful: if the dial were pointing at 50, a single rotation like R1000
|
||||
would cause the dial to point at 0 ten times before returning back to 50!
|
||||
|
||||
Using password method 0x434C49434B, what is the password to open the door?
|
||||
|
||||
Your puzzle answer was 5923.
|
||||
|
||||
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||
|
||||
At this point, you should [17]return to your Advent calendar and try
|
||||
another puzzle.
|
||||
|
||||
If you still want to see it, you can [18]get your puzzle input.
|
||||
|
||||
References
|
||||
|
||||
Visible links
|
||||
1. https://adventofcode.com/
|
||||
2. https://adventofcode.com/2025/about
|
||||
3. https://adventofcode.com/2025/events
|
||||
5. https://adventofcode.com/2025/settings
|
||||
6. https://adventofcode.com/2025/auth/logout
|
||||
7. Advent of Code Supporter
|
||||
https://adventofcode.com/2025/support
|
||||
8. https://adventofcode.com/2025
|
||||
9. https://adventofcode.com/2025
|
||||
10. https://adventofcode.com/2025/support
|
||||
11. https://adventofcode.com/2025/sponsors
|
||||
12. https://adventofcode.com/2025/leaderboard/private
|
||||
13. https://adventofcode.com/2025/stats
|
||||
14. https://adventofcode.com/2025/sponsors
|
||||
15. https://adventofcode.com/2025/sponsors/redirect?url=https%3A%2F%2Fwww%2Ejumptrading%2Ecom%2F
|
||||
16. https://en.wikipedia.org/wiki/Project_management
|
||||
17. https://adventofcode.com/2025
|
||||
18. https://adventofcode.com/2025/day/1/input
|
||||
10
2025/day01/testinput
Normal file
10
2025/day01/testinput
Normal file
@@ -0,0 +1,10 @@
|
||||
L68
|
||||
L30
|
||||
R48
|
||||
L5
|
||||
R60
|
||||
L55
|
||||
L1
|
||||
L99
|
||||
R14
|
||||
L82
|
||||
Reference in New Issue
Block a user