


from random import randint, random
def      _a					( SCREAMING_SNAKE_CASE		,							SCREAMING_SNAKE_CASE		,							SCREAMING_SNAKE_CASE		,							SCREAMING_SNAKE_CASE = False		,							SCREAMING_SNAKE_CASE = False		,							SCREAMING_SNAKE_CASE = 5		,							):


		"""simple docstring"""




		lowercase__				= [[-1] * number_of_cells]  # Create a highway without any car
		lowercase__				= 0
		lowercase__				= max(SCREAMING_SNAKE_CASE		,							0	)
		while i < number_of_cells:
				lowercase__				= (
				    randint(0		,							SCREAMING_SNAKE_CASE	) 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      _a					( SCREAMING_SNAKE_CASE		,							SCREAMING_SNAKE_CASE	):


		"""simple docstring"""




		lowercase__				= 0
		lowercase__				= highway_now[car_index + 1 :]
		for cell in range(len(SCREAMING_SNAKE_CASE	)	):  # 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(SCREAMING_SNAKE_CASE		,							-1	)
def      _a					( SCREAMING_SNAKE_CASE		,							SCREAMING_SNAKE_CASE		,							SCREAMING_SNAKE_CASE	):


		"""simple docstring"""




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

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


		"""simple docstring"""




		lowercase__				= len(highway[0]	)

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

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

		return highway


if __name__ == "__main__":
			import doctest

			doctest.testmod()






from .imports import is_rich_available


if is_rich_available():
		from rich.traceback import install

		install(show_locals=False)

else:
		raise ModuleNotFoundError('''To use the rich extension, install rich with `pip install rich`''')
