Skip to content

Instantly share code, notes, and snippets.

@track8
Created October 7, 2016 09:04
Show Gist options
  • Save track8/0e8c5c4d05185ad3e2eea403451c9e95 to your computer and use it in GitHub Desktop.
Save track8/0e8c5c4d05185ad3e2eea403451c9e95 to your computer and use it in GitHub Desktop.
def euler_62
n = 1
hash = Hash.new {|h, k| h[k] = []}
current_length = 1
while true
cubic = n**3
key = cubic.to_s.split('').sort.join
hash[key] << cubic
if key.length > current_length
current_length = key.length
r = hash.values.find_all {|v| v.length == 5}.flatten.min
break r if r
end
n += 1
end
end
p euler_62
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment