logic

Continue not going to loop start

I am having a bit of trouble understanding this bug. Here is the code: function filter_optionsfordash(array $data,$dash) { $filtered_options = array(); $len = strlen($dash); foreach ($data as $k => $value) { if (substr($k,0,$len) === $dash) { $option_name = trim(str_replace($dash . '_','',$k)); s...

How do you search for logic (algorithm/problem)?

I often find it is difficult to find something that I know the logic sounds familar but cannot recall the name. Using the existing string based search engine just won't get you good result as most of the time the logic is expressed in a totally different way. I understand the generic problem is a unsolvable AI problem. The question ...

N-Queens Problem..How far can we go?

The N-Queens Problem: This problem states that Given a chess board of size N by N. Find the different permutations in which N queens can be placed on the Board without any one killing each other. My question is: What is the maximum value of N for which a program can calculate the answer in reasonable amount of time? Or what is the lar...

Beginner/Basic Logic Learning

I can usually understand the syntax and learn the syntax quickly for most languages, but what is the best way to learn how the syntax works and the logic behind it, so I can program more efficiently and more logically. Hopefully this question makes sense. Any answers would be much appreciated! ...

Prolog difference routine help!

I need some help with a routine that I am trying to create. I need to make a routine that will look something like this: difference([(a,b),(a,c),(b,c),(d,e)],[(a,_)],X). X = [(b,c),(d,e)]. I really need help on this one.. I have written a method so far that can remove the first occurance that it finds.. how ever I need it to remove...

Prolog wildcards

Hi guys, I was wondering, how would I use the underscore twice but check that both instances of that underscore unify? What I basically need is something that returns true if two elements of the same value in one mapping exist... I.E member((,),[(a,a),(b,a),(c,a)]). If I use a variable does that make them unified? I.E ...

Prolog routing routine

Hi, I am trying to write a routing function but I cannot seem to get the result needed. This is the code so far. Predecessor finds the node that is linked to N and returns it as P. traceroute(_,L) :- member((A,A),L). traceroute(N,L) :- predecessor(N,P), append(N,L,L1), traceroute(P,L1). When I run my traceroute(placeA, Y). it retur...

A simple small shell script to compute averages

Can anyone tell me what I'm doing wrong here? #!/bin/sh if [ $# = 0 ] then echo "Usage: $0 <filename>" exit 1 fi sum=0 count=0 while [ $0 != 0 ] do sum="$sum"+"$2" count="$count"+ 1 done if [ "$count" != 0 ] then avg="$sum"/"$count" printf "Sum= $sum \n Count= $count \n Avg= $avg" exi...

How to Sort Arrays in Dictionary?

I'm currently writing a program in Python to track statistics on video games. An example of the dictionary I'm using to track the scores : ten = 1 sec = 9 fir = 10 thi5 = 6 sec5 = 8 games = { 'adom': [ten+fir+sec+sec5, "Ancient Domain of Mysteries"], 'nethack': [fir+fir+fir+sec+thi5, "Nethack"] } Right now, I'...

PHP - Show results from different queries on one page, either or, not all at the same time

Not sure if that was the best way to phrase what I'm trying to do. Here goes: I want users to be able to show results form my DB based on three different tables, one at a time. I have the queries ready, but only want to show one result on the page at a time, based on what the user clicks. The queries are based on 3 different tables. Th...

Throw a logic error for this function

This the function. I dealt with throwing an out_of_range error and can't think of any logic error for this. Any suggestions? Thank you. int hire(Payroll * p) throw (out_of_range, logic_error){ // error if no holes left if (staffcount == MAX_EMPLOYEES) throw (out_of_range("Hire: Too many employee...

prolog, copying lists.

im attempting to get my arms around some basic prolog but struggling a bit. in specific - im trying to got through a list of items and copy it, item by item into a new list. I can get it to reverse, but im finding it tricker doing it without reversing. Ive been trying the following - copy(L,R) :- accCp(L,R). accCp([],R). accCp([H|T],...

simple logic question comparing variables

If I have variables with numbers how to figure out which are the three with the highest value? ...

Is this valid XML?

I know that syntax is valid, but my question is whether it is logically valid: <parent> <name>John</name> <child>Mary</child> <child>Lucy</child> <child>Hannah</child> </parent> or a proper way to do this is: <parent> <name>John</name> <child> <name>Mary</name> </child> <child> <name>Lu...

Exclusive OR in Scheme

What is the exclusive or functions in scheme? I've tried xor and ^, but both give me an unbound local variable error. Googling found nothing. ...

Higher-order unification

I'm working on a higher-order theorem prover, of which unification seems to be the most difficult subproblem. If Huet's algorithm is still considered state-of-the-art, does anyone have any links to explanations of it that are written to be understood by a programmer rather than a mathematician? Or even any examples of where it works an...

Logic to Implement Parent Child Relationship in efficient manner.

Hi.. Friends, I have a Table where Parent Child Relation ship is stored as: ChildID Name ParentID 1 A1 Null 2 A2 1 3 B1 Null 4 A3 2 5 A4 1 I m Woking on Objective C and I need to Generate a text File in Manner: Name =A1> Name =A2> Name =A3/>...

[PHP]: Logic with date differences

Hi, I'm seeking an elegant solution to change the format of time based on the length of time between now, and a ISO formated date in a DB. I'd like the output to look something like this //less than an hour 'X minutes have gone by' //less than 24 hours 'X hours have gone by' //greater than 24 hours ISO date Here is what I have so fa...

existential qualifier in prolog, using setof / bagof

Hi, I had a quick question re. existential qualifier using setof in prolog (i.e. ^). using SICStus it seems that (despite what a number of websites claim), S does indeed appear to be quantified in the code below (using the bog standard, mother of / child of facts, which i havent included here): child(M,F,C) :- setof(X,(mother(S,X)),C)...

Becoming operational in Prolog ASAP

Hi all, May be this sort of question has been asked many times( as I see the list when I move the cursor to this messagebox), But my company has a project running in Prolog and I want to clarify few things about how to go about learning it. I know Prolog is different. It should not be learnt just like any other language. Having said t...