*WriteLine, you know I never used that*
Yes, you are dismissed Don't let it happen again
*WriteLine, you know I never used that*
Yes, you are dismissed Don't let it happen again
Let's act on what we agree on now, and argue later on what we don't.
Black men leave Barbeque alone if Barbeque don't trouble you
there are 6 multiples of 3 as obtained from 19/3 = 6 ...Originally Posted by recursion
however we need 7 terms for our summation to give the correct answer Sum(0,3,6,9,12,15,18) => 7/2 (0 + 18) = 63
what i was saying is that if Nfactors is odd, say 3 from limit = 19Originally Posted by crosswire
(Nfactors/2 * (Nfactors -1) * 5) =>
(3/2 * (3-1) * 5) =>
(1 * (3 -1) * 5) =>
(1 * (2) * 5) =>
(2 * 5) =>
10
but we should have gotten 15 ... since its 3 terms of 5 ... ( 0 + 5 + 10 ) = 15
(Nfactors * (Nfactors -1) * 5 / 2) =>
(3 * (3-1) * 5 / 2) =>
(3 * (2) * 5 / 2) =>
(6 * 5 / 2) =>
(30 / 2) =>
15
i actually explained that, but the post got eaten by a logon timeout while i was editing the post, so i had to resort to multiple posts.
Last edited by icymint3; Aug 16, 2006 at 11:25 PM.
Cultured in Aggression and Koding like a Warrior!!
“Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
"The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein
Actually, didnot reallize the error until you mentioned it in post 17. Also, didn't see that you stated the resolution to it. OK, we are somewhat in agreement then. The "round off" caused by the "/2" should be avoided. Just noticing it there "the Nfactors/2 will give an incorrect result when Nfactors is odd (divide last)" in that post.
Also noted the error of multiple instead of factor. I guess I should do some lines too.
Let's act on what we agree on now, and argue later on what we don't.
Black men leave Barbeque alone if Barbeque don't trouble you
written in Haskell
my first thoughts.... nto the most efficient but hey it'll get the job done
dont have a Haskell compiler at work but there is my 15 second answer......Code:main :: Int -> Int main x = sum_list (siv_list ( define_limit x)) define_limit:: Int -> [Int] define_limit y = [1,2..y] sum_list :: [Int] -> Int sum_list a:[] = a sum_list a:b = a + sum_list (b) siv_list :: [Int] -> [Int] siv_list (x:[]) = if mod x 3 = 0 || mod x 5 = 0 then x else 0 siv_list (x:xs) = if mod x 3 = 0 || mod x 5 = 0 then (siv_list (xs)):x:[] else (siv_list (xs)):[]
Last edited by gmanr26; Aug 17, 2006 at 08:37 AM.
"And what's the real lesson? Don't leave things in the fridge"
hrm.. seems more like a math question.. I recall the summation series from school as:
n/2 * (n+1)
so the ans is:
3 * ((limit/3)*((limit/3)+1)/2 + 5 * ((limit/5)*((limit/5)+1)/2 - 15 * ((limit/15)*((limit/15)+1)/2
It is a math problem so the math logic must be optimised first before running code logic : A two phase process.
Let's act on what we agree on now, and argue later on what we don't.
Black men leave Barbeque alone if Barbeque don't trouble you
BTW define "most efficient code wins" because if the limit is 1,234,567,890 and a solution has 10 pages of code which takes 0.000001 sec to completely run the task, then which variables define most efficient code, ie. variables like logical and mathematical optimizations, code lenght, code speed. I see someone throwing in asm. I assume that it is mathematical, followed by logical, followed by short code for the most efficient. Any iterations would espect to be slow especially when limit is large. Even though I did maths like this in primary school, I think , I might would have overlooked the mathematical optimisation
I will try to put up my solution. Laid back at the moment.
Let's act on what we agree on now, and argue later on what we don't.
Black men leave Barbeque alone if Barbeque don't trouble you