Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Prolog Help please

  • 16-05-2009 2: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,659 ✭✭✭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