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