def insert( arr, idx ):
	i = idx - 1
	val = arr[idx]
	while i >=0 and cmp( arr[i], val ) > 0 :
		arr[i+1] = arr[i]
		i -= 1	
	arr[i+1] = val
def insert(arr, idx):
    i = idx - 1
    val = arr[idx]
    while i >= 0 and cmp(arr[i], val) > 0:
        arr[i + 1] = arr[i]
        i -= 1
    arr[i + 1] = val
Exemple #3
0
    def compare(self):
        while True:
            while True:
                s1, s2 = sample(self._sounds, 2)
                if 0 < abs(s1.sid - s2.sid) <= 3:
                    break
            print("listening...")

            while True:
                s1.play()
                s2.play()

                while True:
                    v = input("input the maximum one: (1, 2): ").strip()
                    if v in ["1", "2"]:
                        break

                v = int(v)
                cmp_result = nlp.cmp(s1.sid, s2.sid)
                if (v == 1 and cmp_result == 1) or (v == 2
                                                    and cmp_result == -1):
                    self._right_sounds.play()
                    print(s1.name, s2.name)
                    break
                else:
                    self._wrong_sound_hint.play()
    def __cmp__(self, other):
        cn = cmp(self.n, other.n)
        cm = cmp_float(self.mean, other.mean, TOLERANCE['datum'])
        cs = cmp_float(self.stderr, other.stderr, TOLERANCE['datum'])

        if cn != 0: return cn
        if cm != 0: return cm
        return cs
def partition(A, l, r):
    p = selectPivotIndex(A, l, r)
    swap(A, p, r)
    store = l
    for i in range(l, r):
        if cmp(A[i], A[r]) <= 0:
            swap(A, i, store)
            store += 1
    swap(A, store, r)
    return store
def partition(A,l,r):
	p = selectPivotIndex(A,l,r)
	swap(A,p,r)
	store = l
	for i in range(l,r):
		if cmp(A[i], A[r]) <= 0:
			swap(A,i,store)
			store += 1
	swap(A,store,r)
	return store
Exemple #7
0
def exist_conflict_picks(picks):
    size = len(picks)
    if size < 2:
        return False
    for i in range(size - 1):
        for j in range(i + 1, size):
            if (isinstance(picks[i], PickWin)
                    and isinstance(picks[j], PickWin)
                    and picks[i].sider_id != picks[j].sider_id):
                return True
            if isinstance(picks[i], PickSetsScore) and isinstance(
                    picks[j], PickSetsScore):
                win_i, loss_i = picks[i].value
                win_j, loss_j = picks[j].value
                if (picks[i].sider_id == picks[j].sider_id and
                    (co.cmp(win_i, loss_i) * co.cmp(win_j, loss_j)) < 0):
                    return True
                if (picks[i].sider_id != picks[j].sider_id and
                    (co.cmp(win_i, loss_i) * co.cmp(win_j, loss_j)) > 0):
                    return True
    return False
def partition(A, l, r, pidx):

    idx, store, pivot = 0, l, A[pidx]

    # move pivot to end of the array
    swap(A, r, pidx)

    # all values <= pivot moved to front of array, and pivot inserted just after
    for i in range(l, r):
        if cmp(A[i], pivot) <= 0:
            swap(A, i, store)
            store += 1
    swap(A, r, store)
    return store
def partition( A, l, r, pidx):

	idx, store, pivot = 0, l, A[pidx]

	# move pivot to end of the array
	swap(A,r,pidx)

	# all values <= pivot moved to front of array, and pivot inserted just after
	for i in range(l,r):
		if cmp(A[i],pivot) <= 0:
			swap(A, i, store)
			store += 1
	swap(A,r,store)
	return store
Exemple #10
0
 def result(self, match):
     """return: True if win, False if loss, None if bet returned"""
     games_sum = match.score.games_count()
     if games_sum == 0:
         return None
     cmpr = co.cmp(games_sum, self.value)
     if not match.score.retired:
         if cmpr == 0:
             return None
         elif cmpr == -1:
             return self.is_less
         else:
             return not self.is_less
     if cmpr >= 0:  # games_sum >= value
         return not self.is_less
     full_score = sc.completed_score(match.score,
                                     best_of_five=self.value > 25.6)
     games_sum = full_score.games_count()
     cmpr = co.cmp(games_sum, self.value)
     if cmpr <= 0:  # games_sum <= value
         return None
     else:
         return not self.is_less
Exemple #11
0
    def favorite_firsted_offer(self):
        import ratings_std

        def is_flip_by_rating(first_player, second_player):
            cmp_val = ratings_std.compare_rank(
                first_player.rating.rank("std"),
                second_player.rating.rank("std"),
                min_diff=1,
            )
            if cmp_val == co.LT:
                result = False
            elif cmp_val == co.GT:
                result = True
            elif cmp_val == co.EQ:
                result = random.choice((True, False))
            else:
                result = None
            return result

        result_offer = copy.deepcopy(self.offer)
        if not result_offer.win_coefs:
            if not self.first_player or not self.second_player:
                return None, None
            is_flip = is_flip_by_rating(self.first_player, self.second_player)
            if is_flip:
                result_offer.flip()
            return result_offer, is_flip

        left_chance, right_chance = result_offer.win_coefs.chances()
        compare = co.cmp(left_chance, right_chance)
        is_flip = False
        if compare == -1:
            is_flip = True
        elif compare == 0 and self.first_player and self.second_player:
            is_flip = is_flip_by_rating(self.first_player, self.second_player)
        if is_flip:
            result_offer.flip()
        return result_offer, is_flip
Exemple #12
0
 def __cmp__(self, other):
   if not isinstance(other, HueApp):
     raise TypeError
   return cmp((self.name, self.version), (other.name, other.version))
 def compare(mr1, mr2):
     """compare (match1, round1) vs (match2, round2)"""
     if mr1[0].date is not None and mr2[0].date is not None:
         return co.cmp((mr1[0].date, mr1[1]), (mr2[0].date, mr2[1]))
     return co.cmp(mr1[1], mr2[1])