Created
September 10, 2017 04:47
-
-
Save snahor/eb844da9d289715b9000f8f1148c0f22 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
def fib(): | |
a, b = 0, 1 | |
while True: | |
yield a | |
a, b = b, a + b |
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
# Hofstadter Figure-Figure sequences | |
# F(1) = 1, S(1) = 2 | |
# F(n) = F(n - 1) + S(n - 1) | |
def fig(): | |
f, s = 1, 2 | |
used = [] | |
while True: | |
yield f, s | |
f = f + s | |
used.append(f) | |
s += 1 | |
if used[0] == s: | |
s += 1 | |
used = used[1:] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment