문제

Let us have 3 variables of type boolean - a, b, c. You can choose the values of these values to be whatever you like (TRUE or FALSE).

Is it possible to create an expression using the three values only once and using only && (AND) operator, || (OR) operator and brackets to make it give us a different result if the brackets were removed.

For example:

var a = false;
var b = false;
var c = false;
var d = true;
console.log(  a || b && c || d  );
console.log(  (a || b) && (c || d)  );

will give us different results because of the brackets.

Is it possible to find an expression using only three variables? I'm using JavaScript but the question is also valid for C, Java, etc...

도움이 되었습니까?

해결책

It's definitely possible. For example:

var a = true;
var b = false;
var c = false;

console.log(a || b && c);
console.log((a || b) && c);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top