As was mentioned above, try using some datastructure that has something like a hash table for lookups of possible solutions. Something like a dictionary in Python, an associative array in PHP, a map in Elixir, etc.
I think it really depends on your philosophy. Elixir doesn't have many idioms or strong suggestions as to how to go about a problem, so you see different approaches. For some, code being easy to reason about is more important than efficiency. I personally adhere to two things above efficiency:
datastructures should carry the majority of the complexity; algorithms should be clean.
No optimization before practical bottlenecks are identified at the expense of clarity.
Other than that, I really appreciate this different take on the solution!
Edit: I also like that this solution directly solves the problem and only the problem. Very nice.
Other solutions don't have to have separate cases for even and odd by basing the middle off of the division. That's smart and something I've learned now!
noice
dang jeff
As was mentioned above, try using some datastructure that has something like a hash table for lookups of possible solutions. Something like a dictionary in Python, an associative array in PHP, a map in Elixir, etc.
I think it really depends on your philosophy. Elixir doesn't have many idioms or strong suggestions as to how to go about a problem, so you see different approaches. For some, code being easy to reason about is more important than efficiency. I personally adhere to two things above efficiency:
Other than that, I really appreciate this different take on the solution!
Edit: I also like that this solution directly solves the problem and only the problem. Very nice.
Very clean! You could also just use Stream.dedup here instead of uniq for slightly less overhead since the ones will be next to each other.
Wow. I've got a lot to learn.
I knew something like this was possible and just couldn't sort it out. Thank you!
Other solutions don't have to have separate cases for even and odd by basing the middle off of the division. That's smart and something I've learned now!
This comment is hidden because it contains spoiler information about the solution
noice, much better than my ham-fisted attempt!