11
Your challenge today is to take input like this:
fbcfbee
ffcabbe
debceec
bccabbe
edcfbcd
daeaafc
eebcbeb
And output the best possible move in a Bejeweled-like game that will match three or more letters, like this (note the capital B
and C
):
fbcfbee
ffcabbe
deBCeec
bccabbe
edcfbcd
daeaafc
eebcbeb
Full specifications:
- The input will be
n
lines ofn
lowercase letters each (wheren
could be any number). - The output will be the best move you could make in a match-3 game, with the two letters you want to swap capitalized.
Matches should have the following priority (in these examples,
.
indicates a square that doesn't matter):Five-in-a-row
xxYxx ..X..
Broken five-in-a-row
X.. Yxx x.. x..
or
.X. xYx .x. .x.
Four-in-a-row
xYxx .X..
Three-in-a-row
xYx .X.
You must find the match of the highest priority and output it.
- If there are multiple matches of the same priority, you can output any one of them.
- There will always be at least one match (your program can break if there are no matches, or do anything you want).
- I/O can be in any reasonable format (stdin/out, reading and writing files, function arguments/return values, dialog boxes, etc.) but NOT hardcoded (like
x="[insert input here]"
). - This is code-golf so shortest code in bytes wins. If you use any network access for some reason, all bytes downloaded from the network count against your score.
1+1, but I protest the title; there could be a better move. For instance, one that creates two fives, or one that causes a drop to create more stuff. – Justin – 2014-01-26T05:53:51.830
Does broken five-in-a-row also cover
..x.\nxxYX\n..x.
? – Peter Taylor – 2014-01-26T08:54:17.010@Peter Yes, it does. – Doorknob – 2014-01-26T14:12:03.313
There are 2 broken 5 in a row pattern: the L pattern and the T pattern. Do you require both to be matched? – n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ – 2014-01-26T15:01:36.970
@nhahtdh Yes, I'll edit to clarify that. – Doorknob – 2014-01-26T15:02:01.513
@Quincunx Ok, edited title – Doorknob – 2014-01-26T15:03:41.163