Created
September 19, 2016 04:26
-
-
Save louisswarren/bc18fffc468ffbc246119ec09f5f21c1 to your computer and use it in GitHub Desktop.
This should be compatible with your Cosc367 project
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
from sequences import * | |
class ai_class: | |
def __getitem__(self, items): | |
if items[-1] is not Ellipsis: | |
yield from items | |
return | |
expression = find_sequence(items[:-1]) | |
yield from items[:-1] | |
x, y = items[-3:-1] | |
i = len(items) | |
while True: | |
d = {'i': i, 'x': x, 'y': y, | |
'+': lambda a, b: a + b, | |
'-': lambda a, b: a - b, | |
'*': lambda a, b: a * b} | |
r = evaluate(expression, d) | |
yield r | |
i += 1 | |
x = y | |
y = r | |
ai = ai_class() | |
print(list(__import__('itertools').islice(ai[1, 1, 2, 3, 5, 8, ...], 15))) | |
# [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment