-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathfactors
executable file
·48 lines (40 loc) · 951 Bytes
/
factors
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
#!/usr/bin/env bash
check_factor()
{
if [ $# -ne 3 ];
then
args=("$@")
count=0
num2=1
for a in ${args[*]};
do
if [ $count -gt 1 ];
then
num2=$(echo $a*$num2 | bc)
fi
count=$((count + 1))
done
else
num2=$3
fi
num1=$2
num=$(echo "$1" | tr ':' '=')
result=$(echo "if($num2 > $num1) 1 else 0" | bc)
if ((result == 1)); then
numcp=$num1
num1=$num2
num2=$numcp
fi
echo "$num$num1*$num2"
}
if [ $# -ne 1 ]
then
echo 'Usage: factors <file>'
exit 1
else
while read i
do
result=$(factor "$i")
check_factor $result
done < "$1"
fi