From May 22, 2023 to July 10, 2023, I solved 30 computational math problems from Project Euler¹. Here's a summary of what I learned.
What is Project Euler?
Project Euler (pronounced 'Project Oiler') is a database of math problems – but with a key twist. In order to solve the problems, using code is essential, as attempting to solve them by hand is nearly impossible.
Some examples of the problems I had to solve:
- Problem #4 asks for the largest palindrome made from the product of two 3-digit numbers.
- Problem #17 asks: "If all the numbers from 1 to 1000 (inclusive) were written out in words, how many letters would be used?"
- Problem #25 asks for the index of the first term in the Fibonacci sequence that contains 1000 digits.
How did I solve these problems?
I used Zed (a code editor), Go (a coding language), and GitHub (version control) to solve Project Euler problems. Keep in mind that I had no coding experience before I started this challenge for myself. I learned how to code by solving these problems!
Can I see your code?
Absolutely! Here's the open-source repository.
And I solved all of these problems with my own code! Again, you can look at the repository if you'd like. I did, however, ask my dad (a software engineer) and ChatGPT questions about specific Go topics.
What did you learn (in terms of coding)?
I learned a ton! Here's a few of the great things I learned:
- How to use Unix and Git commands
- How to structure a Go file (with package and import declarations)
- Different data types (int, string, bool, etc.)
- Basic Go constructs (if / else if / else statements, for loops, slices, maps)
- How to create a good function (with appropriate inputs and outputs)
- How to write succinct yet descriptive code comments
- How to maintain consistent style (in terms of naming and whitespace)
What did you learn in general?
I learned a ton in regards to coding and computers, but I also learned a lot that's applicable to real life. Some examples:
- How to name functions and variables well (to save other people and my future self from having to debug weirdly-named functions)
- How to provide high-level overviews of complex problems / issues when you're done solving them (super important if you want to understand a problem easier when you're looking at it in the far future)
- How to ask StackOverflow and ChatGPT for help (and provide sufficient information so they can actually help me)
Do you have any advice?
If you're looking to learn code like I did, then I certainly have some advice:
- Code every day. This is super important – I consistently noticed that when I didn't code for a few days, it was significantly harder to get back into the 'flow' of coding.
- You can read all of the code you want. But the only way to actually learn how to code is to write code. Solve Project Euler problems, or solve your own problems, but write some code. It's truly the only way to learn.
- Don't be afraid to ask the internet for help. Even experienced coders Google tough concepts and browse StackExchange all the time. Coding is not a closed-book exam by any means.
¹ I know this article was published on July 8. But '50 days' sounds better than '48 days'.