Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Stuwmeer(object):
- def __init__(self, landschap):
- self.landschap = landschap
- self.landschap = list(self.landschap)
- aantal_rijen = max(self.landschap)
- lijst = []
- while aantal_rijen != 0:
- for i in range(len(self.landschap)):
- if self.landschap[i] >= aantal_rijen:
- lijst.append(1)
- elif self.landschap[i] < aantal_rijen:
- lijst.append(0)
- lijst.append("\n")
- hoogstegetal -= 1
- lijsthekjes = []
- for elem in lijst:
- if elem == 1:
- lijsthekjes.append("#")
- elif elem == 0:
- lijsthekjes.append(" ")
- else:
- lijsthekjes.append("\n")
- #laatste \n verwijderen
- lijsthekjes.pop(-1)
- self.lijst_per_hoogte = lijsthekjes
- def __repr__(self):
- #een lange string maken
- return "".join(self.lijst_per_hoogte)
- def vullen(self):
- startgetal = self.lijst_per_hoogte.count("~")
- #maak een lijst van strings
- string = self.__repr__()
- lagen = string.split("\n")
- #overloop elke laag en vervang de spaties tussen de hekjes
- lijsthekjes = []
- for index in range(len(lagen)):
- lijst_laag = list(lagen[index])
- index1 = (lagen[index]).find("#")
- index2 = (lagen[index]).rfind("#")
- for i in range(len(lijst_laag)):
- if lijst_laag[i] == ' ' and i in range(index1,index2):
- lijst_laag[i] = "~"
- lijsthekjes.append(lijst_laag[i])
- lijsthekjes.append("\n")
- lijsthekjes.pop(-1)
- self.lijst_per_hoogte = lijsthekjes
- eindgetal = self.lijst_per_hoogte.count("~")
- return eindgetal - startgetal
- def lozen(self):
- getal = self.lijst_per_hoogte.count("~")
- lijsthekjes = self.lijst_per_hoogte
- for i in range(len(lijsthekjes)):
- if lijsthekjes[i] == "~":
- lijsthekjes[i] = " "
- self.lijst_per_hoogte = lijsthekjes
- return getal
- def infiltreren(self):
- startgetal = self.lijst_per_hoogte.count("~")
- landschap = self.landschap
- stringhekjes = self.__repr__()
- lagen = stringhekjes.split("\n")
- string = ""
- for laag in lagen:
- lijst_laag = list(laag)
- for i in range(len(lijst_laag)):
- teller1, teller2 = 0, 0
- if landschap[i] == 0 and lijst_laag[i] == "~":
- while lijst_laag[i + teller1] != "#":
- lijst_laag[i + teller1] = " "
- teller1 += 1
- while lijst_laag[i - teller2] != "#":
- lijst_laag[i - teller2] = " "
- teller2 += 1
- string += "".join(lijst_laag) + "\n"
- lijsthekjes = list(string)
- lijsthekjes.pop(-1)
- self.lijst_per_hoogte = lijsthekjes
- eindgetal = self.lijst_per_hoogte.count("~")
- return startgetal - eindgetal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement