Last active
August 29, 2015 14:08
-
-
Save tixxit/a9628b6661b4077ff88c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// This prints the top 10 alternative bases, ordered by the (# of factors, excluding 1 & base) / base. | |
// So, the last number printed has the highest number of factors relative to the size of the base. | |
// | |
// Turns out that 12 is a great base! | |
object Main extends App { | |
// 7560 is the smallest number that is divisible by all number between 1 and 10. | |
val facMap = (1 to 7560).foldLeft(Map.empty[List[Int], Int]) { (acc, n) => | |
val factors = (2 to (n / 2)).filter(n % _ == 0).toList | |
if (acc contains factors) acc | |
else acc + (factors -> n) | |
} | |
val result = facMap.toList.map { case (factors, n) => | |
(factors.size.toDouble / n.toDouble) -> n | |
}.sorted.map(_.swap) | |
result.takeRight(10) foreach { case (n, k) => | |
println(s"$n -> $k") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result: