Project Euler Tricks
Discussions center on efficient mathematical solutions to Project Euler problems, like using n(n+1)/2 for sums instead of loops, brute force critiques, and related puzzles such as primes and digits of e.
Activity Over Time
Top Contributors
Keywords
Sample Comments
I think the joke is that it's hardcoded. It's definitely easier to implement it for n numbers yourself.
- project euler #7: <a href="https://replpad.com/Ly8gcHJvamVjdCBldWxlciAjNwoKZnVuY3Rpb24gaXNQcmltZShuKSB7CiAgICBmb3IgKGkgPSAyOyBpIDw9IChuIC8gaSk7IGkrKykgewogICAgICAgIGlmIChuICUgaSA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gZmFsc2UKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gdHJ1ZQp9CgovLyBpc1ByaW1lKDIpCi8vIGlzUHJpbWUoMykKLy8gaXNQcmltZSg0KQovLyBpc1ByaW1lKDUpCgpmdW5jdGlvbiBudGhQcmltZShuKSB7CiAgICBpZiAobikgewogICAgICAgIGxldCBwb3NpdGlvbiA9IDAKICAgICAgICBmb3IgKGxldCBpID0gMjs7IGkrKykgewogICAgICAgICAg
This can be helpful in Project Euler challenges.
Read this to instantly annihilate Project Euler problems
What's amusing is that multiplying integers with periodic digits is much faster using this method
Just wait until you hear how much power is being spent on finding multiples of 3 and 5!
This is primary school arithmetic, not programming :(
Iām disturbed that he needed a for loop to compute 100*(1-0.9^10)
The way you add the integers up to n isn(n+1)/2.Fixed that for you. No loops, and it's exact. Pick a better example.
Spoiler: for small values of infinite apparently.. 1720 in this case