fork(1) download
  1. # your code goes here
  2.  
  3. def binary(path):
  4. return ''.join('1'+'0'*(step-1) for step in path)
  5.  
  6.  
  7. def recursion_zenik(n,k,path=[]):
  8. if n==0:
  9. if path and max(path)-min(path)>k:
  10. print(binary(path),'fail')
  11. return 0
  12. print(binary(path),'ok')
  13. return 1
  14. return sum(recursion_zenik(n-i,k,path+[i]) for i in range(1,n+1))
  15.  
  16. print('Result =',recursion_zenik(6,2))
Success #stdin #stdout 0.04s 9380KB
stdin
Standard input is empty
stdout
111111 ok
111110 ok
111101 ok
111100 ok
111011 ok
111010 ok
111001 ok
111000 fail
110111 ok
110110 ok
110101 ok
110100 ok
110011 ok
110010 ok
110001 fail
110000 fail
101111 ok
101110 ok
101101 ok
101100 ok
101011 ok
101010 ok
101001 ok
101000 ok
100111 ok
100110 ok
100101 ok
100100 ok
100011 fail
100010 ok
100001 fail
100000 ok
Result = 27