Page 3 of 3 FirstFirst 123
Results 21 to 28 of 28

Thread: Summer Challenge #1

  1. #21
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Thumbs up

    *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

  2. #22
    Join Date
    Dec 2002
    Posts
    500
    Rep Power
    0

    Default

    Quote Originally Posted by recursion
    Not sure if I get that.............., however I do see a flaw with my previous post......, maybe the same thing........, Nfactors should include zero for each summation (Nfactors)++.
    there are 6 multiples of 3 as obtained from 19/3 = 6 ...
    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

    Quote Originally Posted by crosswire
    Anyway, I disagree with some of what you say ice and that nFactor / 2 is not needed if we work in 'double' as in calculate everything at 2twice their true value and in the end we can do one scale down of a half. Later.
    what i was saying is that if Nfactors is odd, say 3 from limit = 19
    (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

  3. #23
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    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

  4. #24
    Join Date
    Jul 2006
    Posts
    249
    Rep Power
    0

    Default

    written in Haskell

    my first thoughts.... nto the most efficient but hey it'll get the job done

    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)):[]
    dont have a Haskell compiler at work but there is my 15 second answer......
    Last edited by gmanr26; Aug 17, 2006 at 08:37 AM.
    "And what's the real lesson? Don't leave things in the fridge"

  5. #25
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default

    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

  6. #26
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    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

  7. #27
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    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

  8. #28
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default

    Quote Originally Posted by crosswire View Post
    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.
    well one things for sure < loc does not necessarly mean most efficient.
    Last edited by leoandru; Aug 22, 2006 at 11:07 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •