Welcome to MindCipher, a social repository of the world's greatest brain teasers, logic puzzles and mental challenges.

Martyn Shutt

Likes 0

Martyn Shutt must be new here...

Ratings 0

No ratings yet!

Comments 3

No if() Only abs()

This is the solution I came up with in C++;

int largerNum(int x, int y){

int pt1 = (x - y);
int pt2 = (pt1 - abs(pt1)) / (x/x + y/y); // 2
int pt3 = abs(pt2);
return pt3 + x;


I decided it would be easier for me to get to the solution if I broke it up into individual parts. But working from that, as a single expression;

return (abs((x - y - abs(pt1)) / (x/x + y/y))) + x;

No if() Only abs()

Correction; as a single return statement it should be

return (abs((x - y - abs(x - y)) / (x/x + y/y))) + x;

I accidentally left variable pt1 in there.

No if() Only abs()

But as highlighted in other posts, it doesn't work if either number is zero. It actually crashes my compiled application. Probably due to dividing by zero.