Your task is to find the total destination of objects that are falling to a planet, you will get inputs like this:
7
...#...
.......
#..O..#
.......
...#...
.......
.......
where O is the planet and # are the objects, note that the planet will attract objects from the for basic directions(NEWS). You should output:
#
#O#
#
i.e the objects after reaching their destination.
The first number given as an input is the length of the grid(nxn), in the above example it is 7.
The object should always move in the shortest direction(note that the allowed directions are only horizontal and vertical; the object can't move diagonally)
If an object is equidistant from two directions it should go in a clock wise direction:
..#
...
O..
Will reach this side:
...
...
O#.
If an object collides with the planet, it will stop. If it collides with another object they become one object,
4
.#..
#...
....
.O..
would become:
....
....
.#..
.O..
One final example:
6
..#...
.#....
......
.#O...
....#.
......
Output:
......
......
..#...
.#O#..
......
......
Note: You should output the final shape, so all outputs are accepted as long as they show the final shape of the planet.
for example for this input:
...#
....
.O..
....
Should output:
O#
or
....
....
.O#.
....
Both of these are accepted.
This is code-golf so the shortest answer will win
Note 2:
As you may have noticed a .
represents vaccum so the shortest path is the shortest number of dots.
For example:
.#.
...
.O.
Is not accepted to be
O#
since the shortest path is vertical. Note3:
The object should always move to be in the same line with the planet in one of the four directions(choosing the shortest)
|<#
|
|
-----O------
|
Restrictions:
2<=n<=100