A small piece of bash script that will calculate the prime factors, given a number
factors() { num=$1 sqrt=`echo "sqrt($num)" | bc` for (( i=$sqrt;$i>=2;i-- )) do if [[ `echo $num % $i | bc` -eq 0 ]] then echo "$i `echo $num/$i | bc`" fi done }
A small piece of bash script that will calculate the prime factors, given a number
factors() { num=$1 sqrt=`echo "sqrt($num)" | bc` for (( i=$sqrt;$i>=2;i-- )) do if [[ `echo $num % $i | bc` -eq 0 ]] then echo "$i `echo $num/$i | bc`" fi done }