Skip to content

Instantly share code, notes, and snippets.

@zerosum
Created May 25, 2017 09:19
Show Gist options
  • Save zerosum/f48ebc7dd91dfb6acd50decb7e854237 to your computer and use it in GitHub Desktop.
Save zerosum/f48ebc7dd91dfb6acd50decb7e854237 to your computer and use it in GitHub Desktop.
Project Euler: Problem 26
def loop(numer: Int, denom: Int, digits: Seq[(Int, Int)]): Int = {
val quot = numer / denom
val rem = numer % denom
val digit = (quot, rem)
if (rem == 0) {
0
} else if (digits.contains(digit)) {
digits.indexWhere(_ == digit) + 1
} else {
loop(rem * 10, denom, digit :: digits.toList)
}
}
(2 until 1000).map(n => n -> loop(10, n, Nil)).maxBy(_._2)._1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment