fork(1) download
  1. # your code goes here
  2. def recursion_zenik(n,k,path=[]):
  3. if path and max(path)-min(path)>k:
  4. print('Zenik rule fail:',path)
  5. return 0
  6. if n==0:
  7. print('Success:',path)
  8. return 1
  9. return sum(recursion_zenik(n-i,k,path+[i]) for i in range(1,n+1))
  10.  
  11. print('Result =',recursion_zenik(5,2))
Success #stdin #stdout 0.04s 9384KB
stdin
Standard input is empty
stdout
Success: [1, 1, 1, 1, 1]
Success: [1, 1, 1, 2]
Success: [1, 1, 2, 1]
Success: [1, 1, 3]
Success: [1, 2, 1, 1]
Success: [1, 2, 2]
Success: [1, 3, 1]
Zenik rule fail: [1, 4]
Success: [2, 1, 1, 1]
Success: [2, 1, 2]
Success: [2, 2, 1]
Success: [2, 3]
Success: [3, 1, 1]
Success: [3, 2]
Zenik rule fail: [4, 1]
Success: [5]
Result = 14