Working through the Project Euler problem set. I am grateful to Mr. Euler 🧙 for maintaining this website for over 300 years now and I'm sure he's probably more than a little tired.
I do not know the math so almost always my first approach is brute force and iteration, because I am full monke programmer.
Once I have my humble approach, only then do I look at the description and solution from Project Euler. When I implement the Euler solution there is always a flabbergasting performance improvement as I squint at the math and my original function struggles to finish.
I take it as an opportunity to learn the math behind the answer. Sometimes this takes considerably longer for me than learning a programming concept but I hope to find more and more uses for the math in my personal and professional programming.
In case you missed it this code is in JavaScript. To run it you will need to install Node.js unless you can just execute it with your mind 🧠.
If you're not using your brain, open a terminal/console/command prompt/powershell/dark window into the nether and type:
# Navigate to wherever you downloaded the project and specific problem folder you are trying to run
cd to/the/folder/problem-01
# Run it with Node
node index.js
If you prefer a big sparse browser tab and looking at its guts in the dev tools instead you will still need to install Node.js but then you can install http-server, or any other local web server, but I'm using the really convenient http-server for this project because it's got a turtle. I recommend installing it globally which means it will be available anywhere credit cards are accepted.
npm install --global http-server
# Or if you're one of those smart kids in class that everyone hates
npm i -g http-server
# Then traverse to the main project directory if you haven't already
cd to/the/folder/
http-server
Once the server is running open a browser and go to http://localhost:8080/problems/problems-0001-0050/problem-01/index.html. You will need to include the problem folder in the path because you started the server from the project root, which is normal, and you will need to include the filename (index.html). Even though it says it defaults to index.html it doesn't always work. Or ever. That's OK I love you turtle 🐢