blob: 58b91e8540b0a624f13b8c0367a92a7acbe51eae (
plain)
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
|
#!/usr/bin/env sh
usage="usage: check <year> <day> <language> <testfile> [<benchmark>]"
year=${1?$usage}
day=${2?$usage}
lang=${3?$usage}
input=${4?$usage}
bench=$5
# get directory of this script
script=$(readlink -f $0)
script_path=$(dirname $script)
# find aoc and data paths
aoc_path=$script_path/$year/$day
data_path=$aoc_path/data/$input.txt
case $lang in
python)
solve=$aoc_path/python.py
;;
rust)
cargo build --target-dir /tmp/aoc_rust --manifest-path $aoc_path/rust/Cargo.toml
solve=/tmp/aoc_rust/debug/aoc_$year-$day
;;
rustc)
cargo build --release --target-dir /tmp/aoc_rust --manifest-path $aoc_path/rust/Cargo.toml
solve=/tmp/aoc_rust/release/aoc_$year-$day
;;
*)
echo "unknown lang: $lang"
exit 1
;;
esac
result=$(cat $data_path | $solve)
diff=$(echo "$result" | diff $aoc_path/data/$4.ans -)
code=$?
[ $code -eq 0 ] && echo Solved with $lang! || echo "$diff"
[ -n "$bench" ] && hyperfine --shell none --input $data_path $solve && exit 0
echo "\n---stdout---"
echo "$result"
exit $code
|