diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2026-05-06 08:30:49 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2026-05-06 08:30:49 +0200 |
| commit | 60052659b98832c78c902e4f27ecee2663d8e913 (patch) | |
| tree | 9efc1388569c43456557aa1975b4bec99bf06c94 /scripts/aoc | |
| parent | 10e16c2fb2266bb2b46ec7ea64d721de0c29a0d9 (diff) | |
| download | config-60052659b98832c78c902e4f27ecee2663d8e913.tar.gz config-60052659b98832c78c902e4f27ecee2663d8e913.zip | |
Added scripts
Diffstat (limited to '')
| -rwxr-xr-x | scripts/aoc | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/scripts/aoc b/scripts/aoc new file mode 100755 index 0000000..40f94ed --- /dev/null +++ b/scripts/aoc | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Set up a working environment for Advent of Code (https://adventofcode.com/). | ||
| 4 | # Requires tmux, lynx, curl and a valid AOC_SESSION_COOKIE session cookie. | ||
| 5 | |||
| 6 | # usage: aoc [yyyy nn] | ||
| 7 | # If yyyy (year) and nn (day, with leading zero if single digit) are not | ||
| 8 | # specified, the current year and day are used. | ||
| 9 | |||
| 10 | editor="vi a.py" | ||
| 11 | basedir="$HOME/src/aoc" | ||
| 12 | lynx_cookie_file="$(mktemp)" | ||
| 13 | clibrowser="lynx -cookie_file=$lynx_cookie_file" | ||
| 14 | |||
| 15 | year="${1:-$(date +'%Y')}" | ||
| 16 | day="${2:-$(date +'%d')}" | ||
| 17 | daynozero="$(echo "$day" | sed 's/^0//')" | ||
| 18 | |||
| 19 | cd "$basedir/$year/$day" | ||
| 20 | |||
| 21 | # Download the puzzle input and save it to input.txt | ||
| 22 | if [ ! -e input.txt ]; then | ||
| 23 | url="https://adventofcode.com/$year/day/$daynozero/input" | ||
| 24 | curl "$url" -H "cookie: session=$AOC_SESSION_COOKIE" -o input.txt | ||
| 25 | fi | ||
| 26 | |||
| 27 | # Download the problem statement page and split out the code blocks | ||
| 28 | url="https://adventofcode.com/$year/day/$daynozero" | ||
| 29 | curl "$url" | sed -n '/<pre><code>/,/<\/code><\/pre>/ p' | (\ | ||
| 30 | i=1 | ||
| 31 | rm -f "code-$i.txt" | ||
| 32 | IFS='' | ||
| 33 | while read -r line; do | ||
| 34 | if [ "$line" = "</code></pre>" ]; then | ||
| 35 | i=$((i + 1)) | ||
| 36 | rm -f "code-$i.txt" | ||
| 37 | else | ||
| 38 | echo "$line" | sed 's/<.*>//g' >> "code-$i.txt" | ||
| 39 | fi | ||
| 40 | done | ||
| 41 | ) | ||
| 42 | |||
| 43 | # Open a tmux session with lynx in its own windows, and an editor and a | ||
| 44 | # terminal in split view. | ||
| 45 | printf 'adventofcode.com\tFALSE\t/\tTRUE\t2079722976\tsession\t%s' \ | ||
| 46 | "$AOC_SESSION_COOKIE" > "$lynx_cookie_file" | ||
| 47 | tmux new-session \; \ | ||
| 48 | send-keys "$editor" C-m \; \ | ||
| 49 | split-window -h \; \ | ||
| 50 | select-pane -t 0 \; \ | ||
| 51 | new-window \; \ | ||
| 52 | send-keys "$clibrowser $url" C-m \; | ||
