Factors of an integer: Difference between revisions

(→‎{{header|Minimal BASIC}}: {{works with|Commodore BASIC}} added)
Line 6,239:
}
}</lang>
SinceBrute factorsforce can't be higher thanuntil sqrt(num) is enough, the code above can be edited as follows (Scala 3 enabled)
<lang Scala>def factors(num: Int) = {
val list = (1 to math.sqrt(num).floor.toInt).filter(num {% divisor_ =>= 0)
list ++ list.reverse.dropWhile(d => d*d == num).map(num / _)
num % divisor == 0
}
}</lang>
 
51

edits