Python (under progress) def f(x): if x:a=f(x-1);return(a+x,a-x)[a-x not in map(f,range(x)) and a>x] return 0