def archive_filler(month: int, year: int) -> Post:
by math_explorer, Jul 30, 2016, 8:44 AM
Arbitrary throwback to August 2012, plus optional static typing is the future, plus I somehow just cannot find interesting Python snippets lying around. Or good post ideas, for that matter.
the more things seem to change, the more they stay the same
import itertools from typing import Iterable def count_lifts(seq: Iterable[int], strength: int) -> int: liftn = 1 subtotal = 0 for candy in seq: if candy + subtotal > strength: liftn += 1 subtotal = 0 subtotal += candy return liftn def minimal_lifts(candies: Iterable[int], strength: int) -> int: return (-1 if max(candies) > strength else min(count_lifts(s, strength) for s in itertools.permutations(candies))) if __name__ == "__main__": # input format: # <candy 1> <candy 2> ... <candy n> # <strength> cs = [int(t) for t in input().split()] x = int(input()) print(minimal_lifts(cs, x))
the more things seem to change, the more they stay the same