You are an employee at the hip new grocery store Half Foods, and it's the day before Thanksgiving Christmas Easter. Since the store will be packed with customers rushing to get their foodstuffs, the store needs a traffic manager to send everyone to the appropriate lines. Being lazy, you'd like to automate this so that you can go hit the deli before everyone takes all the turkey ham whatever. However, all you have with you is your phone, and coding long programs on it is a real pain -- so you need to bust out your ninja code-golf skills.
Challenge
Let's visualize the grocery store on a two-dimensional grid. Here's a sample grid to dissect:
e
s
s
s
Y
# # #s #
#s # #s #
#s # #s #
#s #s #s #
#3 #1 #4 #
x x x x
The grid starts out with an e
, which represents an "outlet" to the rest of the store. Every generation, all of the outlets in the grid spawn a shopper (s
) directly below. The shoppers move downward each generation until they reach you (Y
). When a shopper reaches the same row as you, you must teleport the shopper to the beginning of the line with the least amount of shoppers in it. A shopper immediately moves to the line when they would move into the row with the Y
, there is no generation in between. The lines are represented by the #
s -- the column after the #
s is a line. The shoppers go down to the end of the line (represented by an exit x
), and then turn into a random number between 1
and 5
. Each generation, you must decrement numbered shoppers by 1
-- when a shopper would reach 0
, they're done checking out and they leave the store.
Given an input of a grid like this, output the next generation of the grocery store (move all the shoppers down simultaneously, redirect shoppers, and have them leave if they are done).
Samples
Input:
e
Y
# # # #
# # # #
# # # #
# # # #
# # # #
x x x x
Output:
e
s
Y
# # # #
# # # #
# # # #
# # # #
# # # #
x x x x
Input:
e
s
Y
# # # #
# # # #
# # # #
# # # #
# # # #
x x x x
Output
e
s
Y
#s # # #
# # # #
# # # #
# # # #
# # # #
x x x x
Input:
e
Y
# # # #
# # # #
# # # #
#s # # #
# # # #
x x x x
(Possible) Output:
e
s
Y
# # # #
# # # #
# # # #
# # # #
#3 # # #
x x x x
Input:
e
s
Y
# # # #
# # # #
# # # #
# # # #
#3 # # #
x x x x
Output:
e
s
Y
# #s # #
# # # #
# # # #
# # # #
#2 # # #
x x x x
Input:
e
Y
# # # #
# # # #
# # # #
# # # #
#1 # # #
x x x x
Output:
e
s
Y
# # # #
# # # #
# # # #
# # # #
# # # #
x x x x
This is code-golf, so shortest code wins.