Question for anyone who has programmed with "prolog" before.

Recommended Videos
Jan 27, 2011
3,737
0
0
Ok, so I'm doing an assignment for school, using prolog.

We're supposed to check if a user-inputted list is even or odd.

So (being more of a Java guy), I thought of using a counter variable (starts at 0, goes up as the program works through the elements of the list), then taking mod 2 of it to see if it's even or odd.

But the problem is that prolog doesn't seem to be capable of storing a number value in a variable, then referring to it later.

Does anyone know how to do that? Or if I'm totally on the wrong track, tell me so. Because I've gone through my book, my notes, the lecture notes and a few online sites, and I still don't know how this works...


--
Captcha: Walk!" inchsta .......Wait, I'm supposed to walk an inch at a time? Silly captcha!
 

Aitur

New member
Jan 1, 2011
56
0
0
I've never used prolog and I was originally suggest using letters to count the list instead, so for each list element you append "a" to the x variable, so a list with ten items results in "x = aaaaaaaaaa", then you just need to get the len of x.

However, this might be more useful - even lists [http://www.anselm.edu/homepage/mmalita/culpro/even0.html], from this site [http://www.anselm.edu/homepage/mmalita/culpro/index.html]

But like I said, I've never used prolog so I could be talking complete crap here, if I am I'll offer apologies and shuffle off back to my corner.
Also my captcha is +.0973 nedcmp, that doesn't happen to be a prolog command is it? Maybe captcha knows something we don't.
 

Aedes

New member
Sep 11, 2009
566
0
0
Eh... I was going to try to help you out but seems like the guy above already gave a link to the solution...

What I can tell you, however, is that Prolog is quite different from the usual programming languages we're used to.
If you can manage to understand how to use lists (those dreaded [head|tail] ) and the command 'append', you should be able to do most things on Prolog.