Multiple What?

James Wu
4 min readSep 29, 2020

This week marks the twelve-week of school at Flatiron. In another three weeks, my cohorts and I will be graduating. We will be asked to do whiteboard questions on interviews and we will be judged on how we approach these problems. My friend, Nimajneb sent me to Project Eulers to sharpen my mind for those instances. Here is my attempt in solving the first problem.

https://projecteuler.net/problem=1

I have not solved an actual math problem in years. I feel like Alan Garner at the casino.

I think that like those symbols that appear in front of Alan mean something or at least one of them does. Let me grab the symbol, Σ. I know that this symbol means summation (I had to google the name).

lost is the state that I am in

I vaguely remember a famous mathematician that figured out how to add a group of numbers from 1 to 100 (I am going to have to google this).

I need to review of how this summation formula works. I, first, need to add the first and last number together (1+100=101). I am, then, going to divide the sum by 2 (101/2=50.5) and multiple the divided result by the number of integers that was in my group (100). The sum of all numbers from 1 to 100 is 5,050. I just need to apply this concept to my Euler’s problem.

I will need to figure out the largest number in my group and how many instances my main variables (3,5) are in 1,000. The biggest number in my group of numbers is 999 (since my problem asks me for all numbers below 1000). 999 divided by 3 and 5 is 333 and 199 (there is some change in here, but we do not care)respectively. Using Gauss’ formula, my summation should looks like the code box below and yield the following results:

For 3: (3+999)/2 * 333 = 166,833For 5: (5+995)/2 * 199= 99,500

I do believe I am double counting for the instances where the number is divisible by both 5 and by 3. I need to find those instances and remove them from my sum. I will find those instances by using the multiple of 3*5 or 15. All multiples of 15 are double counted since both of my main variables, 3 and 5. Using the same formula above, I can find the total summation of all numbers divisible by 15 under 1,000.

For 15: (15+990)/2 * 55= 33,165

Adding my sums for 3 and 5 and taking away my sum for 15, I have the following:

166,833 + 99,500 - 33,165 = 233,168.

I almost forgot I am trying to become software engineer and not a mathematician. I need to create functions to calculate sums and a function to add the sums.

Below, I have created two functions based on my math formulas above.

function summation(a,b){
let highestNumber = Math.floor(b/a)
return (highestNumber*a+a)/2*highestNumber
}
function combined(a,b,c){
let x = summation(a,c)
let y = summation(b,c)
let z = summation((a*b),c)
return x+y-z
}

My equation does not look brilliant in any way. I created a summation function and had another function to add my sums together. I think I barely manage to solve the problem above. I hope my approach is adequate and I hope to learn more approaches going forward.

Kanpai,

James Wu

--

--

James Wu

Full Stack Developer | Software Engineer | React | React Native | Expo | Ruby on Rails | AWS S3