Questions tagged [logic]

Logic refers to the ultimate flow of your code and how you arrive your desired solution. Questions should relate to finding a coding solution (or improving existing coding logic) to a given problem. Please use with an appropriate language tag, a thorough description of your logic, and the relevant code you're working on. General logic questions are off-topic. If you simply need a code review, consider https://codereview.stackexchange.com

Note that the bulk of questions tagged concern the broad sense of program logic described in the excerpt above. Before using the tag, consider if a tag about a more specialised logic-related topic would be a better fit. Examples include:

Furthermore, if your question is about one of those specialised topics, consider whether it essentially involves programming in some way. If it doesn't, it will likely be more appropriately posted elsewhere in the network. Some sites in which such questions might be a good fit, depending on the circumstances of each concrete case, are Philosophy, Mathematics and Computer Science.

9357 questions
24
votes
2 answers

Is there an AND option on the rules condition in .gitlab-ci.yml?

I want to create some nested conditions: i need this pipeline to work when it is a merge or merge request and with certain name start "feature". So, is there an AND condition in the 'only' option for jobs?
Claudio Torres
  • 355
  • 1
  • 2
  • 6
24
votes
2 answers

AngularJS and PHP backend

Maybe it's not a real question, rather is's a discussion. I decided to learn angular, using a simple task, build a blog system. And i have a few questions. Lest imagine that the php app will have the MVC structure, so i have some questions: Should…
Cawa
  • 1,269
  • 3
  • 25
  • 44
24
votes
2 answers

Using the Logic Monad in Haskell

Recently, I implemented a naïve DPLL Sat Solver in Haskell, adapted from John Harrison's Handbook of Practical Logic and Automated Reasoning. DPLL is a variety of backtrack search, so I want to experiment with using the Logic monad from Oleg…
Matt W-D
  • 1,605
  • 2
  • 19
  • 22
23
votes
7 answers

What are some practical applications of an FPGA?

I'm super excited about my program powering a little seven-segment display, but when I show it off to people not in the field, they always say "well what can you do with it?" I'm never able to give them a concise answer. Can anyone help me out?
Willem Ellis
  • 4,886
  • 7
  • 38
  • 55
23
votes
8 answers

python build a dynamic growing truth table

My question is simple: "how to build a dynamic growing truth table in python in an elegant way?" for n=3 for p in False, True: for q in False, True: for r in False, True: print '|{0} | {1} | {2} |'.format(int(p),int(q),…
evildead
  • 4,607
  • 4
  • 25
  • 49
23
votes
4 answers

What is the type of the __LINE__ macro in C++

What is the type of the __LINE__ macro in C++?
prabhakaran
  • 5,126
  • 17
  • 71
  • 107
23
votes
18 answers

How to create a method to return 1 or 0 without using conditions?

I was asked a question in an interview to return 1 if provided 0 and return 0 if provided 1 without using conditions i.e if, ternary etc Just to give you and idea below code without if's: public int testMethod(int value){ if(value==0) return 1; …
Rafay
  • 603
  • 2
  • 9
  • 24
22
votes
6 answers

Determine if two strings are similar in Javascript?

Let's say I have two strings, is there any way to check if they are at least 90% similar? var string1 = "theBoardmeetstoday,tomorrow51"; var string2 = "Board meets today, tomorrow"; Thanks, Tegan
Tegan Snyder
  • 741
  • 1
  • 9
  • 20
22
votes
8 answers

Mathematical (Arithmetic) representation of XOR

I have spent the last 5 hours searching for an answer. Even though I have found many answers they have not helped in any way. What I am basically looking for is a mathematical, arithmetic only representation of the bitwise XOR operator for any 32bit…
user3170842
  • 231
  • 1
  • 2
  • 3
22
votes
10 answers

How does a programmer think?

This may be a hopelessly vague question. But I am interested to hear whatever logical thought processes people go through when learning a new concept or trying to get their brain around code they might not have ever seen before. Basically, what…
Gordon Potter
  • 5,802
  • 9
  • 42
  • 60
22
votes
6 answers

XOR Objective-c

Is there a way to put a condition that return true only if one of the two component return true? BOOL var1 BOOL var2 something shorter than if((var1 && !var2) || (!var1 && var2)) Thank you
Nicolas Manzini
  • 8,379
  • 6
  • 63
  • 81
21
votes
6 answers

Can !a!=!!b^!!-!a||!+!a|!c return anything other than 1?

I was playing the Javascript game with somebody and we were having fun making ridiculous and absurd expressions to make our inputs get a particular output. This little charming one !a!=!!b^!!-!a||!+!a|!c always seemed to return 1. I tried to reason…
Peter Olson
  • 139,199
  • 49
  • 202
  • 242
21
votes
10 answers

Any way to toggle between two strings using one piece of JavaScript?

I want to do something like if(something.val() == 'string1') { something.val('string2'); } else if(something.val() == 'string2') { something.val('string1') } But in one line of code. I can't quite remember how it's done, but it involves…
Bojangles
  • 99,427
  • 50
  • 170
  • 208
21
votes
6 answers

Is there a short-circuit OR in PHP that returns the left-most value?

In some languages, you can do $a = $b OR $c OR die("no value"); That is, the OR will short-circuit, only evaluating values from left to right until it finds a true value. But in addition, it returns the actual value that was evaluated, as opposed to…
Steve
  • 4,033
  • 5
  • 32
  • 29
20
votes
8 answers

Why do Strings start with a "" in Java?

Possible Duplicate: Why does “abcd”.StartsWith(“”) return true? Whilst debugging through some code I found a particular piece of my validation was using the .startsWith() method on the String class to check if a String started with a blank…
Jimmy
  • 16,123
  • 39
  • 133
  • 213