from string import ascii_uppercase as alpha import itertools MAX_K = 37 def checkio(number): to_int = lambda x: int(x) if x.isdigit() else alpha.index(x) + 10 digits = list(map(to_int, number)) k = max(digits) + 1 for k in itertools.count(k): if k >…

## CheckIO: Broken Clock

from datetime import datetime, timedelta import re def to_sec(unit): dct = {‘second’: 1, ‘minute’: 60, ‘hour’: 3600} m = re.compile(‘^(second|minute|hour)’) return dct[m.match(unit).group()] def broken_clock(starting_time, wrong_time, error_description): a, b, c, d = error_description.replace(‘at ‘, ”).split() err_per_sec = (int(a) * to_sec(b)) /…

## CheckIO: Pattern Recognition

import itertools as it def checkio(pattern, image): pattern_height, pattern_width = len(pattern), len(list(zip(*pattern))) image_height, image_width = len(image), len(list(zip(*image))) scan = lambda: it.product(range(pattern_height), range(pattern_width)) for i, j in it.product(range(image_height), range(image_width)): try: if all(image[i + x][j + y] == pattern[x][y] for (x, y)…

## CheckIO: Determinant

def cofactor(matrix, row_num, col_num): cols = [col for i, col in enumerate(matrix) if i != col_num] rows = [row for i, row in enumerate(zip(*cols)) if i != row_num] return list(zip(*rows)) def checkio(matrix): if len(matrix) == 1: return matrix[0][0] else: sign…

## CheckIO: Shooting range

import math def calc_hitpoint(crd1, direction1, crd2, direction2): (a, b), (c, d) = crd1, crd2 (d1, d2), (d3, d4) = direction1, direction2 if d1 * d4 == d2 * d3: return None, None # parralel lines k = ((b – d)…