Skip to content

Instantly share code, notes, and snippets.

@beoran
Created November 16, 2012 18:55
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 beoran/4089890 to your computer and use it in GitHub Desktop.
Save beoran/4089890 to your computer and use it in GitHub Desktop.
nsteps the rubyway.
# this has only one side effect, it defines the nsteps fmethod
def nsteps(x, y)
if (x.even?)
return false if(y.odd?)
return x * 2 if(x == y)
return x * 2 - 1 if (x==(y-2))
return false
else
return false if(y.even?)
return x * 2 if(x == y)
return x * 2 - 1 if (x==(y-2))
return false
end
end
# this has no side effects effects
lambda do |x, y|
if (x.even?)
return false if(y.odd?)
return x * 2 if(x == y)
return x * 2 - 1 if (x==(y-2))
return false
else
return false if(y.even?)
return x * 2 if(x == y)
return x * 2 - 1 if (x==(y-2))
return false
end
end.call(1, 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment