FAQ Database Discussion Community


Double compare in JavaScript looks weird [duplicate]

javascript,boolean,compare,boolean-expression
This question already has an answer here: chaining double equals == returns false 3 answers Let's var a = "first", b = "second", c = "first";. Expression a == c returns true, (of course!); a == c is true too. Then why does a == a == c return...

How to create a boolean local variable as a result of MouseEvent?

java,mouseevent,boolean-expression
I'm just starting to learn Java and I'm trying to correctly initialise 4 variables that come from a MouseEvent. I understand how to retrieve a click position, but I don't know how to create a boolean local variable, leftClicked, and initialize it to true if the left mouse button is...

I have a language where I need to determine if my flow control statement predicates are tautologies or contradictions

compiler-construction,compiler-errors,boolean-expression
Hello I'm working on a domain specific language with my project group. We want to report to the language user if the predicate in for example if(predicate) or while(predicate) are always true or always false. The logic operators implemented on the language are AND, OR, NEGATION as well as the...

What's wrong with order for not() in python?

python,operators,boolean-expression
What's wrong with using not() in python?. I tried this In [1]: not(1) + 1 Out[1]: False And it worked fine. But after readjusting it, In [2]: 1 + not(1) Out[2]: SyntaxError: invalid syntax It gives an error. How does the order matters?...

SSN validation using strings

java,string,validation,io,boolean-expression
I'm supposed to write a program that reads in a SSN as a string, including dashes, like DDD-DD-DDDD, where 'D' is a digit. If it's valid, it prints "valid ssn" and the opposite if it isn't valid. I'm supposed to have four methods: main, public static boolean validSSN(String s), public...

Using a BOOLEAN expression in a #define value

ios,define,boolean-expression
I usually define my constants like so #define kIamAconstant and I have my api endpoint in a constant like this. Now my project requires me to have a toggle that switches this between two different end points for testing. I have a 10s of thousands of lines of code, and...

Which laws simplify this boolean expression?

boolean-expression,simplification,boolean-algebra
Which laws do I need to use to simplify !X + (!Y + !Z)*(Y + Z) to !X + (Y*!Z) + (!Y*Z) ...

switch between true and false state

jquery,boolean-logic,boolean-expression
I have an object representing a player and let us say 2 players //create a player object function player(name,state,score) { this.name = name; this.state = state; this.score = score; } var players = [ new player('player1',true,0), new player('player2',false,0) ]; so I want the players to make a move one after...

How to express a condition in a Mongo Pipeline with multiple $and's on the same level

php,mongodb,aggregation,boolean-expression
My problem is that I need to express a condition in a Mongo Aggregation pipeline in the format ((A&B)||(C&D)) which when you write it out in the format that Mongo writes it's boolean expressions in yields {$or: {$and: {A, B}, $and: {C ,D}}. The problem with this is that you...

Boolean function confusion

boolean-expression
I'm trying to do the Kmap for F(A,B,C,D)= A’B’C’D’+AC’D’+B’CD’+A’BCD+BC’D . I'm getting a little confused because not all the variable groupings have the same number of variables. some have 4 and some have 3. is this equivalent to F(A,B,C,D) = F(0,2,4,5,7) ? I don't know if you have to do...

Understanding a Boolean conjunction statement in Rails method

ruby-on-rails,ruby,boolean-expression
This might be a trivial point, but I don't understand it and it bothers me. Going through the Ruby on Rails Tutorial by Michael Hartl, there is this method definition : def create user = User.find_by(email: params[:session][:email].downcase) if user && user.authenticate(params[:session][:password]) log_in user redirect_to user else flash.now[:danger] = "Invalid email/password...

Boolean expressions - getting mixed up with AND, OR logical operators and how they work

javascript,boolean-expression
I have to convert a number to comma format. E.g 12345 => 12,345. I have my solution : function convert(n) { n = n.toString(); var result = ''; var count = 0, var idx = n.length - 1; while (r = n[idx]) { count++; result = ((count % 3 ==...