Project Euler — Problem 102 Solution

The prob­lem descrip­tion is here, and click here to see all my oth­er Euler solu­tions in F#.


After read­ing the ques­tion, a quick search on how to test if a point is in a tri­an­gle turned up this use­ful SO answer. Trans­lat­ing the algo­rithm to F# is pret­ty triv­ial:


I saved the triangle.txt file along­side the script file, so to make it eas­i­er to load and parse. The con­tent of the file looks like this:





so for each line, we have the 3 (x,y) coor­di­nates sep­a­rat­ed by com­ma.

F# 4 also added a chunkBy­Size com­bi­na­tor to the Array mod­ule, which comes in handy here:


This solu­tion runs for 20ms on my machine.


The source code for this solu­tion is here.

Liked this post? Why not support me on Patreon and help me get rid of the ads!