Stones Settle
grid is a list of strings of equal length, one per row, top row first. o is a loose stone, # is a fixed block and . is empty space. Gravity pulls every loose stone straight down its column until it rests on the bottom row, on a fixed block, or on another stone that has already come to rest. Fixed blocks never move, and stones never move sideways. Return the grid after every stone has settled, in the same format, without changing grid.
Example 1
In column 0 both stones fall to the bottom. In column 1 the stone already rests on the block below it, and in column 2 the stone rests on the block in row 2.
Example 2
The bottom stone stays put and the stone above it falls onto it. The top stone falls only as far as the block.
Constraints
1 <= rows, cols <= 10- every row has the same length
- every character is
o,#or.
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Grids problems
- Turns to MatchEasy
- Turtle CommandsEasy
- Up and to the RightEasy
- Wireworld StepEasy
- Crush and FallMedium
- Four in a RowMedium
- Life-Like GenerationsMedium
- Minutes to BurnMedium