Created
April 5, 2016 11:37
-
-
Save RafalSladek/c94bc8bb05b0ddacf1ffafd8c2563571 to your computer and use it in GitHub Desktop.
this recurisve function returns prime factors of given number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getPrimeFactors( | |
yourNumber: Int, | |
primeFactors: List[Int]): List[Int] = { | |
for (i <- 2 to yourNumber if (yourNumber % i == 0)) { | |
return getPrimeFactors(yourNumber / 2, primeFactors :+ i) | |
} | |
primeFactors | |
} | |
getPrimeFactors(36, List()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment