Untitled

 avatar
unknown
plain_text
a year ago
1.0 kB
21
Indexable
environment = [
    ["D", ".", "D", "."],
    ["D", ".", "D", "."],
    ["D", ".", ".", "."],
    ["D", "D", "D", "D"]
]

at_x, at_y = 0, 0
cleaned = 0;


def state():
    for i in range(4):         
        row = ""
        for j in range(4):     
            if i == at_x and j == at_y:
                row += "A "
            else:
                row += environment[i][j] + " "
        print(row)
    print("----------------------------------")

print("Initial Environment:")
state()

while True:
    if environment[at_x][at_y] == "D":
        cleaned += 1
        environment[at_x][at_y] = "."
        print(f"Cleaned cell at ({at_x}, {at_y})")
    
    state()

    dirty= 0
    
    for row in environment: 
      if "D" in row:           
        dirty = True
        break              


    if not dirty:
      print("Cleaning complete. Total cells cleaned:", cleaned)
      break
    
    if at_y < 3:
        at_y += 1
    else:
        at_y = 0
        if at_x < 3:
            at_x += 1

    
    

        
Editor is loading...
Leave a Comment