Python recursive algorithm

welcome to shbcf.ru