fork(2) download
  1. '''
  2. Verifier for answers for the PPCG question Finding Collatz-like rules with many loops
  3.  
  4. Input is expected from standard input as space-separated integers `d m i min_value_1 min_value_2 ...`.
  5. E.g. for d=3 m=7 i=8 min_values=[1 2 4] the input should be "3 7 8 1 4 2"
  6. '''
  7.  
  8. def itOne(n,d,m,i):
  9. return (n*m+i) if n%d else n//d
  10.  
  11. def checkMin(n,d,m,i):
  12. ni=n
  13. while True:
  14. ni=itOne(ni,d,m,i)
  15. if ni<n:
  16. return False
  17. if ni==n:
  18. return True
  19.  
  20. strin=input()
  21. d,m,i,*mins=map(int,strin.split())
  22.  
  23. ok=True
  24. minset=set()
  25.  
  26. for mine in mins:
  27. if mine in minset or not checkMin(mine,d,m,i):
  28. ok=False
  29. break
  30. minset.add(mine)
  31.  
  32. if ok:
  33. print('d=',d,' m=',m,' i=',i,' is VERIFIED for a score of ',len(minset),'.',sep='')
  34. else:
  35. print('The given input FAILED the test.')
  36.  
Success #stdin #stdout 0.02s 8736KB
stdin
3 7 8 1 4 2
stdout
d=3 m=7 i=8 is VERIFIED for a score of 3.