Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. ## This is my procedural way. For some reason this results in kernel death. Why?
  2. def merge_lists(list_of_lists):
  3.     single_list = []
  4.     for individual_list in list_of_lists:
  5.         for entry in individual_list:
  6.             single_list.append(entry)
  7.     return single_list        
  8.  
  9. def planner(k):
  10.     plan = [[1]]
  11.     if k > 1:
  12.         while k not in merge_lists(plan):
  13.             for individual_list in plan:
  14.                 temp = list(individual_list)
  15.                 for entry in individual_list:
  16.                     temp2 = list(temp)
  17.                     temp2.append(temp[-1] + entry)
  18.                     plan.append(temp2)          
  19.         plan_optimal = []
  20.         for individal_list in plan:
  21.             if k in individual_list:
  22.                 plan_optimal.append(individual_list)
  23.         return plan_optimal    
  24.     if k == 1:
  25.         return plan
  26. print(planner(2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement