logic

C# logic order and compiler behavior

In C#, (and feel free to answer for other languages), what order does the runtime evaluate a logic statement? Example: DataTable myDt = new DataTable(); if (myDt != null && myDt.Rows.Count > 0) { //do some stuff with myDt } Which statement does the runtime evaluate first - myDt != null or: myDt.Rows.Count > 0 ? Is there a...

Most succinct way to determine if a variable equals a value from a 'list' of values

If I have a variable in C# that needs to be checked to determine if it is equal to one of a set of variables, what is the best way to do this? I'm not looking for a solution that stores the set in an array. I'm more curious to see if there is a solution that uses boolean logic in some way to get the answer. I know I could do something ...

Teaching someone to program

What is the best way to teach someone how to program, the language doesn't matter. It's more of a case of how to make them think logical and clearly on how to over come a problem. Or is this something that comes naturally to most developers and can't be taught. Any online resources or book recommendations appreciated. ...

Efficient synthesis of a 4-to-1 function in Verilog

I need to implement a 4-to-1 function in Veriog. The input is 4 bits, a number from 0-15. The output is a single bit, 0 or 1. Each input gives a different output and the mapping from inputs to outputs is known, but the inputs and outputs themselves are not. I want vcs to successfully optimizing the code and also have it be as short/n...

Testing ladder logic

We all know the various ways of testing OO systems. However, it looks like I'll be going to do a project where I'll be dealing with PLC ladder logic (don't ask :/), and I was wondering if there's a good way of testing the validity of the system. The only way I see so far is simply constructing a huge table with all known states of the s...

What would be the best algorithm to find an ID that is not used from a table that has the capacity to hold a million rows.

To elaborate .. a) A table (BIGTABLE) has a capacity to hold a million rows with a primary Key as the ID. (random and unique) b) What algorithm can be used to arrive at an ID that has not been used so far. This number will be used to insert another row into table BIGTABLE. Updated the question with more details.. C) This table already h...

How to logically organize recurring tasks?

What's the best way to create recurring tasks? Should I create some special syntax and parse it, kind of similar to Cronjobs on Linux or should I much rather just use a cronjob that runs every hour to create more of those recurring tasks with no end? Keep in mind, that you can have endless recurring tasks and tasks with an enddate. ...

Should LOGIC-techniques be blended into Mainstream Programming?

I refer specifically to predicate logic, somewhat as implemented in PROLOG, but less strictly bound to first-order logic. PROLOG-techniques offers powerful solutions towards data-analysis, data-mining, problem-solving, etc., but PROLOG's reputation as an exotic toy for AI, expert-systems and research seems to prevent the application of ...

Why does "abcd".StartsWith("") return true?

Title is the entire question. Can someone give me a reason why this happens? ...

Awk scripting help - Logic Issue

I'm currently writing a simple .sh script to parse an Exim log file for strings matching " o' ". Currently, when viewing output.txt, all that is there is a 0 printed on every line(606 lines). I'm guessing my logic is wrong, as awk does not throw any errors. Here is my code(updated for concatenation and counter issues). Edit: I've adopte...

State and time transending logic and program flow?

Wondering if it would ever be useful to index every possible state of an application using some reference keys... Meaning, say we have a program that starts, has only so many possible outcomes, say 8. but if each outcome is attained through stepping through many more logic states, and in between each branch is considered to be a state ...

Select Poorly Used Start and End Dates From Facility Table

I'm using DB2, although a solution using any flavor of SQL would likely be easy enough for me to convert. I didn't design this database, or the application that uses the database. I haven't the power to change this application, how it works, or the data. Because it defies what I consider to be conventional use of a start and an end da...

Looking for simple rules-engine library in .NET

Hi, Does anyone know of a good .NET library rules library (ideally open-source)? I need something that can do nested logic expressions, e.g., (A AND B) AND (B OR C OR D). I need to do comparisons of object properties, e.g., A.P1 AND B.P1. (Ideally, I could compare any property -- A.P1 AND B.P2). It should store the rules in a data...

Struts logic tag problem

i know this doesnt work but i dont know why, also how can i make it work? <% int result = referer.indexOf("smlMoverDetail.do"); %> <% if (result == -1){%> <%out.print("checking");%> <bean:define id="JOININGDATE" name="smlMoverDetailForm" property="empFDJoiningDate" type="java.lang.String" toScope="session"/> <%}%> Please pleas...

Struts Logic Problem

Why doesn't the code below work? The idea is that the page checks to see if the dropdown variable has changes since you last refreshed the page. <logic:equal name="Result" value = "-1"> <bean:define id="JOININGDATE" name="smlMoverDetailForm" property="empFDJoiningDate" type="java.lang.String" toScope = "session" /> </logic...

What problems are best solved with Logic Programming?

By Logic Programming I mean the a sub-paradigm of declarative programming languages. Don't confuse this question with "What problems can you solve with if-then-else?" A language like Prolog is very fascinating, and it's worth learning for the sake of learning, but I have to wonder what class of real-world problems is best expressed and...

Correct order for control structure logic (true/false, false/true)?

I am new to programming, and am wondering if there is a correct way to order your control structure logic. It seems more natural to check for the most likely case first, but I have the feeling that some control structures won't work unless they check everything that's false to arrive at something that's true (logical deduction?) It wou...

How do I convert a number to two's complement in verilog?

I am trying to design a 4-bit adder subtracter in verilog. This is only the second thing I have ever written in verilog, and I don't know all the correct syntax yet. This is the module I have so far: module Question3(carryin, X, Y, Z, S, carryout, overflow); parameter n = 4; input carryin, Z; input [n-1:0]X, Y; output re...

Why C++ cannot be parsed with a LR(1) parser?

I were reading about parsers and parser generators when I hit upon this statement in wikipedia's LR parsing -page: "Many programming languages can be parsed using some variation of an LR parser. One notable exception is C++." Why is it so? What particular property in C++ causes it to be impossible to parse with LR parsers? I first tri...

Boolean logic rule evaluator

I have essentially a survey that is shown, and people answer questions a lot like a test, and there are different paths, it is pretty easy so far, but i wanted to make it more dynamic, so that i can have a generic rule that is for the test with all the paths, to make the evaluator easier to work with currently i just allow AND's, and ea...