Make a list of every data-point's coords and size [((x,y), (w,h)), ...]
Transform each entry to a list of coords (all coords of this rect) [(x,y), ...], so now I have a list of lists with w * h coordinate-pairs
Concatenate all lists into one, so now I have a huge list of every occupied field.
Count every coordinate in a map, %{(x,y) => count, (x,y) => count, ...}
Throw out every entry where count < 2
Count entries in resulting list
Takes about a second. The first version used lists and list-diffing to find duplicates, but this took minutes to compute. Maps were much faster at this size (hundeds of thousands of entries).
I should mention I'm just learning Elixir, so this is not to be understood as "good code" or "knows what he's doing".
Ryan is an engineer in the Sacramento Area with a focus in Python, Ruby, and Rust. Bash/Python Exercism mentor. Coding, physics, calculus, music, woodworking. Looking for work!
Just a heads up, you can put the word βelixirβ immediately after the opening triple backtick, and your code will show up with syntax highlighting. π
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
My solution (Elixir) for the first part was:
Takes about a second. The first version used lists and list-diffing to find duplicates, but this took minutes to compute. Maps were much faster at this size (hundeds of thousands of entries).
I should mention I'm just learning Elixir, so this is not to be understood as "good code" or "knows what he's doing".
Here's the code:
Cool! Thanks for sharing!
Just a heads up, you can put the word βelixirβ immediately after the opening triple backtick, and your code will show up with syntax highlighting. π