Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Sat Feb 25 15:35:49 2017
  4.  
  5. @author: hanbyulkim
  6. """
  7. cache = dict()
  8. min_good_seq = []
  9.  
  10. def is_good(seq, begin_index):
  11. #print(seq)
  12. if len(seq) == 2:
  13. # if seq[0] == seq[1]: # if bad
  14. return seq[0] != seq[1]
  15.  
  16. for end_index in range(1, int(len(seq))+1):
  17. return is_good(seq[1:], begin_index + 1) and seq[:end_index] != seq[end_index:2*end_index]
  18.  
  19. def all_123_seq(picked, N):
  20. global min_good_seq
  21. if N == 0:
  22. good = is_good(picked, 0)
  23. if good:
  24. print("%s => %r" % (picked, is_good(picked, 0)))
  25. for pick in picked:
  26. min_good_seq.append(pick)
  27. return True
  28.  
  29. return False
  30.  
  31. for i in range(1, 3+1):
  32. picked.append(i)
  33. good = all_123_seq(picked, N-1)
  34. if good:
  35. return True
  36. picked.pop()
  37.  
  38. def main():
  39. N = 4
  40. good = all_123_seq([], N)
  41. print(min_good_seq)
  42. #is_good("111111", 0)
  43. #print(min_good_seq(N))
  44.  
  45.  
  46. if __name__ == '__main__':
  47. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement