Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Instead of repeatedly calling replaceElement to update the grid, we use the setElement function to update a single cell, and then we process the valid neighbors using a combination of map and filter.
- We define a list of neighbors relative to the current cell. In this case, we exclude diagonals (as indicated by dx /= dy) to mimic the original behavior.
- We use filter to retain only the valid neighbor positions within the grid bounds.
- We recursively call spreadLight for each valid neighbor and update the grid with the light. This is done using foldl and generates a new grid with light spreading efficiently.
Advertisement
Add Comment
Please, Sign In to add comment