Looking for assistance on how to create a function that takes a map of this format, for example:
{[1 0] 1
[0 0] 2
[1 1] 3
[0 1] 4}
And returns a 2d vector that looks like, for example:
[[2 1]
[4 3]]
So, the 2d vector represents an x,y grid where (0,0) is the upper left corner. The keys for the map are [x y] and the values for the map are the 2d vector values.
I’ve been attempting a solution trying different mixtures of for, reduce, map, assoc-in, update-in, etc. It’s been several days and I am not making progress so I appreciate any assistance. Thanks.
Also notice that x and y are swapped in reducing function, I made it to match your expected output, although I have a feeling it can be wrong. [0 1] coordinate should be 4 according to our input map, but (get-in out [0 1]) returns 1 — looks like axises are wrong in out
reduce-kv is almost the same as reduce, just a bit more efficient on maps because it avoids constructing map entries by passing key and value as separate arguments to reducing function
bellow is my very boring answer to your question. The main idea is to build from the empty answer [[nil nil] [nil nil]] the solution. For that, I use map-indexed to fetch the proper items in the input.
I did not put my answer in a standalone function for readability.