This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SCORES = {'win': 1, 'lose': 0, 'tie': 0.5} | |
class Player: | |
INITIAL_RATING = 1000 | |
def __init__(self, name, rating=INITIAL_RATING, total_matches=0): | |
self.name = name | |
self.rating = rating |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def adjacency_matrix_to_adjacency_list(adjacency_matrix): | |
adjacency_list = [] | |
indices = np.argwhere(adjacency_matrix==1) | |
for node in range(len(adjacency_matrix)): | |
adjacency_list.append([]) | |
for index in indices: | |
if index[0] == node: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
def set_cover_recursive(sets, result, element_index=0, prefix=[]): | |
if len(prefix)==len(sets[0]): | |
result.append(prefix) | |
return True | |
# Check validity of allocation | |
for i in range(len(sets)): | |
if sets[i][element_index] == 1: | |
set_cover_recursive(sets, result, element_index+1, prefix+[i]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#groups is list of integers in ascending order without gaps | |
def getRow(lists, row): | |
res = [] | |
for l in lists: | |
for i in range(len(l)): | |
if i==row: | |
res.append(l[i]) | |
return res |