Created
November 28, 2015 17:29
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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