#Class practice in Python
#Problem 1
#The Turing Machine
"""The Turing Machine is a mathematical machine that has some infinite array of cells(for this example use 1000).
In each of these cells, it contains some type of number. The macine also has a read and write head component, which with commands, can move across the type, read, write, or print the contents of any cells
Your task is to implement a turing machine that takes commands in the form of strings.
It must use the following commands:
">": Move the head one index forward
"<": Move the head one index back
"+": increment the number of the current cell by 1.
"-":decrement the number of the current cell by 1.
".":Print the contents of the current cell.
The eval method of the class should be the one to process these commands.
d = TuringMachine()
=> None
d.eval(".++.")
0
2
=> None
d.eval(".++.")
2
4
=> None
d.eval(".++--.")
4
4
=> None
d.eval(">>++++.")
4
"""
class TuringMachine:
def __init__(self):
self.cells = [0 for i in range(1000)]
self.head = 0
def eval(self, code):
pass
#Problem 2
#Family Tree
"""
Create a class that implements a family tree.
Here, every node in the tree is a person, whom has two parents, and one or more children.
Each node is called a "Person", and that person has some surname attribute, a string.
Each person can create a child with another person whom does not have the same surname.
Additionally, each person has some first name and a gender, "M" or "F".
=> None
a = Person("josh", "farley", "M")
=> None
a
=> (josh, farley) -> [[]]
b = Person("sarah", "smith", "F")
=> None
a.create_child(b, "sam")
=> None
a
=> (josh, farley) -> [[(sam, farley) -> [[]]]]
b
=> (sarah, smith) -> [[(sam, farley) -> [[]]]]
"""
class Person:
def __init__(self, first, last, gender):
assert gender in ["M", "F"]
"""Your code here"""
pass
def __repr__(self):
return "({0}, {1}) -> [{2}]".format(self.first, self.last, self.children)
def pickgender(self):
#facilitates a random picking of gender
import random
return random.choice(["M", "F"])
def create_child(self, other, first):
"""Your code here"""
pass