


from random import randint, random





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase      ,	_lowerCAmelCase      ,	_lowerCAmelCase = False      ,	_lowerCAmelCase = False      ,	_lowerCAmelCase = 5      ,	)						->	str:


						'''simple docstring'''






						__snake_case				=		[[-1] * number_of_cells]  # Create a highway without any car
						__snake_case				=		0
						__snake_case				=		max(_lowerCAmelCase      ,	0 )
						while i < number_of_cells:
												__snake_case				=		(
												    randint(0      ,	_lowerCAmelCase ) if random_speed else initial_speed
												)  # Place the cars
												i += (
												    randint(1      ,	max_speed * 2 ) if random_frequency else frequency
												)  # Arbitrary number, may need tuning
						return highway





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase )						->	List[str]:


						'''simple docstring'''






						__snake_case				=		0
						__snake_case				=		highway_now[car_index + 1 :]
						for cell in range(len(_lowerCAmelCase ) ):  # May need a better name for this
												if cells[cell] != -1:  # If the cell is not empty then
																		return distance  # we have the distance we wanted
												distance += 1
						# Here if the car is near the end of the highway
						return distance + get_distance(_lowerCAmelCase      ,	-1 )





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase      ,	_lowerCAmelCase )						->	Tuple:


						'''simple docstring'''






						__snake_case				=		len(_lowerCAmelCase )
						# Beforce calculations, the highway is empty
						__snake_case				=		[-1] * number_of_cells

						for car_index in range(_lowerCAmelCase ):
												if highway_now[car_index] != -1:
																		# Add 1 to the current speed of the car and cap the speed
																		__snake_case				=		min(highway_now[car_index] + 1      ,	_lowerCAmelCase )
																		# Number of empty cell before the next car
																		__snake_case				=		get_distance(_lowerCAmelCase      ,	_lowerCAmelCase ) - 1
																		# We can't have the car causing an accident
																		__snake_case				=		min(next_highway[car_index]      ,	_lowerCAmelCase )
																		if random() < probability:
																								# Randomly, a driver will slow down
																								__snake_case				=		max(next_highway[car_index] - 1      ,	0 )
						return next_highway





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase      ,	_lowerCAmelCase      ,	_lowerCAmelCase )						->	Any:


						'''simple docstring'''






						__snake_case				=		len(highway[0] )

						for i in range(_lowerCAmelCase ):
												__snake_case				=		update(highway[i]      ,	_lowerCAmelCase      ,	_lowerCAmelCase )
												__snake_case				=		[-1] * number_of_cells

												for car_index in range(_lowerCAmelCase ):
																		__snake_case				=		next_speeds_calculated[car_index]
																		if speed != -1:
																								# Change the position based on the speed (with % to create the loop)
																								__snake_case				=		(car_index + speed) % number_of_cells
																								# Commit the change of position
																								__snake_case				=		speed
												highway.append(_lowerCAmelCase )

						return highway


if __name__ == "__main__":
		import doctest

		doctest.testmod()









from __future__ import annotations





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	list:


						'''simple docstring'''






						if len(_lowerCAmelCase ) == 0:
												return []
						__snake_case		,					__snake_case				=		min(_lowerCAmelCase ), max(_lowerCAmelCase )
						__snake_case				=		int(max_value - min_value ) + 1
						__snake_case				=		[[] for _ in range(_lowerCAmelCase )]

						for i in my_list:
												buckets[int(i - min_value )].append(_lowerCAmelCase )

						return [v for bucket in buckets for v in sorted(_lowerCAmelCase )]


if __name__ == "__main__":
	from doctest import testmod

	testmod()
	assert bucket_sort([4, 5, 3, 2, 1]) == [1, 2, 3, 4, 5]
	assert bucket_sort([0, 1, -10, 15, 2, -2]) == [-10, -2, 0, 1, 2, 15]





