Unfortunately, considering only horizontal and vertical lines doesn’t give you the full picture; you need to also consider diagonal lines.

Because of the limits of the hydrothermal vent mapping system, the lines in your list will only ever be horizontal, vertical, or a diagonal line at exactly 45 degrees. In other words:

Considering all lines from the above example would now produce the following diagram:

1.1....11.
.111...2..
..2.1.111.
...1.2.2..
.112313211
...1.2....
..1...1...
.1.....1..
1.......1.
222111....

You still need to determine the number of points where at least two lines overlap. In the above example, this is still anywhere in the diagram with a 2 or larger - now a total of 12 points.

Assignment

Consider all of the lines. At how many points do at least two lines overlap? Determine this in the following way:

Example

In this interactive session we assume the text files lines01.txt1 and lines02.txt2 to be located in the current directory.

> overlap ("lines01.txt")
12 :: Int
> overlap ("lines02.txt")
20898 :: Int

Epilogue

Jari Komppa (@Sol_HSA3) animated his solution.