Skip to content

Instantly share code, notes, and snippets.

@RafalSladek
Created April 5, 2016 11:37
Show Gist options
  • Save RafalSladek/c94bc8bb05b0ddacf1ffafd8c2563571 to your computer and use it in GitHub Desktop.
Save RafalSladek/c94bc8bb05b0ddacf1ffafd8c2563571 to your computer and use it in GitHub Desktop.
this recurisve function returns prime factors of given number
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