Scripting puzzle / challenge.

Alex Tweedly alex at tweedly.net
Sun Jan 12 20:39:56 EST 2020


It's been a while since we had a puzzle challenge on here ....

I came across this article

https://medium.com/free-code-camp/bet-you-cant-solve-this-google-interview-question-4a6e5a4dc8ee

and it seemed to me like an interesting puzzle. The article is 
interesting, but (IMHO) pretty flawed; don't be put off by how complex 
he makes it seem :-).

Problem is simple:

given a rectangular grid of squares, each square has a color and the 
task is to find the largest contiguous block of any single colour.

We'll keep the problem size moderate - up to 100x100 squares in the 
grid, up to 8 colours. Any 2 squares are adjacent only if they share an 
edge - i.e. corner touches don't count.

The input format is a file : each line is a row of the grid, each 
character is a square within that row, and the value of the char 
represents the colour of that square. (or simply generate the data 
internally in the same format).

So an example would be

rbbrbbrb
rggggggr
rgbbbbgr
rgbbbbgr
rgbbbbgr
rggggggr
rbbrbbrb

which has a block of 18 'g' squares, so the result would be something like

2,2 3,2 4,2 5,2 6,2 7,2 2,3 7,3 2,4 7,4 2,5 7,5 2,6 3,6 4,6 5,6 7,6

I'll post my solution in a day or two - but if you are impatient you can 
download from

https://www.tweedly.org/downloads/color_solver.livecodescript
     - text file, script for the solution function only (< 100 lines)

https://www.tweedly.org/downloads/ColoutCounter.livecode 
<https://www.tweedly.org/downloads/color_solver.livecodescript>
     - stack file, including display of the results, etc.

and some sample data at ..../color_1.txt   .../color_2.txt and 
.../color_3.txt

-- Alex.



More information about the use-livecode mailing list