# def large_prime(n)

return [] if n==1

p factor = (2…n).find {|x| n % x == 0}

p [factor] + large_prime(n/factor)

end

p large_prime(56)

the factors of 56 are [2,2,2,7]

Can someone please tell me step by step whats happening in this code

using

56 as the argument?

I dont understand how the find method is able to get all the prime

factors.

If the condition is n%x == 0, then 4 should be added onto the factors

too right?

I get that find grabs the first value that meets its condition, so

shouldn’t it be [2,4,7,14 etc] instead of [2,2,2,7]? I dont understand

how this line works…

And then 4th line. What is it doing exactly? Is it just taking n and

dividing it by all the factors? so 56/2/2/2/7 until 1?