Skip to content

Instantly share code, notes, and snippets.

@tixxit
Last active August 29, 2015 14:08
Show Gist options
  • Save tixxit/a9628b6661b4077ff88c to your computer and use it in GitHub Desktop.
Save tixxit/a9628b6661b4077ff88c to your computer and use it in GitHub Desktop.
// 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")
}
}
@tixxit
Copy link
Author

tixxit commented Nov 3, 2014

Result:

36 -> 0.19444444444444445
10 -> 0.2
20 -> 0.2
30 -> 0.2
18 -> 0.2222222222222222
4 -> 0.25
8 -> 0.25
24 -> 0.25
6 -> 0.3333333333333333
12 -> 0.3333333333333333

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment