fork download
  1. def f(s):
  2. q,S=[''],[];T=s.startswith
  3. for c in q:
  4. for I in range(60):
  5. for C in[c[:~I|-2]+(i:='antapeaspassbatbeeboacatcodcowdabdogeelelkemuflyfoxgnuhogidejaykeakobkoiolmowlpigratrayyak'[I//2*3:][:3])]+[c+i[I%2+1:]]*(c>''):
  6. if C==s:return 1
  7. if T(C[:-1])+T(C[:-2])and~-(C in S):q+=C,;S+=C,
  8.  
  9. s = """
  10. ant
  11. owl
  12. bass
  13. pride
  14. bobcat
  15. peafowl
  16. elephant
  17. hedgehogs
  18. crocodile
  19. antidemocrat
  20. aspidoganoidei
  21. biodegradability
  22. angioelephantiasis
  23. propreantepenultimate
  24. """
  25. s1 = """
  26. a
  27. ox
  28. ram
  29. bear
  30. koala
  31. antelope
  32. albatross
  33. zookeeper
  34. salamander
  35. caterpillar
  36. hippopotamus
  37. """
  38. for i in filter(None,s.split('\n')):
  39. assert f(i) is not None
  40.  
  41. for i in filter(None,s1.split('\n')):
  42. assert f(i) is None
  43.  
  44. print('tests passed')
Success #stdin #stdout 0.1s 14168KB
stdin
Standard input is empty
stdout
tests passed