Created
November 16, 2012 18:55
-
-
Save beoran/4089890 to your computer and use it in GitHub Desktop.
nsteps the rubyway.
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
# 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