|
PROG
|
(Python)
def f(p, s, x={1:{3:2, 7:4, 9:5}, 2:{8:5}, 3:{1:2, 7:5, 9:6}, 4:{6:5}, 5:{}, 6:{4:5}, 7:{1:4, 3:5, 9:8}, 8:{2:5}, 9:{1:5, 3:6, 7:8}}):
return int(s==0) or sum(f(p+[n], s-1) for n in (n for n in range(1, 10) if (not p or n not in p and (n not in x[p[-1]] or x[p[-1]][n] in p))))
print([f([], s) for s in range(10)]) # Matej Veselovac, Mar 16 2021, based on StackOverflow entry for Jan 5, 2016
|