Refactor TRANSITION-POSITION to use iteration

Using iterative function makes the tests run in 83% of the time of the
old recursive function.