graphs.minimum_path_sum

Functions

fill_row(→ list)

min_path_sum(→ int)

Find the path from top left to bottom right of array of numbers

Module Contents

graphs.minimum_path_sum.fill_row(current_row: list, row_above: list) list
>>> fill_row([2, 2, 2], [1, 2, 3])
[3, 4, 5]
graphs.minimum_path_sum.min_path_sum(grid: list) int

Find the path from top left to bottom right of array of numbers with the lowest possible sum and return the sum along this path. >>> min_path_sum([ … [1, 3, 1], … [1, 5, 1], … [4, 2, 1], … ]) 7

>>> min_path_sum([
...     [1, 0, 5, 6, 7],
...     [8, 9, 0, 4, 2],
...     [4, 4, 4, 5, 1],
...     [9, 6, 3, 1, 0],
...     [8, 4, 3, 2, 7],
... ])
20
>>> min_path_sum(None)
Traceback (most recent call last):
    ...
TypeError: The grid does not contain the appropriate information
>>> min_path_sum([[]])
Traceback (most recent call last):
    ...
TypeError: The grid does not contain the appropriate information