Skip to content

Conversation

@ErdemT09
Copy link
Collaborator

@ErdemT09 ErdemT09 commented Jun 11, 2021

Resolves #65

Algorithm:

Consider this grid for example, where brown tiles are the walls and the green ones are the enemies:
image
When we start the counting for each tile, we first start by counting the first column at the first row. Here, we count 2 for the row and 1 one the column. When we continue to count in the same row, we don't encounter any new walls, hence the count for this row should not change. We can keep the count of this row in a variable and change it only if we encounter a wall, otherwise we would be making unneeded checks.

The same things is valid for the columns. We have counted the column values up until their end or a wall as well. Since we are not directly iterating through the columns, we can keep the number of enemies that we have hit in an array for the columns.
At the first column, for example, we can always reuse the information we have experienced from the first row, as we do not encounter any new walls their.

In places like the 3rd row, our row counter will be reset when we come across a new wall.

@ErdemT09
Copy link
Collaborator Author

The runtime is between 6 and 16 ms.
image

@ErdemT09 ErdemT09 marked this pull request as ready for review June 12, 2021 15:49
Copy link
Collaborator

@altay9 altay9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean explanation and a self-expressive modular code Erdem. Thanks.

@ErdemT09 ErdemT09 merged commit 6d6ba04 into master Jun 13, 2021
@ErdemT09 ErdemT09 deleted the 361.-Bomb-Enemy branch June 13, 2021 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

361. Bomb Enemy

3 participants