def checkio(time_string): ON, OFF = ‘.’, ‘-‘ hour, minitue, second = [‘{:0>2}’.format(x) for x in time_string.split(‘:’)] convert = lambda x: x.replace(‘0’, ON).replace(‘1’, OFF) to_bin = lambda x: bin(int(x))[2:] binary = [to_bin(x) for x in hour + minitue + second] morse…
CheckIO: Min and Max
import functools def abstract(*args, **kwargs): compare = kwargs.get(‘compare’, lambda x,y: x > y) key = kwargs.get(‘key’, lambda x: x) values = iter(args[0]) if len(args) == 1 else iter(args) result = next(values) for i in values: if compare(key(i), key(result)): result =…
CheckIO: Roman numerals
import collections import functools Symbols = collections.namedtuple( ‘Symbols’, [‘unus’, ‘quinque’, ‘decem’, ‘quinquaginta’, ‘centum’, ‘quingenti’, ‘mille’] ) symbol = Symbols(‘I’, ‘V’, ‘X’, ‘L’, ‘C’, ‘D’, ‘M’) def to_roman(digit, one, five, ten): if 0 < digit < 4: return ”.join([one for _…
CheckIO: Feed Pigeons
def iter_pigeons(): i = 1 while True: yield sum(range(1, i + 1)) i += 1 def checkio(portions): pigeons = iter_pigeons() feeded = 0 while True: hungry = next(pigeons) if portions <= hungry: return portions if portions > feeded else feeded…
CheckIO: Pawn Brotherhood
import itertools def safe_pawns(pawns): safe_squares = itertools.chain(*[calc_safe_squares(p) for p in pawns]) return len(pawns & set(safe_squares)) def calc_safe_squares(pos): return (chr(ord(pos[0]) – 1) + str(int(pos[1]) + 1), chr(ord(pos[0]) + 1) + str(int(pos[1]) + 1)) if __name__ == ‘__main__’: #These “asserts” using only…
CheckIO: Speech Module
FIRST_TEN = [“one”, “two”, “three”, “four”, “five”, “six”, “seven”, “eight”, “nine”] SECOND_TEN = [“ten”, “eleven”, “twelve”, “thirteen”, “fourteen”, “fifteen”, “sixteen”, “seventeen”, “eighteen”, “nineteen”] OTHER_TENS = [“twenty”, “thirty”, “forty”, “fifty”, “sixty”, “seventy”, “eighty”, “ninety”] HUNDRED = “hundred” def checkio(number): second_tens =…
CheckIO: Xs and Os Referee
def checkio(rows): cols = [”.join([rows[y][x] for y in range(3)]) for x in range(3)] digs = [”.join([rows[x][x] for x in range(3)]), ”.join([rows[x][2 – x] for x in range(3)])] triples = rows + cols + digs for check in triples: winner =…
CheckIO: The Most Wanted Letter
from string import ascii_lowercase def checkio(text): letters = [x for x in text.lower() if x in ascii_lowercase] counts = sorted({x : letters.count(x) for x in letters}.items(), key=lambda x:x[1], reverse=True) wanted_count = counts[0][1] wanted = sorted([x[0] for x in counts if…
CheckIO: Count “Striped words”
I learned re.split(pattern, text) in CheckIO Count Striped words question. *Striped word is a word its alphabets sequenced vowels or consonants alternately. import string import re VOWELS = “AEIOUY” CONSONANTS = “BCDFGHJKLMNPQRSTVWXZ” DELIMITER = string.punctuation + string.whitespace def split_text(text, delimiters):…