Sink or Swim

A challenge by mousetail avatar mousetail

Description

You will be given a list of lines that look like this:

### <   >    ### <<>><  ##

The characters mean the following:

  • < are rocks that sink left
  • > are bubbles that float right. Cannot pass rocks.
  • # are walls
  • is water (empty space)

Rocks can not pass bubbles, if a bubble is trapped next to a rock, the rock will always push the bubble down regardless of the number of bubbles.

Output the final state of the water column.

In this case, that would be ###< >###<<>>< ##

You may assume no bubbles or rocks can escape.

A few more examples:

  • #<> # becomes #< >#
  • # >< # becomes #>< #
  • # >>>>>>>>>< becomes #>>>>>>>><

Leaderboard

Author bytes
#1 MeWhenI avatar MeWhenI 90