Skip to content

Instantly share code, notes, and snippets.

@lkacenja
Created May 19, 2015 22:55
Show Gist options
  • Save lkacenja/d8bda119de4c56af860a to your computer and use it in GitHub Desktop.
Save lkacenja/d8bda119de4c56af860a to your computer and use it in GitHub Desktop.
Python 23 Generator
class Prime23(object):
step = 0
prime = 1
cases = {
1 : 2,
2 : 3,
3 : 5
}
@classmethod
def __iter__(self):
return self
@classmethod
def next(self):
if (self.step != 0):
self.prime += self.step
self.step = 6 - self.step
else:
self.prime = self.cases[self.prime]
if (self.prime == 5):
self.step = 2
return self.prime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment