jweinst1
10/28/2016 - 10:40 PM

gistfile1.txt

#Generator practice with classes

class Link:
	
	def __init__(self, first, next=None):
		self.first = first
		self.next = next
		
	def __repr__(self):
		return "({0}, {1})".format(self.first, self.next)
		
		
#Question 1
#Define a generator that on each next() call, returns a linked list of 
#numbers from 0 to infinity, making the chain one link longer each time
"""
   f = lazy_numbers()
=> None
   next(f)
=> (0, None)
   next(f)
=> (0, (1, None))
   next(f)
=> (0, (1, (2, None)))
   next(f)
=> (0, (1, (2, (3, None))))
   next(f)
=> (0, (1, (2, (3, (4, None)))))
   next(f)
=> (0, (1, (2, (3, (4, (5, None))))))
   next(f)
=> (0, (1, (2, (3, (4, (5, (6, None)))))))
"""
def lazy_numbers():
	pass
		
		
#Question 2
#define a generator that yields the sequence of strings of integers from 1 to infinity, with each next() call returning the next string.
#You cannot use integers for this problem. You must construct integers with strings
#Hint the .join method of an empty string joins an array of strings together
# "".join(["a", "b"]) => "ab"
"""
   f = intseq()
=> None
   next(f)
=> '1'
   next(f)
=> '2'
   next(f)
=> '3'
   next(f)
=> '4'
   next(f)
=> '5'
   next(f)
=> '6'
   next(f)
=> '7'
   next(f)
=> '8'
   next(f)
=> '9'
   next(f)
=> '10'
"""
def intseq():
	pass
						

"""String Drawing Practice"""

#Question 3
#Define a generator that draws a zigzag line, of some width w. it will generate an infinite number of moving lines
#to mark the line use a star *
#HINT:use the join method here 
def zigzag(w):
	pass