Skip to content

Instantly share code, notes, and snippets.

@shelling
Created September 21, 2016 07:37
Show Gist options
  • Save shelling/4f86dbb47df1b7cbe993f2320fe2cfaa to your computer and use it in GitHub Desktop.
Save shelling/4f86dbb47df1b7cbe993f2320fe2cfaa to your computer and use it in GitHub Desktop.
# 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