from typing import Sequence
from typing import List


def get_evenly_spaced_elements(nr_elements: int, input_sequence: Sequence) -> List:
    """
    Use Bresenham's line algorithm to select `nr_elements` spaced evenly from the `input_sequence`

    Sequences are the general term for ordered sets. Among others, these are lists or Django's QuerySets.

    Definition: https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
    Implementation: https://stackoverflow.com/a/9873804
    """

    len_sequence = len(input_sequence)
    if nr_elements > len_sequence:
        nr_elements = len_sequence

    indices = [i * len_sequence // nr_elements + len_sequence // (2 * nr_elements) for i in range(nr_elements)]
    return [input_sequence[index] for index in indices]