Results 1 to 2 of 2

Thread: c/c++ CHALLENGE__brain ticker

  1. #1
    Join Date
    May 2005
    Posts
    10
    Rep Power
    0

    Cool c/c++ CHALLENGE__brain ticker

    Oh... i recently got this from one of my lecturers at Exed to do for homework...
    I came up with a Brute Force Solution as i needed to hand it in the next day... i'm trying to work out a more elegant solution...and i was curious on your take of the problem...
    here goes:
    write an algorithm that is capable of determining if a given number (for our purposes: a number between 0.00 to 20.00 [yes double precision]) can be represented by four numbers where their sum and their product are equal to the number.
    hold on...don't start saying u don't understand... here's an example:
    a known example is:
    7.11
    solution: 1.20, 1.25, 1.50, 3.16
    that is 7.11 = (1.20 + 1.25 + 1.50 + 3.16) aslo equal to (1.20* 1.25 * 1.50 * 3.16)

    another?
    7.20
    solution
    0.80, 1.50, 2.40, 2.50
    other solutions exist for this 7.20 as well...
    but anyway...
    let me know how it goes
    xyoni forever

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

    Default

    OK let me draw pon some maths. There are 2 equations a+b+c+d=7.2 and a.b.c.d = 7.2. So simultaneous equations will not work and a brut force method must be used. The solution, if it exists, is a continuous set, ie like all points in a volume are continuous with each other. Now to find a solution take a point from one end of the 4d space say -1000,-1000,-1000,-1000 and another point -0.1,-1000,-1000,-1000 and see which is closer to 7.2

    Let nuff = 1 and little = 0
    So a sample of nuff, nuff, nuff, nuff = 1111

    Do other samples like
    1111
    1110
    1101
    1100
    ...
    0000

    See which sample aproaches 7.2.
    Then continue the process of brut force searching using the two closest points found so far as the new nuff and little limits. As you may have noticed, this optimised the search using a binary-like search. I did not do this implementation and I also assumed that there was some order, like greatest to smallest, in the product & sum of all points, thus a binary-like search could be used. The order is more likely wavy, ie high to low to high, so this method could fail to find existing solutions, and I an not comfortable with that part.

    Do you think this approach could work?
    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

Posting Permissions

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