Skip to content

Instantly share code, notes, and snippets.

@jokester
Created November 1, 2011 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jokester/1330477 to your computer and use it in GitHub Desktop.
Save jokester/1330477 to your computer and use it in GitHub Desktop.
solution to project euler no.14
#!/usr/bin/ruby
class PE14
@@l=Hash.new
@@l[1]=1
def PE14.eval x
if @@l[x] #found
return @@l[x]
else
if x%2==0 #even
y=PE14.eval(x/2)
else #old
y=PE14.eval(1+3*x)
end
@@l[x]=y+1
end
end
end
p (1..1000000).max_by {|x| PE14.eval x}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment