blob: 9cf74e68a7c91e7cefd154c603e88ed82366fca7 (
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
47
48
49
50
51
52
53
54
55
56
|
#!/usr/bin/env sh
usage="usage: check <directory> <language> <testfile> [<benchmark>]"
puzzle=${1?$usage}
lang=${2?$usage}
input=${3?$usage}
bench=$4
# get directory of this script
script=$(readlink -f "$0")
script_path=$(dirname "$script")
# get puzzle and data paths
puzzle_path="$script_path"/"$puzzle"
data_path="$puzzle_path"/data/"$input".txt
case $lang in
python)
solve="$puzzle_path"/python.py
;;
raku)
solve="$puzzle_path"/raku.raku
;;
rust)
cargo build --target-dir /tmp/puzzle_rust --manifest-path "$puzzle_path"/rust/Cargo.toml
solve=/tmp/puzzle_rust/debug/puzzle
;;
rustc)
cargo build --release --target-dir /tmp/puzzle_rust --manifest-path "$puzzle_path"/rust/Cargo.toml
solve=/tmp/puzzle_rust/release/puzzle
;;
c)
gcc "$puzzle_path"/c.c -Wall -Wextra -Werror -std=c23 -o /tmp/puzzle_c
solve=/tmp/puzzle_c
;;
cc)
gcc "$puzzle_path"/c.c -Wall -Wextra -Werror -std=c23 -O3 -o /tmp/puzzle_c
solve=/tmp/puzzle_c
;;
*)
echo "unknown lang: $lang"
exit 1
;;
esac
result=$(cat "$data_path" | $solve)
diff=$(echo "$result" | diff "$puzzle_path"/data/"$3".ans -)
code=$?
[ $code -eq 0 ] && echo Solved with "$lang"! || echo "$diff"
[ -n "$bench" ] && hyperfine --shell none --input "$data_path" "$solve" && exit 0
printf "\n---stdout---\n"
echo "$result"
exit $code
|