Skip to content

Instantly share code, notes, and snippets.

@Zami77
Created November 28, 2015 17:29
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 Zami77/285062e0c0cbf2053ad0 to your computer and use it in GitHub Desktop.
Save Zami77/285062e0c0cbf2053ad0 to your computer and use it in GitHub Desktop.
a small program where a plant grows 1 seed a week, and that one seed plants other plants. Also every week the plant gains one seed in total. it takes 2 inputs, how many people and how many starting plants.
class funnyPlant(object):
def __init__(self):
self.seed = 0
def addSeed(self):
self.seed += 1
def getSeed(self):
return int(self.seed)
class plantSolver(object):
def __init__(self,numOfPeople,startingPlants):
self.startingPlants = int(startingPlants)
self.numOfPeople = int(numOfPeople)
self.plants = []
self.totalSeeds = 0
self.week = 0
def solvePlants(self):
for i in range(0,int(self.startingPlants)):
self.plants.append(funnyPlant())
while self.totalSeeds < self.numOfPeople:
for i in range(0,self.totalSeeds):
self.plants.append(funnyPlant())
self.week += 1
for p in self.plants:
self.totalSeeds += p.getSeed()
p.addSeed()
for i in range(0,int(self.startingPlants)):
self.plants.append(funnyPlant())
return self.week
def main():
print "Main:"
numOfPeople = raw_input("Num of people:")
startPlants = raw_input("Starting plants:")
print plantSolver(numOfPeople,startPlants).solvePlants(),"weeks"
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment