I want to solve this problem in Scala.
My code:
def dividers(n: Int) =
(1 until n) filter (x => n%x == 0)
def sumOfDividers(n: Int) = dividers(n).sum
val abNumbers = (1 to 28123) filter (x => sumOfDividers(x) > x)
The next step in my solutios is to make some sequence containing all possible of abundant number from abNumbers sequence. I’ve tried to do this with enhanced for loop, but it throws Java Heap Exception at runtime. How can i place all these sums into a Stream structure?
Use the toStream method on ranges:
Or am I missing something?