-
Notifications
You must be signed in to change notification settings - Fork 0
/
prep-day.sh
executable file
·94 lines (76 loc) · 2.26 KB
/
prep-day.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/sh
set -e
# Downloads the input and sets up module boilerplate for
# the given day. Expects that a `.session` file exists with the
# user's session key from the Advent of Code website. See the
# README for instructions on how to set it up.
#
# This script should be idempotent, so don't worry about things
# breaking if you run it for the same day multiple times.
#
# Usage:
# ./prep-day.sh 10
YEAR=2024
mkdir -p .input
mkdir -p "$YEAR"
if test -z "$1"; then
echo "Must provide day of month (not zero-padded) as first argument"
exit 1
fi
if [[ 1 -gt "$1" || 25 -lt "$1" ]]; then
echo "Day must be between 1 and 25, inclusive"
exit 1
fi
SESSION=$(cat .session)
if test -z "$SESSION"; then
echo "Must set the session from the Advent of Code site"
exit 1
fi
if test -e ".input/$1.txt"; then
echo "Data already exists for day $1, skipping download..."
else
echo "Downloading data for day $1 to .input/$1.txt..."
curl "https://adventofcode.com/$YEAR/day/$1/input" \
--silent --max-time 10 --cookie "session=$SESSION" > ".input/$1.txt"
fi
if test -e "src/day$1.rs"; then
echo "src/day$1.rs already exists, skipping..."
else
echo "Creating boilerplate module for day $1 at src/day$1.rs..."
cat <<-EOF > "src/day$1.rs"
use crate::{DaySolution, FromInput};
pub struct Day$1;
impl FromInput for Day$1 {
fn from_lines(_lines: impl Iterator<Item = String>) -> Self {
todo!("Parse your input from the input file");
for l in _lines {
}
}
}
impl DaySolution for Day$1 {
fn part_one(&self) -> String {
let mut sum = 0_usize;
todo!("Solve part one of day $1 using your parsed input");
sum.to_string()
}
fn part_two(&self) -> String {
let mut sum = 0_usize;
todo!("Solve part two of day $1 using your parsed input");
sum.to_string()
}
}
EOF
SED="sed"
if [ "$(uname -s)" = "Darwin" ]
then
SED=gsed
fi
"$SED" -i "s|// MOD_MARKER|mod day$1;\nuse day$1::Day$1;\n// MOD_MARKER|" src/main.rs
"$SED" -i "s| // DAY_MARKER| $1 => Box::new(Day$1::from_lines(lines)),\n // DAY_MARKER|" src/main.rs
echo "Updated main.rs:"
git diff src/main.rs
#echo " mod day$1;"
#echo " use day$1::Day$1;"
#echo " $1 => Box::new(Day$1::from_lines(lines)),"
fi
echo "Happy coding!"