示例#1
0
def test_accumulate():
    assert list(accumulate(add, [1, 2, 3, 4, 5])) == [1, 3, 6, 10, 15]
    assert list(accumulate(mul, [1, 2, 3, 4, 5])) == [1, 2, 6, 24, 120]
    assert list(accumulate(add, [1, 2, 3, 4, 5], -1)) == [-1, 0, 2, 5, 9, 14]

    def binop(a, b):
        raise AssertionError('binop should not be called')

    start = object()
    assert list(accumulate(binop, [], start)) == [start]
示例#2
0
def test_accumulate():
    assert list(accumulate(add, [1, 2, 3, 4, 5])) == [1, 3, 6, 10, 15]
    assert list(accumulate(mul, [1, 2, 3, 4, 5])) == [1, 2, 6, 24, 120]
    assert list(accumulate(add, [1, 2, 3, 4, 5], -1)) == [-1, 0, 2, 5, 9, 14]

    def binop(a, b):
        raise AssertionError('binop should not be called')

    start = object()
    assert list(accumulate(binop, [], start)) == [start]
def explode_directories(child_directories, already_split=False):
    # get all directories including parents
    # use already_split=True for the result of get_all_directories()
    maybe_split = lambda x: x if already_split else x.split('/')
    return set(
        concat(
            accumulate(join, maybe_split(directory))
            for directory in child_directories))
示例#4
0
def main():
    input_ = load_from_file("day12_input.txt")

    init_ship_pos = ShipPosition(x=0, y=0, direction="E")
    instructions = [Instruction(line[:1], int(line[1:])) for line in input_]

    # PART 1
    moves = accumulate(move, instructions, initial=init_ship_pos)
    last_pos_pt1 = last(moves)
    sol_pt1 = abs(last_pos_pt1)
    print(sol_pt1)

    assert sol_pt1 == 441  # Solution for my input

    # PART 2
    init_with_waypoint = CompPosition(init_ship_pos, WaypointPosition(10, 1))
    moves_pt2 = accumulate(move_pt2, instructions, initial=init_with_waypoint)
    last_pos_pt2 = last(moves_pt2)
    sol_pt2 = abs(last_pos_pt2.ship)
    print(sol_pt2)

    assert sol_pt2 == 40014  # Solution for my input
示例#5
0
文件: path.py 项目: jhunkeler/conda
def explode_directories(child_directories, already_split=False):
    # get all directories including parents
    # use already_split=True for the result of get_all_directories()
    maybe_split = lambda x: x if already_split else x.split('/')
    return set(concat(accumulate(join, maybe_split(directory)) for directory in child_directories))
示例#6
0
文件: path.py 项目: wang1352083/conda
def explode_directories(child_directories):
    # get all directories including parents
    return set(
        concat(
            accumulate(join, directory.split('/'))
            for directory in child_directories))
示例#7
0
def test_accumulate_works_on_consumable_iterables():
    assert list(accumulate(add, iter((1, 2, 3)))) == [1, 3, 6]
示例#8
0
def test_accumulate():
    assert list(accumulate(add, [1, 2, 3, 4, 5])) == [1, 3, 6, 10, 15]
    assert list(accumulate(mul, [1, 2, 3, 4, 5])) == [1, 2, 6, 24, 120]
示例#9
0
def test_accumulate_works_on_consumable_iterables():
    assert list(accumulate(add, iter((1, 2, 3)))) == [1, 3, 6]
示例#10
0
def test_accumulate():
    assert list(accumulate(add, [1, 2, 3, 4, 5])) == [1, 3, 6, 10, 15]
    assert list(accumulate(mul, [1, 2, 3, 4, 5])) == [1, 2, 6, 24, 120]
示例#11
0
文件: path.py 项目: Korijn/conda
def explode_directories(child_directories):
    # get all directories including parents
    return set(concat(accumulate(join, directory.split('/')) for directory in child_directories))