27
3
This challenge is in honor of the Rookie of the Year category winners of Best of PPCG 2015: muddyfish (for I'm not the language you're looking for!) and quartata (for Implement a Truth-Machine). Congratulations!
Background
In the deepest trenches of the ocean, there lives a rare and elusive square-shaped fish called the quartata-fish. It looks like the glider from the Game of Life cellular automaton. Here are two quartata-fish of different sizes:
-o-
--o
ooo
--oo--
--oo--
----oo
----oo
oooooo
oooooo
You have managed to snap a photo of the quartata-fish, but the fish is rather hard to see since it's covered in mud. Now you'll have to write a program to clean up the photo.
Input
Your input is a rectangular 2D grid of the characters .-o#
, given as a newline-separated string.
If you want, you can use pipes |
instead of newlines as the separators, and you may assume one trailing and/or preceding separator.
The input will contain exactly one quartata-fish of some side-length 3*n
, where n ≥ 1
is a positive integer, surrounded by periods .
that represent the ocean floor.
The fish will always be in the orientation depicted above.
Overlaid on this grid, there will be exactly one non-empty rectangular region of hashes #
, which represents a blob of mud.
The blob may cover the quartata-fish partially or entirely.
An example input would be
............
..--oo--....
..--oo--....
..---#####..
..---#####..
..ooo#####..
..oooooo....
Output
Your output shall be generated from the input by replacing all the hashes with the characters .-o
, so that the grid contains exactly one quartata-fish.
There will always be a unique way to perform this replacement properly; in particular, the blob of mud will cover the fish entirely only if its size is 3×3.
The output shall use the same separator as the input.
For the above input, the correct output would be
............
..--oo--....
..--oo--....
..----oo....
..----oo....
..oooooo....
..oooooo....
Rules and scoring
You can write a full program or a function. The lowest byte count wins, and standard loopholes are disallowed. There are no time bounds: if your submission would eventually halt given unlimited time and resources, you're fine.
Test cases
Input:
.......
...-o-.
...--o.
##.ooo.
##.....
Output:
.......
...-o-.
...--o.
...ooo.
.......
Input:
...-o-.
...-#o.
...ooo.
.......
Output:
...-o-.
...--o.
...ooo.
.......
Input:
.........
.###.....
.###.....
.ooo.....
Output:
.........
.-o-.....
.--o.....
.ooo.....
Input:
.....
.###.
.###.
.###.
Output:
.....
.-o-.
.--o.
.ooo.
Input:
......
......
......
...###
...###
...###
Output:
......
......
......
...-o-
...--o
...ooo
Input:
###o--....
###o--....
###-oo....
###-oo....
###ooo....
###ooo....
###.......
Output:
--oo--....
--oo--....
----oo....
----oo....
oooooo....
oooooo....
..........
Input:
............
..--oo--....
..--oo--....
..---#####..
..---#####..
..ooo#####..
..oooooo....
Output:
............
..--oo--....
..--oo--....
..----oo....
..----oo....
..oooooo....
..oooooo....
Input:
...--oo--....
.#########...
.#########...
.#########...
...oooooo....
...oooooo....
.............
.............
Output:
...--oo--....
...--oo--....
...----oo....
...----oo....
...oooooo....
...oooooo....
.............
.............
Input:
..............
..............
.########.....
.########.....
.########-....
.########-....
.########o....
.########o....
.########o....
.########o....
.########.....
..............
Output:
..............
..............
..............
..............
....--oo--....
....--oo--....
....----oo....
....----oo....
....oooooo....
....oooooo....
..............
..............
Input:
.................
.................
..---ooo---......
..--#########....
..--#########....
..--#########....
..--#########....
..--#########....
..oo#########....
..oo#########....
..oo#########....
....#########....
Output:
.................
.................
..---ooo---......
..---ooo---......
..---ooo---......
..------ooo......
..------ooo......
..------ooo......
..ooooooooo......
..ooooooooo......
..ooooooooo......
.................
Input:
.........................
.........................
....----oooo----.........
....----########.........
....----########.........
....----########.........
....----########.........
....----########.........
....----########.........
....----########.........
....oooo########.........
....oooo########.........
....oooooooooooo.........
....oooooooooooo.........
.........................
Output:
.........................
.........................
....----oooo----.........
....----oooo----.........
....----oooo----.........
....----oooo----.........
....--------oooo.........
....--------oooo.........
....--------oooo.........
....--------oooo.........
....oooooooooooo.........
....oooooooooooo.........
....oooooooooooo.........
....oooooooooooo.........
.........................
Is it ok if the entry has a probability it won't finish (bad randomness) even though the chances of that are extremely low? Also are you allowed to change characters other than the single newline-pipe? – Blue – 2016-04-03T20:07:27.713
@muddyfish Yes to first question (it must eventually finish with probability 1, assuming perfect randomness, but may theoretically run forever), no to second (the characters are fixed). – Zgarb – 2016-04-03T20:21:52.673
so is a probability of 0.9 recurring ok? – Blue – 2016-04-03T20:23:14.007
@muddyfish If you're generating random grids in a loop until one fits, that's ok. – Zgarb – 2016-04-03T21:05:35.217
Important test case:
......|......|......|...###|...###|...###
(in case a solution tries all possible top-left coordinates, and tries to fit a 6x6 over the area) – Sp3000 – 2016-04-04T06:41:14.160@Sp3000 Thanks, I'll edit that in when I get the chance. – Zgarb – 2016-04-04T13:56:55.297