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

38 lines
956 B
Bash

#!/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