Some updates to the environment
* direnv setup * aoc script * timer script
This commit is contained in:
parent
32b30b4174
commit
8f97185c39
7
.envrc
Normal file
7
.envrc
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
PATH_add sbin
|
||||||
|
|
||||||
|
export AOCROOT=`pwd`
|
||||||
|
export CURRDAY=`date +%d`
|
||||||
|
export CURRMONTH=`date +%m`
|
||||||
|
export CURRYEAR=`date +%Y`
|
||||||
|
export TODAYDIR="$AOCROOT/$CURRYEAR/day$CURRDAY"
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -54,5 +54,3 @@ _testmain.go
|
|||||||
*/day24/day24
|
*/day24/day24
|
||||||
*/day25/day25
|
*/day25/day25
|
||||||
|
|
||||||
# And my "You got it wrong" timer
|
|
||||||
timer
|
|
||||||
|
157
2023/day06/problem
Normal file
157
2023/day06/problem
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
[1]Advent of Code
|
||||||
|
|
||||||
|
br0xen [7](AoC++) 12*
|
||||||
|
|
||||||
|
--- 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 go 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?
|
||||||
|
|
||||||
|
Your puzzle answer was 449820.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
As the race is about to start, you realize the piece of paper with race
|
||||||
|
times and record distances you got earlier actually just has very bad
|
||||||
|
[16]kerning. There's really only one race - ignore the spaces between the
|
||||||
|
numbers on each line.
|
||||||
|
|
||||||
|
So, the example from before:
|
||||||
|
|
||||||
|
Time: 7 15 30
|
||||||
|
Distance: 9 40 200
|
||||||
|
|
||||||
|
...now instead means this:
|
||||||
|
|
||||||
|
Time: 71530
|
||||||
|
Distance: 940200
|
||||||
|
|
||||||
|
Now, you have to figure out how many ways there are to win this single
|
||||||
|
race. In this example, the race lasts for 71530 milliseconds and the
|
||||||
|
record distance you need to beat is 940200 millimeters. You could hold the
|
||||||
|
button anywhere from 14 to 71516 milliseconds and beat the record, a total
|
||||||
|
of 71503 ways!
|
||||||
|
|
||||||
|
How many ways can you beat the record in this one much longer race?
|
||||||
|
|
||||||
|
Your puzzle answer was 42250895.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
You can also [Shareon [19]Twitter [20]Mastodon] this puzzle.
|
||||||
|
|
||||||
|
References
|
||||||
|
|
||||||
|
Visible links
|
||||||
|
1. https://adventofcode.com/
|
||||||
|
2. https://adventofcode.com/2023/about
|
||||||
|
3. https://adventofcode.com/2023/events
|
||||||
|
4. https://teespring.com/stores/advent-of-code
|
||||||
|
5. https://adventofcode.com/2023/settings
|
||||||
|
6. https://adventofcode.com/2023/auth/logout
|
||||||
|
7. Advent of Code Supporter
|
||||||
|
https://adventofcode.com/2023/support
|
||||||
|
8. https://adventofcode.com/2023
|
||||||
|
9. https://adventofcode.com/2023
|
||||||
|
10. https://adventofcode.com/2023/support
|
||||||
|
11. https://adventofcode.com/2023/sponsors
|
||||||
|
12. https://adventofcode.com/2023/leaderboard
|
||||||
|
13. https://adventofcode.com/2023/stats
|
||||||
|
14. https://adventofcode.com/2023/sponsors
|
||||||
|
16. https://en.wikipedia.org/wiki/Kerning
|
||||||
|
17. https://adventofcode.com/2023
|
||||||
|
18. https://adventofcode.com/2023/day/6/input
|
BIN
favicon.png
Normal file
BIN
favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.0 KiB |
78
sbin/aoc
Executable file
78
sbin/aoc
Executable file
@ -0,0 +1,78 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
today() {
|
||||||
|
echo "Going to today"
|
||||||
|
TODAYDIR="$AOCROOT/$CURRYEAR/day$CURRDAY"
|
||||||
|
if [ ! -d $TODAYDIR ]; then
|
||||||
|
echo "> Doesn't exist, making"
|
||||||
|
mkdir $TODAYDIR
|
||||||
|
fi
|
||||||
|
echo "> cd $TODAYDIR"
|
||||||
|
cd $TODAYDIR
|
||||||
|
}
|
||||||
|
|
||||||
|
getproblem() {
|
||||||
|
YR=$CURRYEAR
|
||||||
|
DY=$CURRDAY
|
||||||
|
|
||||||
|
PWD=$(pwd)
|
||||||
|
PWD=${PWD#$AOCROOT/}
|
||||||
|
echo $PWD
|
||||||
|
if [[ "$PWD" =~ ^[1-9][0-9]{3}/day[0-2][0-9]$ ]]; then
|
||||||
|
YR=${PWD:0:4}
|
||||||
|
DY=${PWD:5:5}
|
||||||
|
DY=${DY/day0/}
|
||||||
|
DY=${DY/day/}
|
||||||
|
else
|
||||||
|
echo "Changing to Today's Directory"
|
||||||
|
cd $AOCROOT/$YR/day$DY
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -f "problem" ]]; then
|
||||||
|
echo "Found problem file."
|
||||||
|
if [[ $1 != "-f" ]]; then
|
||||||
|
# Check if the file already exists
|
||||||
|
echo "Not forcing overwrite."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove any zero padding from day
|
||||||
|
DY=$(echo "$CURRDAY"|awk '$0*=1')
|
||||||
|
echo "Getting problem at $CURRYEAR/day/$DY"
|
||||||
|
elinks -dump https://adventofcode.com/$CURRYEAR/day/$DY > problem
|
||||||
|
vim problem
|
||||||
|
}
|
||||||
|
|
||||||
|
getsessiontoken() {
|
||||||
|
FULLCOOKIE=$(grep "adventofcode" $HOME/.elinks/cookies)
|
||||||
|
if [[ ! -n "$FULLCOOKIE" ]]; then
|
||||||
|
echo "Error pulling elinks cookie"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo $FULLCOOKIE | cut -d" " -f2
|
||||||
|
}
|
||||||
|
|
||||||
|
help() {
|
||||||
|
echo "Usage: aoc [option]"
|
||||||
|
echo "Available Options:"
|
||||||
|
echo ""
|
||||||
|
echo " getproblem - Retrieve the problem for the day associated with the current directory"
|
||||||
|
echo ""
|
||||||
|
echo " getsessiontoken - Echo the session token from the elinks cookie file"
|
||||||
|
echo ""
|
||||||
|
echo " help - Display this message"
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
"getproblem")
|
||||||
|
getproblem $2
|
||||||
|
;;
|
||||||
|
"getsessiontoken")
|
||||||
|
getsessiontoken
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
help
|
||||||
|
;;
|
||||||
|
esac
|
11
sbin/timer
Executable file
11
sbin/timer
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
TIME=1
|
||||||
|
if [[ $# -ne 0 ]]; then
|
||||||
|
TIME=$1
|
||||||
|
fi
|
||||||
|
sleep ${TIME}m
|
||||||
|
|
||||||
|
notify-send -i $AOCROOT/favicon.png "Timer has expired"
|
||||||
|
echo "Done Waiting"
|
||||||
|
|
27
timer.go
27
timer.go
@ -1,27 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
wait := 1
|
|
||||||
if len(os.Args) > 1 {
|
|
||||||
wait = Atoi(os.Args[1])
|
|
||||||
}
|
|
||||||
time.Sleep(time.Minute * time.Duration(wait))
|
|
||||||
fmt.Println("Done waiting")
|
|
||||||
}
|
|
||||||
|
|
||||||
func Atoi(i string) int {
|
|
||||||
var ret int
|
|
||||||
var err error
|
|
||||||
if ret, err = strconv.Atoi(i); err != nil {
|
|
||||||
log.Fatal("Invalid Atoi")
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user