The following code does the backtracking part of your example.
aa.txt
can you send a pull request to him? This way of code sharing is not recommended.