#๐Ÿ”’ Find nearest instance in array

8 messages ยท Page 1 of 1 (latest)

crisp dove
#

Going to bed after this but will check in the morning

If I have an array, say:

    ['0', '0', '0', '0', '0'],
    ['0', '0', 'W', '0', '0'],
    ['0', 'W', '0', '0', '0'],
    ['0', '0', '0', '0', '0'],
    ['0', '0', '0', '0', '0']
] ```

And I wanted to find the distance of every "0" from any  "W", how should I go about this?

Thanks in advance for any suggestions- saw something about BFS algorithms online but a bit confused by them considering it's 1 am and wondering if there isn't an simpler way to go about it. Thanks and goodnight~
dry windBOT
#

@crisp dove

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

bronze horizon
#

Well the easiest way is just run a BFS on every W and keep the minimum

#

Slightly more complex but way faster is to actually make a graph, then merge all the W into just 1 node

shadow gate
#

pretty much a multisource BFS

#

that's assuming you use Manhattan distance

dry windBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.