def main(): for t in '120': i, o = get_testcase(t) clean_data = list(map(int, i)) n = clean_data[0] k = clean_data[1] arr = clean_data[2:] print(solution(n, k, arr) == int(o[0])) print(solution_two(k, arr) == int(o[0]))
def main(): for t in ['02', '00', '01']: i, o = get_testcase(t, read_as=read_raw, folder_name='testcases/matrix_layer_rotation') data = list(map(int, i[0].split())) l = i[1:] l = [list(map(int, e.split())) for e in l] print(matrix_layer_rotation(l, data[0], data[1], data[2]))
def main(): for t in ['00']: i, o = get_testcase( t, read_as=read_raw, folder_name='testcases/binary_search_ice_cream_parlor') trips = int(i[0]) data = i[1:] for i in range(trips): j = i * 3 m = int(data[j]) #c = int(data[j+1]) a = list(map(int, data[j + 2].split())) c1, c2 = solution(m, a) print(c1, c2)
tr.insert('sssss') print(tr.search('s')) print(tr.search('ss')) print(tr.search('sss')) print(tr.search('ssss')) print(tr.search('sssss')) print(tr.search('ssssss')) def solution(data): tr = Trie() #data = [l for l in fileinput.input()] n = int(data[0]) words = data[1:] for letters in words: stuff = [l for l in letters.split()] cmd, i = stuff[0], stuff[1] if cmd == 'add': tr.insert(i) elif cmd == 'find': yield tr.search(i) if __name__ == '__main__': for t in '01': i, o = get_testcase(t, read_as=read_raw) o = list(map(int, o)) for gen, out in zip(solution(i), o): print(gen == out)
def main(): for t in ['00', '01', '02']: i, o = get_testcase(t, read_as=read_raw, folder_name='testcases/hash_tables') print(solution(i) == o[0])
def main(): for t in range(0, 13): i, o = get_testcase(t) print(solution(i) == int(o[0]))
def main(): for t in '0123456789': i, o = get_testcase(t) print(solution(i) == int(o[0]))
def main(): for t in ['00']: i, o = get_testcase(t, folder_name='testcases/running_median') m = MediansCalculator() m.get_medians(list(map(int, i[1:])))
from fixture import get_testcase, read_raw def get_value(p, x, y): profit, loss = p * x, (1 - p) * y return profit - loss def solution(data): n, k = list(map(int, data[0].split())) to_number = lambda x: list(map(float, x.split())) p_arr, x_arr, y_arr = to_number(data[1]), to_number(data[2]), to_number(data[3]) values = [get_value(p,x,y) for p, (x, y) in zip(p_arr, zip(x_arr, y_arr))] sorted_values = sorted(filter(lambda x: x >= 0, values), reverse=True) acc = 0 for i, n in enumerate(sorted_values): acc += n if i + 1 == k: break return round(acc, 2) if __name__ == '__main__': for t in '01': i, o = get_testcase(t, read_as=read_raw, folder_name='testcases/01') print(format(solution(i), '.2f')) print(format(float(o[0]), '.2f')) print(format(solution(i), '.2f') == format(float(o[0]), '.2f'))