FunctionRacerProblemsRace

Stones Settle

EasyGridsPython, JavaScript, TypeScript, Java, C++

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

grid ["oo.","o#o","..#","..."]
returns [".o.",".#o","o.#","o.."]

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

grid ["o",".","#","o",".","o"]
returns [".","o","#",".","o","o"]

The bottom stone stays put and the stone above it falls onto it. The top stone falls only as far as the block.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Grids problems