Solved problem 2, cleaned up problem 1.
Solution to problem 3, takes wayyyy to long to run though.
Much faster (and actually correct) solution.