Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This should be compatible with your Cosc367 project
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