def findFactors(num) num = num.to_f facs = [] knockout = {} sqrt = Math.sqrt(num) 1.upto sqrt.truncate do |n| next if !knockout[n].nil? qt = num / n if qt == qt.truncate facs.push n facs.push qt.to_i unless n == qt elsif n != 1 i = 0 while i <= sqrt knockout[i] = true i += n end end end facs end def findFactorsSort(num) findFactors(num).sort end