def get_scanner_pos(counter, depth):
    """Get the index of scanner, given the counter time and layer depth."""
    remainder = counter / 2 * (depth - 1)
    if remainder > depth:
        return 2 * depth - remainder
    return remainder