def _find_smart_path(challbs, preferences, combinations):
 chall_cost = {}
 max_cost = 1
 for (i, chall_cls) in enumerate(preferences):
  chall_cost[chall_cls] = i
  max_cost += i
 best_combo = []
 best_combo_cost = max_cost
 combo_total = 0
 for combo in combinations:
  for challenge_index in combo:
   combo_total += chall_cost.get(challbs[challenge_index].chall.__class__, max_cost)
  if (combo_total < best_combo_cost):
   best_combo = combo
   best_combo_cost = combo_total
  combo_total = 0
 if (not best_combo):
  _report_no_chall_path()
 return best_combo

def _find_smart_path ( challbs , preferences , combinations ) : chall_cost = { } max_cost = 1 for ( i , chall_cls ) in enumerate ( preferences ) : chall_cost [ chall_cls ] = i max_cost += i best_combo = [ ] best_combo_cost = max_cost combo_total = 0 for combo in combinations : for challenge_index in combo : combo_total += chall_cost . get ( challbs [ challenge_index ] . chall . __class__ , max_cost ) if ( combo_total < best_combo_cost ) : best_combo = combo best_combo_cost = combo_total combo_total = 0 if ( not best_combo ) : _report_no_chall_path ( ) return best_combo
find challenge path with server hints .