Guest User

Untitled

a guest
Apr 16th, 2020
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. from typing import List, Set
  2.  
  3. def find_min_table(table: List[str], chars: Set[str]) -> int:
  4.     for idx in range(len(table) - 1):
  5.         if table[idx] != table[idx + 1]:
  6.             return min([len(table)] + [find_min_table(table[: idx] + [k] + table[idx + 2:], chars) for k in chars if k != table[idx] and k != table[idx + 1]])
  7.    
  8.     return len(table)
  9.  
  10. if __name__ == '__main__':
  11.     initial_array = ['b', 'c', 'd', 'd', 'd', 'c', 'c', 'a']
  12.     chars = set(initial_array)
  13.     print(find_min_table(initial_array, chars))
Advertisement
Add Comment
Please, Sign In to add comment