Created
September 21, 2016 07:37
-
-
Save shelling/4f86dbb47df1b7cbe993f2320fe2cfaa to your computer and use it in GitHub Desktop.
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
# Project Euler 26 | |
def recurring(number) | |
remainders = Hash.new(0) | |
value = 1 | |
position = 0 | |
length = 0 | |
while value != 0 && remainders[value] == 0 | |
remainders[value] = position | |
value = value * 10 | |
value = value % number | |
position += 1 | |
end | |
length = position - remainders[value] if position - remainders[value] > length | |
length | |
end | |
puts (1...1000).map { |d| | |
[d, recurring(d)] | |
}.max { |a, b| | |
a[1] <=> b[1] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment