Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Balanced Interleaving Algorithm
import random
def a_start_check():
if random.random() > 0.5:
print "A first"
return True
else:
print "B first"
return False
def combine(r_a, r_b):
k_a = 0
k_b = 0
combined_ranking = []
a_starts = a_start_check()
while (k_a <= len(r_a) - 1) and (k_b <= len(r_b) - 1):
if (k_a < k_b) or (k_a == k_b and a_starts):
if r_a[k_a] not in combined_ranking:
combined_ranking += [r_a[k_a]]
k_a += 1
else:
if r_b[k_b] not in combined_ranking:
combined_ranking += [r_b[k_b]]
k_b += 1
print k_a, k_b
return combined_ranking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.