This repository has been archived by the owner on Oct 8, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First kata - find the sum all multiples of 3 or 5 less than 1000
Sixth solution. A whole new approach was attempted here. We have removed the loop throughout every single number to check if it is a multiple of 3 ou 5 to a mathematical approach using 2 different formulaes. 1. the sum of the multiples 3 or 5 = sum of multiples of 3 + sum of multiples of 5 - sum of multiples of 3 * 5 2. the sum of multiples of 3 = ((n * (n + 1)) / 2) * d where n = 1000 / 3 (upper limit divided by the multiple) d = multiple (in this case 3) with this solution we solve the performance issue of the previous solution by providing a constant-time solution. previous solution = 1 operation per number (i.e 10^10 will cause the function to run 10^10 steps) new solution = 3 operation per limit (1 to compute the sum of multiples of 3, 1 to compute the sum of multiples of 5, 1 to compute the sum of multiples of 3 * 5)
- Loading branch information