0

Do you TRY it? It works.

#include <stdio.h>

int main (void)
{
   int a, b, c, d, min1, max1, min2, max2, min, max;
   scanf ("%d %d %d %d", &a, &b, &c, &d);
   if (a > b) 
   {
      max1 = a;
      min1 = b;
   }
   else 
   {
      max1 = b; 
      min1 = a;
   }
   if (c > d) 
   {
      max2 = c;
      min2 = d;
   }
   else 
   {
      max2 = d;
      min2 = c;
   }
   if (min1 < min2) min = min1;
   else min = min2;
   if (max1 > max2) max = max1;
   else max = max2;
   printf ("%d %d", max, min);
   return 0;
}

Sample running, with A as 1 and B as 10 (i.e. highest AND lowest in A and B):

$ ./a.exe
1 10 4 5
10 1

Sample running, with A as 1 and D as 4:

$ ./a.exe
1 2 3 4
4 1

It works.

0

Damn. Battery is dead on that computer. I will have to wait a while.

This is similar to what I was doing, but not quite the same.

Now if this DOESN'T work for me after it just worked for you, then I have more serious problems!

But just for fun-- run it a few times with different combinations and see what happens.

0

But just for fun-- run it a few times with different combinations and see what happens.

There are only 4! permutations. It's trivial to test this algorithm rigorously by hand.

0

I have not tested yours on my computer because the battery is dead, but I printed it out to take a look.

The only real difference I can see is that you have defined your final min as

if (min1 < min2)
min = min1
else min = min 2

Mine was the opposite:

if (min1 > min2)
min = min2
else min = min1

..... but that's the same meaning.

Other than that, the only difference is that you went (at the end) min first, then max and I did Max first then min...

then there was also that you used the words "max" and "min", whereas I used X and Y.

.......... are any of these programming errors that would cause the program to malfunction and ocassionally fail with the minimum number?

0

No way to get it down to 4 "if"s.

You can as kvothetech said, but you have to introduce new variables.

min1 = smallest of A and B
max1 = largest of A and B

min2 = smallest of C and D
max2 = largest of C and D

min = smallest of min1 and min2

max = largest of max1 and max2

Each block above is one if/else

1

Code

#include <stdio.h>

int main(int argc, char *argv[])
{
    int i, a, b, c, d, w1, w2, l1, l2, x, y, arr[24][4];
    i = 0;
    //just to come up with permutations
    for(a=1;a<5;a++){
      for(b=1;b<5;b++){
        for(c=1;c<5;c++){
          for(d=1;d<5;d++){
            if(!(a==b || a==c || a==d || b==c || b==d || c==d)){
            arr[i][0]=a;
            arr[i][1]=b;
            arr[i][2]=c;
            arr[i][3]=d;
            i++;
            }
          }
        }
      }
    }
    for(i=0;i<24;i++){
      //for each combination calculates max and min
      if(arr[i][0]>arr[i][1]){
        w1 = arr[i][0];
        l1 = arr[i][1];
      }
      else{
        w1 = arr[i][1];
        l1 = arr[i][0];
      }
      if(arr[i][2]>arr[i][3]){
        w2 = arr[i][2];
        l2 = arr[i][3];
      }
      else{
        w2 = arr[i][3];
        l2 = arr[i][2];
      }
      if(w1>w2)
        x = w1;
      else
        x = w2;
      if(l1<l2)
        y = l1;
      else
        y = l2;

      printf("%d%d%d%d - %d %d\n", arr[i][0], arr[i][1], arr[i][2], arr[i][3], x, y);
    }
    system("PAUSE");    
    return 0;
}

Output

1234 - 4 1
1243 - 4 1
1324 - 4 1
1342 - 4 1
1423 - 4 1
1432 - 4 1
2134 - 4 1
2143 - 4 1
2314 - 4 1
2341 - 4 1
2413 - 4 1
2431 - 4 1
3124 - 4 1
3142 - 4 1
3214 - 4 1
3241 - 4 1
3412 - 4 1
3421 - 4 1
4123 - 4 1
4132 - 4 1
4213 - 4 1
4231 - 4 1
4312 - 4 1
4321 - 4 1
0

Well that's a nice complicated program that violates the premise of the assignments and the teacher would never believe is mine anyway........ : ) : )

Edited by cocopium

0

Nevermind the for loops. I was just showing you that kvothetech's solution works for all 24 combinations of 1, 2, 3 and 4. Since you asked...

0

I tried the standard 2 mins 2 max's, but it just isn't working for me (everyone else says it works for them-- but so far nobody has tested the exact same thing and can verify beyond a shadow of a doubt that it works for the in all 4 number arangements).

Maybe I screwed up my defaults or something. I don't know. All I know at this point is that physics, calculus, and chemistry are much easier than computer programming!! : )

0

Well that's a nice complicated program that violates the premise of the assignments and the teacher would never believe is mine anyway........ : ) : )

Wow. When you described yourself as a "champion puzzle solver", clearly you didn't mean as a programmer. Otherwise you'd be able to see that scudzilla's code is a test framework wrapped around the same algorithm you've been claiming doesn't produce the correct result.

0

Oh, it's the same thing?? I couldn't tell. Sorry (computer idiot)

0

No, I can't see that. Prior to this class I have never interacted with a computer. I don't know what I did wrong, but I have rearranged that program in every different way and it just isn't working. I think I just must have screwed up something in the software (reset defaults??? I don't know)

0

No, I can't see that.

Write it out on paper.

Only one other thing remaining, show your code.

Edited by pritaeas

0

I did. Up above.
I wrote it out.

If you see what's wrong, please, by all means, enlighten me. Otherwise I give up. I have tried my best here, but logic skill alone can't make it work...... and I don't have computer skills.

If you scroll up you will see my code. I think I wrote the majority of it several times, but I know I wrote the whole thing out once.

0

oh-- but I didn't type out the comments, the introduction of variables, etc..... just the important part.

0

I did. Up above.
I wrote it out.

You posted pseudocode. Please post a complete C program that compiles and runs.

0

I can't copy and paste. It's on a different computer (my notebook that I don't even know how to use!!). There is no internet on that computer (haven't bought a wireless modem yet).

I can re-type it piece by piece, but that will take a while.

0

You'll find that we're very patient. But at this point, if the algorithm isn't working it's because something is wrong with your code.

Edited by deceptikon

0

Ok. I'm getting everything ready to start typing in a second. But it will take a while.

0

Oh no. I just typed up that entire code, then lost it trying to use the "inline code" thing here.

(any way to retrieve it?)
I don't have the will to type it all up again right now.

In any case-- you were right. There was something wrong with the code. I had forgotten to put { } around multiple choice "if"s.
Once I fixed that, it ran fine.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.