Remove premature optimizations and useless indexes
Add a useful return value to solve.

- Make solution slightly more concise.
Add tests for the new return value.
Remove some useless constants.