completed!

finally managed to do it right! all tests have been successful. had a
lot of fun when trying to find the solution but then it got really dirty
during implementation. code could still be cleaned up but it works
perfectly fine.