Jim's
Tutorials

Fall 2018
course
site

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.

attachments [paper clip]

  last modified size
TXT euler6.py Thu Mar 28 2024 10:23 am 1.0K
TXT euler_5.rb Thu Mar 28 2024 10:23 am 1.3K
TXT euler_5_spec.rb Thu Mar 28 2024 10:23 am 615B
TXT euler_6_test.py Thu Mar 28 2024 10:23 am 350B