logic

Returning a value after a recursion in Prolog

Hello, I decided to study some logic programming and I stumbled across a problem. It is programmed in SWI Prolog. test(A, B, N):- nonvar(B), B = final, true. test(A, B, N):- N > 2, test(A, final, N). test(A, B, N):- N1 is N + 1, test(N1, B, N1). It is just a sample with no real use except it is driving me crazy. The problem ...

Two stars in a Prolog list

Hi, what are the two stars in a list? [53, 5, 1, 53, 97, 115, 53, 50, 52, 121, 55, 56, 55, 97, 4, 1, 98, **] I tried searching but no success. Thanks, Jan ...

Logic for number of person viewed

I want to show the number of viewer for a particular Article. How i will do it in my program? Any strategy, someone can suggest ... ...

How would I do an OR statement with a Switch case? (PHP)

How would I go about converting this if statement: for($i = 1; $i < $argc; $i++) { ... if(in_array($argv[$i], array('-V', '--version'))) { $displayVersion = TRUE; } ... } Into a switch case without needing to write two switch statements? ...

Tool to draw logic gates from text

Is there a tool to draw out logic gates / the circuit diagram from a textual description of those gates (such as HDL)? Thank you. ...

Why does IQueryable.All() return true on an empty collection?

So I ran into a situation today where some production code was failing precisely because a method performed exactly as documented in MSDN. Shame on me for not reading the documentation. However, I'm still scratching my head as to why it behaves this way, even if "by design", since this behavior is exactly opposite what I would have exp...

Efficient Algorithm for comparing only the lists that have been updated

Hi everyone, Even describing this problem is hard, But I'll give it a go. I've been struggling with this for a few days and decided to ask here. OK, so I'm trying to model "concepts", or "things" as I call them. Just concepts in general. It's to do with processing logic. So, each "thing" is defined by it's relationship to other things...

VB.NET Select Case Compiler Optimizations?

Does the VB.NET 2008 compiler selectively optimize Select Case Statements? For example, a Select Case Statement with a sufficient quantity of integer cases could be organized as a binary search. I ask this because I am curious whether or not I should opt for a Select Case in place of If Statements with multiple Else If's where integer...

Recognizing Spaces in text [C]

I'm writing a program that deciphers sentences, syllables, and words given in a basic text file. The program cycles through the file character by character. It first looks if it is some kind of end-of-sentence marker, like ! ? : ; or . Then if the character is not a space or tab, it assumes it is a character. Finally, it identifies tha...

Why Does this Loop Return 1 when using && instead of 'and' ???

Riddle me this... in the while($row = mysql_fetch_assoc($result) and $runningOK) loop, if the PHP && operator is used in place of the and the mysql_fetch_assoc fails terrible and returns just the number 1 when running. I've tried mysql_fetch_array() and in place and I still have the 1 problem. It is when, and only when, I replace the && ...

being able to solve google code jam problem sets

This is not a homework question, but rather my intention to know if this is what it takes to learn programming. I keep loggin into TopCoder not to actually participate but to get the basic understand of how the problems are solved. But to my knowledge I don't understand what the problem is and how to translate the problem into an algorit...

Conditional logic on SQL aliases

I've got an SQL query that pieces together historic price information. It's not particularly clean and could probably be optimized a great deal. One reason for this is that I use a subquery to grab the 'previous' price value via a subquery and assign it to the alias 'last_value'. Ideally, I'd like to be able to use this alias in the quer...

In Java, what are the boolean "order of operations"?

Let's take a simple example of an object "Cat". I want to be sure the "not null" cat is either orange or grey. if(cat != null && cat.getColor() == "orange" || cat.getColor() == "grey") { //do stuff } I believe AND comes first, then the OR. I'm kinda fuzzy though, so here are my questions: 1) Can someone walk me through this state...

jQuery OR Selector?

I am wondering if there is a way to have "OR" logic in jQuery selectors. For example, I know an element is either a descendant of an element with class classA or classB, and I want to do something like elem.parents('.classA or .classB'). Does jQuery provide such functionality? ...

What is the best way to think about the order of programming?

Possible Duplicate: How to Think in OO I am sort of new to programming. I am working with Objective-C and iPhone app Dev. I am having some trouble wrapping my mind around the OOP mindset. Does anyone have any tips or tricks to think or visualize the programming process before you sit down and start it? ...

Logic variables support for .NET

I am looking for a library/assembly that allows me to work with logical variables in F#. I want to avoid reinventing the wheel in implementing the required union-find datastructure, unification code and so on. I have found Prolog.NET, but the manual is a bit sparse. I do not want a full-fledged Prolog implementation, but only its treatm...

ruleML - benefits/bad points?

Hi guys, I'm currently looking into ruleML and I was wondering if maybe someone could give me a short list of advantages and disadvantages about it? Thanks ...

First Order Logic Engine

I'd like to create an application that can do simple reasoning using first order logic. Can anyone recommend an "engine" that can accept an arbitrary number of FOL expressions, and allow querying of those expressions (preferably accessible via Python)? ...

Why is ''>0 True in Python?

In Python 2.6.4: >> ''>0 True Why is that? ...

How can I simplfy this logic

I'm having trouble simplifying this conditional statements logic. Is there a more effervescent way of writing this? if(($x || $a) && ($x || $y)) { if($x){ return true; } } return false; ...