Solved euler-5 in ruby:
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
I brute forced the algorithm which took a solid minute or two to process using an array and modulo arithmatic. Then I wrote some tests, refactored everything into an object and took out some unnecessary terms. I figured out that I only had to jump by 20, not 1, because the number had to be divisible by 20 and I could start checking at 2520. I also realized I didn't have to check for 1-10 because any number factorable by 11-20 is also factorable by 1-10. This improved the run-time to a second or two.
last modified | size | ||
euler6.py | Wed Dec 04 2024 07:15 pm | 1.0K | |
euler_5.rb | Wed Dec 04 2024 07:15 pm | 1.3K | |
euler_5_spec.rb | Wed Dec 04 2024 07:15 pm | 615B | |
euler_6_test.py | Wed Dec 04 2024 07:15 pm | 350B |