#Find coordinates of every occurrence of element in matrix
17 messages · Page 1 of 1 (latest)
i think you're looking for _ but its not clear from your question
you meant looking for * ?
I looking for the * characters and their coordinates, (looking for the stars ), i have managed to get the point when i get the Col numbers for each of them, now i!m trying to add the row numbers to it
can you paste the data before you ran with index
have you got livebook? this is a good problem for it
Write interactive and collaborative code notebooks in Elixir.
no, i sadly can't use more than the basic Elixir provides
data = """
- * - - -
- - - - -
- - * - *
- - - - -
* - - - *
"""
``` ```elixir
rows =
data
|> String.split("\n") # split by row
|> Enum.reverse() # reverse so coords start at the bottom
|> Enum.reject(&(&1 == "")) # remove the extra row
``` ```elixir
locations =
for {row, row_index} <- Enum.with_index(rows) do
cells =
row
|> String.split() # split by whitespace
|> Enum.reverse() # reverse so coords start at the left
for {"*", col_index} <- Enum.with_index(cells) do
{row_index + 1, col_index + 1}
end
end
``` ```elixir
IO.puts(data)
locations =
locations
|> List.flatten() # remove emptys
load this file into livebook
theres a problem with it but i dont have time to do more, however that should get you close 🙂