Skip to content

Instantly share code, notes, and snippets.

@louisswarren
Created September 19, 2016 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save louisswarren/bc18fffc468ffbc246119ec09f5f21c1 to your computer and use it in GitHub Desktop.
Save louisswarren/bc18fffc468ffbc246119ec09f5f21c1 to your computer and use it in GitHub Desktop.
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