Created
June 8, 2016 19:30
-
-
Save anonymous/edcc55be663d21a989a10bf58cf6c03f to your computer and use it in GitHub Desktop.
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
#!/usr/local/bin/ruby | |
def runner( x, y, size, num ) | |
=begin | |
if x == size && y == size | |
puts "Path found" | |
end | |
unless x + 1 > size | |
runner( x + 1, y, size ) | |
end | |
unless y + 1 > size | |
runner( x, y + 1, size ) | |
end | |
=end | |
if x + 1 <= size && y + 1 <= size | |
num + runner( x + 1, y, size, num) + runner( x, y + 1, size, num) | |
elsif x + 1 <= size && y + 1 > size | |
num + runner( x + 1, y, size, num) | |
elsif x + 1 > size && y + 1 <= size | |
num + runner( x, y + 1, size, num) | |
else | |
return 1 | |
end | |
puts num | |
end | |
runner( 0 , 0, 2, 0 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment