import itertools as it from math import ceil, hypot def checkio(radius): “””count tiles””” crds = [ ((x1, y1), (x2, y2)) for x1, y1, x2, y2 in it.product(range(ceil(radius + 1)), repeat=4) if x2 == x1 + 1 and y2 == y1…
CheckIO: CheckSum
import functools def map_point(val): double = val * 2 if double < 10: return double else: return functools.reduce(lambda x, y: x + y, map(int, str(double))) def checkio(data): charseq = lambda x: ord(x) – 48 clean = lambda L: [x for…
CheckIO: Vigenere Cipher
from string import ascii_uppercase as alpha import itertools as it def decrypt(enc_alpha, key_alpha): if alpha.index(enc_alpha) >= alpha.index(key_alpha): return alpha[alpha.index(enc_alpha) – alpha.index(key_alpha)] else: return alpha[len(alpha) + alpha.index(enc_alpha) – alpha.index(key_alpha)] def find_key(repeated): length = 1 while length <= len(repeated): check, iter_key =…
CheckIO: What does the cow say?
COW = r”’ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||—-w | || || ”’ TOP = ‘_’ BOTTOM = ‘-‘ BORDERS = ‘/\\|’ MAX_ROW = 39 def make_rows(text): rows, num = [”], 0 words = text.split(‘ ‘) for i, w…
CheckIO: Numbers Factory
def checkio(number): ret = [] for i in range(9, 1, -1): while not number % i: number /= i ret.append(i) if number == 1: return int(”.join(map(str, sorted(ret)))) return 0 if __name__ == ‘__main__’: #These “asserts” using only for self-checking and…
CheckIO: Moria doors
import itertools def calc_coefficient(x, y): score = 0 if x[0] == y[0]: score += 10 if x[-1] == y[-1]: score += 10 score += (len(x) / len(y)) * 30 if len(x) <= len(y) else (len(y) / len(x)) * 30 score…
CheckIO: Open Labyrinth
class Node(object): def __init__(self, index, crd): self.index = index self.crd = crd self.links = None def __sub__(self, other): return ( self.crd[0] – other.crd[0], self.crd[1] – other.crd[1] ) def map_to_graph(maze_map): graph = [] def get_index(crd): for n in graph: if n.crd…
CheckIO: Weak Point
def weak_point(matrix): check = lambda x: [sum(y) for y in x] rows, cols = check(matrix), check(zip(*matrix)) return [rows.index(min(rows)), cols.index(min(cols))] if __name__ == ‘__main__’: #These “asserts” using only for self-checking and not necessary for auto-testing assert isinstance(weak_point([[1]]), (list, tuple)), “The result…