Inspired by Is this Flow Free puzzle trivial? by @Bubbler. Lengthy chunks of this challenge are borrowed from there. This may be one step of a solution for the linked challenge, depending on chosen strategy.
Flow Free is a series of puzzle games whose objective is to connect all the same-colored pairs of dots on the grid. In this challenge, we consider the original game on a rectangular grid (no variations like bridges, warps, or hexagonal grids).
A puzzle in Flow Free might look like this:
Puzzle Solution ....1 11111 ..... 13333 ..24. 13243 1.... 13243 23... 23243 ...43 22243
Given a solved Flow Free puzzle, output the unsolved puzzle.
The input can be taken as a single string/array or a list of lines. You may also take the dimensions of the array as input.
You may assume only the digits 1-9 are used and the numbers used in the solved puzzle will be a strict prefix of these (i.e. no need to handle there being
2s but no
1s in the input). Also, each line represented by each digit is a valid polystrip of length 3 or higher.
Unsolving means identifying the ends of the polystrips and keeping them in place, while replacing other cells with a
0 or any consistent non-digit character.
Output the string/array in any convenient manner.
This is code-golf, the shortest code per language wins!