aboutsummaryrefslogtreecommitdiff
path: root/entries
diff options
context:
space:
mode:
authorfunemy2022-10-24 02:21:33 +0000
committerfunemy2022-10-24 02:21:33 +0000
commit201f9e290b59838ed249b7d1be03e5b8230bef3e (patch)
tree0d72555dadd6a590c993c921d9af73caca9922b6 /entries
parenta89c7847195a7b20e307b042fbc821e741ccdaa4 (diff)
add proper bound check
Diffstat (limited to 'entries')
-rwxr-xr-xentries/funemy/z3/z3fib.sh16
1 files changed, 12 insertions, 4 deletions
diff --git a/entries/funemy/z3/z3fib.sh b/entries/funemy/z3/z3fib.sh
index 9faa228..03a7209 100755
--- a/entries/funemy/z3/z3fib.sh
+++ b/entries/funemy/z3/z3fib.sh
@@ -14,6 +14,11 @@ else
touch fib.smt2
fi
+if [ "$1" -lt "0" ]; then
+ echo "Argument must be larger than 0."
+ exit 1
+fi
+
for i in $(seq 0 $1);
do
echo "(declare-const x$i Int)" >> fib.smt2
@@ -32,10 +37,13 @@ done
echo " (= x0 0)" >> fib.smt2
echo " (= x1 1)" >> fib.smt2
-for i in $(seq 2 $1);
-do
- echo " (= x$i (+ x$(($i - 2)) x$(($i - 1))))" >> fib.smt2
-done
+if [ "$1" -ge "2" ]; then
+ for i in $(seq 2 $1);
+ do
+ echo " (= x$i (+ x$(($i - 2)) x$(($i - 1))))" >> fib.smt2
+ done
+fi
+
echo " )" >> fib.smt2
echo ")" >> fib.smt2