there’s this problem about line crossings I saw somewhere and was trying to solve.
There’s a 64×64 grid of 8 bit pixels and it has a bunch of 1 pixel wide vertical and horizontal lines of different colors on it. All parallel lines have at least one space between them. The problem is to find the number of line crossings that each set of colored lines makes (e.g. all green line crossings count towards one sum). And find which set of lines had the fewest amount of crossings. Also, all vertical lines of a color are the same size and all horizontal lines of the same color are the same size.
I had a few ideas but they all seem pretty inefficient. It would involve going through every pixel in the grid, if you run into a color determine if it’s a vertical or horizontal line, and then go in the direction of the line all the while checking adjacent sides for different colors.
I’m trying to decide if first counting the length of the horizontal and vertical lines for each color would speed up the process. Do you guys have any brilliant ideas for how to do this?
Here are two examples. Notice that parallel lines always have a space in between them.


On the grid with your lines look for 2 types of 3×3 squares:
“.” represents background (always black?), “a” and “b” represent 2 different colors (also different from the background color). If found, bump up by 1 the counts for a-colored line intersections and b-colored line intersections.