Created
December 16, 2013 17:58
-
-
Save berdario/7991399 to your computer and use it in GitHub Desktop.
Both snippets are mostly the same:
the factor solution is a recursive word, while the python one has an imperative iteration. The complexity of the function (in number of steps) is linear with the size of the smaller input
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
: gcd ( a b -- c ) over zero? [ nip ] [ over mod swap gcd ] if ; |
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
def gcd(a, b): | |
while b: | |
a, b = b, a % b | |
return a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment