number-sets/code-files/calculate-fibonacci.sh

38 lines
974 B
Bash
Raw Permalink Normal View History

#!/bin/bash
maxint=9223372036854775807
root=3037000499
2024-12-18 07:53:50 +02:00
found=0
rm -f fibonacci.list
SECONDS=0
2024-12-18 07:53:50 +02:00
destination=1099511627775
n=1
l=1
t=0
2024-12-18 07:53:50 +02:00
echo "0000000001 1" >> fibonacci.list
2024-12-18 07:53:50 +02:00
while [[ $n -le $destination ]] && [[ $n -gt 0 ]]; do
t=$((l+n))
l=$n
n=$t
if [[ $n -le $destination ]]; then
clear
((found++))
2024-12-18 07:53:50 +02:00
hex=$(printf "%010X" "$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