Exp - No: Date: Vacuum Cleaner Problem
Exp - No: Date: Vacuum Cleaner Problem
NO: DATE:
VACUUM CLEANER PROBLEM
AIM:
ALGORITHM:
OUTPUT:
PROGRAM:
class VacuumCleaner:
def __init__(self, grid):
self.grid = grid
self.x = 0
self.y = 0
self.rows = len(grid)
self.cols = len(grid[0])
self.directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] # Right, Down, Left, Up
def print_grid(self):
for row in self.grid:
print(' '.join(map(str, row)))
print()
def move_right(self):
if self.y < self.cols - 1:
self.y += 1
else:
self.move_down()
def move_down(self):
if self.x < self.rows - 1:
self.x += 1
self.y = 0
else:
self.x = 0
self.y = 0
def clean(self):
if self.grid[self.x][self.y] == 1:
self.grid[self.x][self.y] = 0
def is_done(self):
return all(cell == 0 for row in self.grid for cell in row)
def main():
# User input for grid dimensions
rows = int(input("Enter number of rows: "))
cols = int(input("Enter number of columns: "))
vacuum = VacuumCleaner(grid)
print("Initial Grid:")
vacuum.print_grid()
print("Cleaning completed!")
vacuum.print_grid()
if __name__ == "__main__":
main()
RESULT: