Guest User

Untitled

a guest
Dec 3rd, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. import math
  2.  
  3. ter = open("map.txt","r")
  4. xpos = 0 #current x position
  5. ypos = 0 #current y position
  6. down = 1 #how many down
  7. right = 3 #how many right
  8. lines = [] #list of all the lines of the map
  9. trees = 0 #amount of trees detected
  10.  
  11. for line in ter: #do loop for line in file
  12.     lines.append(line.strip()) #make list of all the lines of the map
  13.  
  14. for i in range(math.floor(len(lines)/down)): #do loop the amount of lines divided by how many down (rounded down)
  15.     if (lines[ypos])[xpos] == "#": #if "tree" detected
  16.         trees += 1 #add tree to the amount
  17.     xpos += right #add to the x position
  18.     ypos += down #add to the y position
  19.     if xpos >= len(lines[i]): #if x position is greater or same as the length of one map line
  20.         xpos = xpos-len(lines[i]) #subtract length of one map line from x position
  21. print(trees,"trees")
  22.  
  23.    
  24.    
  25.  
  26.  
Advertisement
Add Comment
Please, Sign In to add comment