-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseries.sh
85 lines (80 loc) · 1.49 KB
/
series.sh
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
function copyright {
echo ""
echo "*********************"
echo "* *"
echo "*This script is to *"
echo "*series and *"
echo "*numbers. *"
echo "*Copyright 2020 *"
echo "*Pro-Haker *"
echo "*********************"
echo ""
}
function help {
echo "SYNTAX: $0 <mersenne|fibonacci|palindromic|lucas> <number_quantity|number>"
}
function fibonacci {
# read -p "How much Fibonacci's numbers you want to see?" n
a=0
b=1
n=$1
for (( i=1; i<=n; i++ ));
do
echo "$i Fibonacci's number is $a"
fibonacci=$((a+b))
a=$b
b=$fibonacci
done
}
function mersenne {
# read -p "How much Mersenne's numbers you want to see? " n
n=$1
for (( i=1; i<=n; i++ )); do
# a=$((2^i))
mersenne=$((2 ** i -1))
# echo $a
echo "$i Mersenne's number is $mersenne"
done
}
function palindromic_number {
n=$1
if [[ $(rev <<< "$n") == "$n" ]]; then
echo "Number is palindromic number"
else
echo "Number isn't palindromic number"
fi
}
function lucas {
a=2
b=1
n=$1
for (( i=1; i<=n; i++ ));
do
echo "$i Lucas's number is $a"
lucas=$((a+b))
a=$b
b=$lucas
done
}
if [ $# -lt 2 ]; then
help
copyright
else
if [ $1 == "fibonacci" ]; then
fibonacci $2
copyright
elif [ $1 == "mersenne" ]; then
mersenne $2
copyright
elif [ $1 == "palindromic" ]; then
palindromic_number $2
copyright
elif [ $1 == "lucas" ]; then
lucas $2
copyright
else
help
copyright
fi
fi