Find longest consecutive characters in 2D array

Charcoal, 110 bytes

≔⪫A⸿θPθFθ«≔⟦⟧ηF∧¬№0⸿ι⟦→↘↓↙⟧«≔KDLθ✳κζW›Lζ№ζι≔⊟ζε⊞η⟦κιLζ⟧»¿⁼¹⌈Eη§κ²⊞υ⊟ηFη⊞υκι»⎚≔⌈Eυ§ι²εFΦυ⁼⊟ιε«⊟ι,Iε,P✳⊟ι⎇⊖ε¹.¦⸿

Try it online! Link is to verbose version of code. Takes an array of strings as input. Explanation:

≔⪫A⸿θPθ

Join the strings with carriage returns (not newlines) and output them without moving the cursor.

Fθ«

Loop over each character in the string.

≔⟦⟧η

Collect all of the consecutive characters starting at this position in an array.

F∧¬№0⸿ι⟦→↘↓↙⟧«

If the current character is not a 0 or a carriage return, then check all four directions.

≔KDLθ✳κζ

Peek as much as possible in that direction.

W›Lζ№ζι≔⊟ζε

Shorten the string until all of the characters are the same.

⊞η⟦κιLζ⟧»

Save the results in the array.

¿⁼¹⌈Eη§κ²⊞υ⊟ηFη⊞υκ

If the maximum consecutive character was 1, then only push one of the results to the final array, otherwise push all of them.

ι»

Reprint the current character, this time allowing the cursor to move.

Clear the input from the canvas.

≔⌈Eυ§ι²ε

Find the longest consecutive length.

FΦυ⁼⊟ιε«

Loop over the entries with that length.

⊟ι,Iε,

Output the character and length.

P✳⊟ι⎇⊖ε¹.¦⸿

If the length is 1 then output a . otherwise output a direction character. Then move to the start of the next line for the next result.


Jelly, 52 54 bytes

,UŒD€;,Z$ṣ€€”0ŒrẎ€⁺;€"“\/-|”Ẏ2ị$ÐṀ¹F}ḟ”0;€1,”.ʋؽœị’Ɗ?

Try it online!

A monadic link that takes a list of strings and returns. list of maximal outputs each in the order n, m, d. A third of the code is to deal with the requirement for dots (last example). Now handles Kevin Cruijssen’s edge case correctly.