Solved by Nyder Menendez
Date: Mon, 26 Feb 2001 21:26:58 -0000
From: nyder2000@yahoo.es
Subject: [The Challenge]0014 - Solution

Ok... let's go again...

(Small job... I had to download DJGPP and install it... to see what it was about... but hey... it's always good to learn... and since we're in "Carnivals"... there's a little free time... :-)

Unless you can think of another limitation... or the challenge is to solve it by a... specific method... (for which it would be good to give a guide... :-)

According to my research (documentation...) the comma ',' is an "operator"... correct me if I'm wrong...

and as an operator it appears in the list of... order of precedence... so... it should (unless they say otherwise...) be able to be used within the useful line of code...

and I think... unless I'm mistaken... that was what was meant by stating... the following...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

>> If we go by the definition of a useful line of code that was given in the foundations of this challenge, it is also valid to put any number of lines of code, because not only is the ';' a statement separator, but so is the ','. Very true, <<"this is allowed">>. That is a difference between a useful line of code and a statement.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

So... after several attempts... to understand the precedence logic... of both compilers... (TC 3.0 and DJGPP)... the simplest solution... IMHO... would be the following...

#include <iostream>
using std::cout;
using std::cin;

void main()
{
 int a,b;

 cout << "\n\nEnter integer A: ";
 cin >> a;
 cout << "\nEnter integer B: ";
 cin >> b;

 a=a+b,a=a-(b=(((a-b)>=b)*b)+((b>(a-b))*(a-b)));

 if( a==b )
	 cout << "\n\nThey are equal numbers."; 
else 
	 cout << "\n\nThe largest is " << a << " and the smallest is " << b << ".";
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Which I was able to test... in both compilers... and it worked... but... if they say that you can't... use the comma operator ','... then... no way... just let me know... and we'll try other solutions... By the way... the parentheses... :-)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 a=a+b,a=a-(b=(((a-b)>=b)*b)+((b>(a-b))*(a-b)));
            \  \\\ /   /  /   \\  \ //   \ ///
             \  \\   /  /     \\  /     //
              \  \\  /  /       \\ /      //
               \  \\/  /         \      //
                \  \  /           \     //
                 \  \/             \   //
                  \                 \ //
                   \                 /
                    \________________/

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
That way of "working" the precedence of both compilers... is... very interesting... it seems that they use at a certain point... reverse precedences... and what I seem to interpret... is that those of Borland... threw it away... (they failed...) since the parentheses... in this case... are evaluated from right to left ( <--- ) ... and yet... internally... the other parentheses... (it seems complicated, doesn't it?)... :-) are evaluated from left to right... ( ---> )...

(To understand what I am saying you would have to... try all the possible options that I made... or... imagine them... :-)

and that of "left to right... and then right to left... is a lack of consistency... if I don't understand I'm wrong...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Well... I hope I haven't bored you... keep enjoying the carnivals... :-)

nyder2000@yahoo.es



