Factors of an integer: Difference between revisions

m
→‎{{header|Scala}}: Text/code separated
m (→‎{{header|C sharp|C#}}: formatted with Visual Code)
m (→‎{{header|Scala}}: Text/code separated)
Line 5,011:
 
=={{header|Scala}}==
<lang Scala>
Brute force approach:
<lang Scala>def factors(num: Int) = {
 
def factors(num: Int) = {
(1 to num).filter { divisor =>
num % divisor == 0
}
}</lang Scala>
}
Since factors can't be higher than sqrt(num), the code above can be edited as follows
<lang Scala>def factors(num: Int) = {
(1 to sqrt(num)).filter { divisor =>
num % divisor == 0
}
}</lang>
}
</lang>
 
=={{header|Scheme}}==
Anonymous user