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