Yan Cui
I help clients go faster for less using serverless technologies.
This article is brought to you by
I never fully recovered my workspace setup when I upgraded my laptop two years ago, and I still miss things today. If only I had known about Gitpod back then…
The problem description is here, and click here to see all my other Euler solutions in F#.
After reading the question, a quick search on how to test if a point is in a triangle turned up this useful SO answer. Translating the algorithm to F# is pretty trivial:
I saved the triangle.txt file alongside the script file, so to make it easier to load and parse. The content of the file looks like this:
-340,495,-153,-910,835,-947
-175,41,-421,-714,574,-645
-547,712,-352,579,951,-786
419,-864,-83,650,-399,171
…
so for each line, we have the 3 (x,y) coordinates separated by comma.
F# 4 also added a chunkBySize combinator to the Array module, which comes in handy here:
This solution runs for 20ms on my machine.
The source code for this solution is here.
Whenever you’re ready, here are 3 ways I can help you:
- Production-Ready Serverless: Join 20+ AWS Heroes & Community Builders and 1000+ other students in levelling up your serverless game. This is your one-stop shop for quickly levelling up your serverless skills.
- I help clients launch product ideas, improve their development processes and upskill their teams. If you’d like to work together, then let’s get in touch.
- Join my community on Discord, ask questions, and join the discussion on all things AWS and Serverless.