Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. class Stuwmeer(object):
  2. def __init__(self, landschap):
  3. self.landschap = landschap
  4. self.landschap = list(self.landschap)
  5.  
  6. aantal_rijen = max(self.landschap)
  7. lijst = []
  8. while aantal_rijen != 0:
  9. for i in range(len(self.landschap)):
  10. if self.landschap[i] >= aantal_rijen:
  11. lijst.append(1)
  12. elif self.landschap[i] < aantal_rijen:
  13. lijst.append(0)
  14. lijst.append("\n")
  15. hoogstegetal -= 1
  16.  
  17. lijsthekjes = []
  18. for elem in lijst:
  19. if elem == 1:
  20. lijsthekjes.append("#")
  21. elif elem == 0:
  22. lijsthekjes.append(" ")
  23. else:
  24. lijsthekjes.append("\n")
  25. #laatste \n verwijderen
  26. lijsthekjes.pop(-1)
  27.  
  28. self.lijst_per_hoogte = lijsthekjes
  29.  
  30.  
  31.  
  32. def __repr__(self):
  33. #een lange string maken
  34. return "".join(self.lijst_per_hoogte)
  35.  
  36. def vullen(self):
  37.  
  38. startgetal = self.lijst_per_hoogte.count("~")
  39. #maak een lijst van strings
  40. string = self.__repr__()
  41. lagen = string.split("\n")
  42.  
  43. #overloop elke laag en vervang de spaties tussen de hekjes
  44. lijsthekjes = []
  45. for index in range(len(lagen)):
  46. lijst_laag = list(lagen[index])
  47. index1 = (lagen[index]).find("#")
  48. index2 = (lagen[index]).rfind("#")
  49. for i in range(len(lijst_laag)):
  50. if lijst_laag[i] == ' ' and i in range(index1,index2):
  51. lijst_laag[i] = "~"
  52. lijsthekjes.append(lijst_laag[i])
  53. lijsthekjes.append("\n")
  54. lijsthekjes.pop(-1)
  55. self.lijst_per_hoogte = lijsthekjes
  56.  
  57. eindgetal = self.lijst_per_hoogte.count("~")
  58.  
  59. return eindgetal - startgetal
  60.  
  61.  
  62. def lozen(self):
  63.  
  64. getal = self.lijst_per_hoogte.count("~")
  65.  
  66. lijsthekjes = self.lijst_per_hoogte
  67.  
  68. for i in range(len(lijsthekjes)):
  69. if lijsthekjes[i] == "~":
  70. lijsthekjes[i] = " "
  71.  
  72. self.lijst_per_hoogte = lijsthekjes
  73.  
  74. return getal
  75.  
  76. def infiltreren(self):
  77.  
  78. startgetal = self.lijst_per_hoogte.count("~")
  79.  
  80. landschap = self.landschap
  81. stringhekjes = self.__repr__()
  82. lagen = stringhekjes.split("\n")
  83. string = ""
  84.  
  85. for laag in lagen:
  86. lijst_laag = list(laag)
  87. for i in range(len(lijst_laag)):
  88. teller1, teller2 = 0, 0
  89. if landschap[i] == 0 and lijst_laag[i] == "~":
  90. while lijst_laag[i + teller1] != "#":
  91. lijst_laag[i + teller1] = " "
  92. teller1 += 1
  93.  
  94. while lijst_laag[i - teller2] != "#":
  95. lijst_laag[i - teller2] = " "
  96. teller2 += 1
  97. string += "".join(lijst_laag) + "\n"
  98.  
  99. lijsthekjes = list(string)
  100. lijsthekjes.pop(-1)
  101.  
  102. self.lijst_per_hoogte = lijsthekjes
  103.  
  104. eindgetal = self.lijst_per_hoogte.count("~")
  105.  
  106. return startgetal - eindgetal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement