Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- field = np.zeros((1024, 1024), dtype=int)
- x, y = 512, 512
- directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
- direction_index = 0
- while 0 <= x < 1024 and 0 <= y < 1024:
- field[y, x] = 1 - field[y, x]
- if field[y, x] == 0:
- direction_index = (direction_index + 1) % 4
- else:
- direction_index = (direction_index - 1) % 4
- dx, dy = directions[direction_index]
- x += dx
- y += dy
- black_cells = np.sum(field)
- print("Число черных клеток на пути муравья:", black_cells)
- plt.imshow(field, cmap='binary')
- plt.axis('off')
- plt.savefig('ant_path.png', format='png', dpi=300)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement