Debian Codegraph @

factr.sh

raw symbols SCIP
1 #!/bin/bash
2 # factr.sh: Factor a number
3
4 MIN=2 # Will not work for number smaller than this.
5 E_NOARGS=85
6 E_TOOSMALL=86
7
8 if [ -z $1 ]
9 then
10 echo "Usage: $0 number"
11 exit $E_NOARGS
12 fi
13
14 if [ "$1" -lt "$MIN" ]
15 then
16 echo "Number to factor must be $MIN or greater."
17 exit $E_TOOSMALL
18 fi
19
20 # Exercise: Add type checking (to reject non-integer arg).
21
22 echo "Factors of $1:"
23 # -------------------------------------------------------
24 echo "$1[p]s2[lip/dli%0=1dvsr]s12sid2%0=13sidvsr[dli%0=\
25 1lrli2+dsi!>.]ds.xd1<2" | dc
26 # -------------------------------------------------------
27 # Above code written by Michel Charpentier &lt;[email protected]&gt;
28 # (as a one-liner, here broken into two lines for display purposes).
29 # Used in ABS Guide with permission (thanks!).
30
31 exit
32
33 # $ sh factr.sh 270138
34 # 2
35 # 3
36 # 11
37 # 4093