@Flopet17 posted this blog page in the penguin slack channel
DISREGARD MY SOLUTION … while my maths equation is correct my interpretation of the problem is wrong and i created a solution based on this … eg If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
i was summing all numbers for 3 eg 3,6,9,and all numbers for 5 eg 5
but change his number to 29 he would have 3,5,6,9,10,12,15,18,20,21,24,25,27
i would be doing 3,6,9,12,15,18,21,24,27, and then 5,10,15,20,25
so i would be doing some numbers twice as i took it as two seperate lists …
oh well back to the drawing board lol
so after reading it … i decided to see if i could write a version of the problem he was talking about
basically it was to sum all the numbers up to and less than a max divisible by the num eg if max was 20 and num was 4 you would have 4,8,12,16 … no 20 as 20 is equal to max so result would be 40
so after doing it i recalled from a challenge @P1xt posted the best solutions for certain problems would be arithmetic solutions rather than using loops and arrays and such … so decided to look at the problem for that angle .
so opened up my Microsoft excel and set out to look at the problem and see if i could see any relationships between the numbers and totals … and spotted one and then converted it to a arithmetic equation
this then i converted to code
I am very happy with the result as i expanded it not just to do one number but to do a list of numbers eg get the total for each number in list then return the sum of all totals … and also to do one for sum all the numbers less or = to max divisible by the num
Im even more happy because pre coding days i would never consider being able to do something like this … i would have thought only very clever people could work out things like this … but here i am now doing it lol lol (and im not the clever)
here is my equation
a*((a/x-1)/2+1)``` here is a repl of it in action .... https://repl.it/GHA4/12