2005 math problem

From: uthman (o_masud_at_yahoo.com)
Date: 01/15/05


Date: Sat, 15 Jan 2005 14:52:59 +0000 (UTC)

Concerning the 2005 math problem ( which asks to use adding,
subtracting, dividing, multiplying, exponentiating, square-rooting,
making decimal numbers, factorials, and concatenating numbers [like
making 1 and 2 into 12 or 21] with the digits 2005 to make the
integers 1-100), does anyone know of an efficient algorithm to do
this? Mine involves making many loops; 1 for the numbers 1-100, 4 for
the different input values of the functions, and 3 for the functions
themselves.
Please see below code:
Notes: max_number_to_solve is in this case 100. the f_2 function takes
in three parameters: the first number, the second number, and the
function number. The function number indicates what function to use
(adding, subtracting, etc.) while the first and second numbers are
inputs to the function. There are 12 positions in the vector
"digits[]" because 4 take up "2005", 4 more take up the factorials of
each of those digits, 4 more take up the square roots of each of those
digits, and 1 takes up the null character. It starts at digits[0],
which is "2" if the year is "2005".
If anyone wants the full program (I think it works) e-mail me at
o_masud@yahoo.com
(uses c++)

        for(x=1;x <=max_number_to_solve;x++){//to obtain answers
        for(int a = 0; a <= 11; a++){// for 12 digits:1st var
        for(int b=0; b<=11; b++){// for 12 digits: 2nd var
        for(int c=0;c<=11;c++){// " ": 3rd var
        for(int d=0;d<=11;d++){// " ": 4th var
        for(int e=0;e<=6;e++){// 7 2-parameter functions
        for(int f=0;f<=6;f++){// 7 2-paramter functions
        for (int g=0;g<=6;g++){// 7 2-parameter functions
        // 0-6 correspond to a function #
                if (x==( f_2(f_2(a,b,e), f_2(c,d,f), g) ) && nonrepeating(a,b,c,d)
&& !found[x]) {
                        outfile<<x<<"= [" << g << "]( [" << e << "] ("<< a <<","<<b<<"),
["<<f<<"]("<<c<<","<<d<<") )"<<endl;
                        found[x]=true;
                }
        }}}}}}}}

Thanks



Relevant Pages

  • Re: Sine code for ANSI C
    ... > your take on the following floating point issues.. ... > digits and accurate within its precision. ... subtracting 2*pi from your argument r until it's less than 2*pi. ...
    (comp.lang.c)
  • Re: OT How do this work?
    ... BJ Conner wrote: ... By adding the two digits and then subtracting the result, your answer is constrained to a certain set of numbers. ... Cut "to the chase" for my email address. ...
    (rec.outdoors.fishing.fly)
  • Re: floating point help!
    ... How does subtracting '0' turn this into an array of digits? ... subtraction does an implicit conversion back to numeric by ML design. ...
    (comp.soft-sys.matlab)
  • Re: How does this work?
    ... digits and subtracting the result from the original number. ... All the answers are multiples of 9. ... Wyre Piddle, Worcestershire ...
    (uk.education.staffroom)
  • Re: mode for a scene?
    ... >>> of a multidigit number and the result is divisible by three, ... > Adding the digits of a number is equivalent to repeatedly dividing by 9. ... > When the total is 9 or less, that's the remainder. ... Subtracting nine ...
    (rec.arts.sf.composition)