I have tweaked and tested and tweaked. As far as I can see this gives the correct result every time for everything I could think of to test. Yet for some reason it doesn't validate. Does anybody know what else I can do? This is no longer a programming problem imo but a validator problem. Every testcase has at least 1 recursion call, every test case gives the correct number of actions and the correct output. What more do they want?