Created
May 25, 2017 09:19
-
-
Save zerosum/f48ebc7dd91dfb6acd50decb7e854237 to your computer and use it in GitHub Desktop.
Project Euler: Problem 26
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 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