Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Prolog Help please

  • 16-05-2009 03:59PM
    #1
    Closed Accounts Posts: 636 ✭✭✭


    Ok so I am doing a prolog course at the moment and need to know how to do something

    Basically I have to write a predicate split(+List,-NumberList,-Termlist). It really simple but I can't seem to do it!

    It has to split a list of terms and numbers into two seperate lists.
    so split([1,a,3,c,d,5],A,B). should give

    A=[5,3,1]
    B=[d,c,a].

    I have
    split([],A,B).
    split([S|F],List1,List2):-
    (number(S), append(,List1,Ans), split(F,Ans,List2));append(,List2,Bans),split(F,List1.Bans).


    I know I probably have some logic error but that to me jsut makes sense. Also I am not sure what the base case should be. should it be split([],[],[]).


Comments

  • Registered Users, Registered Users 2 Posts: 1,389 ✭✭✭cianclarke


    Tried your other Erasmus buddy? He's pretty 1337th with prolog as I recall!


  • Closed Accounts Posts: 636 ✭✭✭NADA


    Yeah. In his words. I hate prolog eugh go away!!!


  • Closed Accounts Posts: 636 ✭✭✭NADA


    Never mind guys. I just figured it out. I did this in the end.

    reverse(L,R):- rev(L,[],R).

    rev([H|T],Acc,R):-
    rev(T,[H|Acc],R).
    rev([],Acc,Acc).

    trenne(List,NList,TList):- seperate(List,[],[],NList,TList).

    seperate([H|T],Acc1,Acc2,NList,TList):-
    ((number(H),seperate(T,[H|Acc1],Acc2,NList,TList)); (seperate(T,Acc1,[H|Acc2],NList,TList))),!.

    seperate([],Acc1,Acc2,Acc1,Acc2).




    God I hate that language!


  • Registered Users, Registered Users 2 Posts: 5,753 ✭✭✭veryangryman


    Its not the worst once you get into it.

    That said, its quite useless. Not touched it since college


  • Registered Users, Registered Users 2 Posts: 5,618 ✭✭✭Civilian_Target


    lol! I pretty much remember doing exactly this exercise at Queens...

    Believe it or not, after Queens I wrote quite a lot of Prolog in the end, for implementing Robot AI, and ended up really liking it. Quite a neat little language!


  • Advertisement
Advertisement