Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save codeperfectplus/2ece78a078accff5f2f8dbfa7cc2ff07 to your computer and use it in GitHub Desktop.

Select an option

Save codeperfectplus/2ece78a078accff5f2f8dbfa7cc2ff07 to your computer and use it in GitHub Desktop.
class EvenStream(object):
def __init__(self):
self.current = 0
def get_next(self):
to_return = self.current
self.current += 2
return to_return
class OddStream(object):
def __init__(self):
self.current = 1
def get_next(self):
to_return = self.current
self.current += 2
return to_return
def print_from_stream(n, stream=EvenStream()):
temp = stream.current
for _ in range(n):
print(stream.get_next())
stream.current =temp
queries = int(input())
for _ in range(queries):
stream_name, n = input().split()
n = int(n)
if stream_name == "even":
print_from_stream(n)
else:
print_from_stream(n, OddStream())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment