initial commit
This commit is contained in:
38
scripts/download.sh
Executable file
38
scripts/download.sh
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e;
|
||||
|
||||
if ! command -v 'aoc' &> /dev/null
|
||||
then
|
||||
echo "command \`aoc\` not found. Try running \`cargo install aoc-cli\` to install it."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -n "$1" ]; then
|
||||
>&2 echo "Argument is required for day."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
day=$(echo $1 | sed 's/^0*//');
|
||||
day_padded=`printf %02d $day`;
|
||||
|
||||
filename="day$day_padded";
|
||||
input_path="src/inputs/$filename.txt";
|
||||
|
||||
tmp_dir=$(mktemp -d);
|
||||
tmp_file_path="$tmp_dir/input";
|
||||
|
||||
aoc download --day $day --file $tmp_file_path;
|
||||
cat $tmp_file_path > $input_path;
|
||||
echo "Wrote input to \"$input_path\"...";
|
||||
|
||||
cat <<EOF
|
||||
_==_ _
|
||||
_,(",)|_|
|
||||
\/. \-|
|
||||
__( : )|_ Done!
|
||||
EOF
|
||||
|
||||
# Make sure it gets removed even if the script exits abnormally.
|
||||
trap "exit 1" HUP INT PIPE QUIT TERM
|
||||
trap 'rm -rf "$tmp_dir"' EXIT
|
||||
76
scripts/scaffold.sh
Executable file
76
scripts/scaffold.sh
Executable file
@@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e;
|
||||
|
||||
if [ ! -n "$1" ]; then
|
||||
>&2 echo "Argument is required for day."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
day=$(echo $1 | sed 's/^0*//');
|
||||
day_padded=`printf %02d $day`;
|
||||
|
||||
filename="day$day_padded";
|
||||
|
||||
input_path="src/inputs/$filename.txt";
|
||||
example_path="src/examples/$filename.txt";
|
||||
module_path="src/solutions/$filename.rs";
|
||||
|
||||
touch $module_path;
|
||||
|
||||
cat > $module_path <<EOF
|
||||
pub fn part_one(input: &str) -> u32 {
|
||||
0
|
||||
}
|
||||
|
||||
pub fn part_two(input: &str) -> u32 {
|
||||
0
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_part_one() {
|
||||
use aoc::read_file;
|
||||
let input = read_file("examples", day);
|
||||
assert_eq!(part_one(&input), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_part_two() {
|
||||
use aoc::read_file;
|
||||
let input = read_file("examples", day);
|
||||
assert_eq!(part_two(&input), 0);
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
perl -pi -e "s,day,$day,g" $module_path;
|
||||
|
||||
echo "Created module \"$module_path\"";
|
||||
|
||||
touch $input_path;
|
||||
echo "Created input file \"$input_path\"";
|
||||
|
||||
touch $example_path;
|
||||
echo "Created example file \"$example_path\"";
|
||||
|
||||
line=" $day => solve_day!($filename, &input),"
|
||||
perl -pi -le "print '$line' if(/^*.day not solved/);" "src/main.rs";
|
||||
|
||||
echo "Linked new module in \"src/main.rs\"";
|
||||
|
||||
LINE="pub mod $filename;";
|
||||
FILE="src/solutions/mod.rs";
|
||||
grep -qF -- "$LINE" "$FILE" || echo "$LINE" >> "$FILE";
|
||||
echo "Linked new module in \"$FILE\"";
|
||||
|
||||
|
||||
cat <<EOF
|
||||
_==_ _
|
||||
_,(",)|_|
|
||||
\/. \-|
|
||||
__( : )|_ Done!
|
||||
EOF
|
||||
Reference in New Issue
Block a user