From 8f97185c39369bb2071639ee198fc3f81428a5a0 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Wed, 6 Dec 2023 08:59:56 -0600 Subject: [PATCH] Some updates to the environment * direnv setup * aoc script * timer script --- .envrc | 7 ++ .gitignore | 2 - 2023/day06/problem | 157 +++++++++++++++++++++++++++++++++++++++++++++ favicon.png | Bin 0 -> 5160 bytes sbin/aoc | 78 ++++++++++++++++++++++ sbin/timer | 11 ++++ timer.go | 27 -------- 7 files changed, 253 insertions(+), 29 deletions(-) create mode 100644 .envrc create mode 100644 2023/day06/problem create mode 100644 favicon.png create mode 100755 sbin/aoc create mode 100755 sbin/timer delete mode 100644 timer.go diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..b4523a3 --- /dev/null +++ b/.envrc @@ -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" diff --git a/.gitignore b/.gitignore index efa193a..88a7921 100644 --- a/.gitignore +++ b/.gitignore @@ -54,5 +54,3 @@ _testmain.go */day24/day24 */day25/day25 -# And my "You got it wrong" timer -timer diff --git a/2023/day06/problem b/2023/day06/problem new file mode 100644 index 0000000..4ddad8c --- /dev/null +++ b/2023/day06/problem @@ -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 diff --git a/favicon.png b/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..2b02b9938e1c5cc8d2af29db8ad91e35111118a1 GIT binary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0HTk zNtRb~4*Y(wzQGoO7b$4$pO>7Km0j||KfaokF_Q=@B85kxWGfd2sa W(diAc!BP|e0000 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 diff --git a/sbin/timer b/sbin/timer new file mode 100755 index 0000000..3c174d1 --- /dev/null +++ b/sbin/timer @@ -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" + diff --git a/timer.go b/timer.go deleted file mode 100644 index a2a44a8..0000000 --- a/timer.go +++ /dev/null @@ -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 -}