def entering_basement(ops): """ >>> entering_basement('()())') 5 """ levels = p.scan(consume, ops, 0) return p.iindex(levels, -1)
def move_santa(directions): """ >>> move_santa('>') {(1, 0), (0, 0)} >>> move_santa('^v^v^v^v^v') {(0, -1), (0, 0)} """ return set(p.scan(single_move, directions, (0, 0)))
def enqueue(reindeer): """ >>> list(p.take(6, enqueue(('Vixen', 8, 2, 2)))) [8, 16, 16, 16, 24, 32] """ _, speed, running, resting = reindeer one_cycle = it.chain(it.repeat(speed, running), it.repeat(0, resting)) return p.drop(1, p.scan(operator.add, it.cycle(one_cycle), 0))
def accum(reindeers, num): """ >>> rds = [('Comet', 14, 10, 127), ('Dancer', 16, 11, 162)] >>> list(accum(rds, 1000)) [312, 689] """ queues = [enqueue(r) for r in reindeers] winners = (is_max(x) for x in zip(*queues)) scores = p.scan(lambda s, x: map(sum, zip(s, x)), winners, it.repeat(0)) return p.nth(num+1, scores)