From 623602eae604eb098031ca2c09da992522d9980c Mon Sep 17 00:00:00 2001 From: Ze'ev Schurmann Date: Wed, 18 Dec 2024 07:35:15 +0200 Subject: [PATCH] Added Bash script for Fibonacci number sets --- code-files/calculate-fibonacci.sh | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 code-files/calculate-fibonacci.sh diff --git a/code-files/calculate-fibonacci.sh b/code-files/calculate-fibonacci.sh new file mode 100644 index 0000000..709ff90 --- /dev/null +++ b/code-files/calculate-fibonacci.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +maxint=9223372036854775807 +root=3037000499 +destination=255 +found=0 + +rm -f fibonacci.list + +SECONDS=0 + +destination=65535 +n=1 +l=1 +t=0 + +echo "0001 1" >> fibonacci.list + +while [[ $n -le $destination ]]; do + t=$((l+n)) + l=$n + n=$t + if [[ $n -le $destination ]]; then + clear + ((found++)) + hex=$(printf "%04X" "$n") + echo "Number $n of $destination is FIBONACCI [$((n*100/destination)) %]" + echo "$hex $n" >> fibonacci.list + rate=$((SECONDS*1000000/n)) + estsec=$((rate*destination/1000000)) + remsec=$((estsec-SECONDS)) + echo "Running Time: $((SECONDS/86400)) days, $(((SECONDS%86400)/3600)) hours, $(((SECONDS%3600)/60)) minutes and $(((SECONDS%60))) seconds..." + echo "Remaining Time: $((remsec/86400)) days, $(((remsec%86400)/3600)) hours, $(((remsec%3600)/60)) minutes and $(((remsec%60))) seconds..." + echo "Found $found FIBONACCI numbers at an average rate of $((found/(SECONDS+1))) per second..." + fi +done +