Link to home
Start Free TrialLog in
Avatar of assaad
assaad

asked on

prolog splitting a list into 3 other lists and each have different type like + and -

Hi, i am trying to split a list into 3 lists: the first one consists of only positive numbers and the second one of negative numbers and the third one of atoms only for example:

?- partition([5,1,anything,-2,-3,10], L1, L2, L3).

L1= [5,1,10]
L2=[-2,-3]
L3=[anything]

any ideas????
Avatar of InteractiveMind
InteractiveMind
Flag of United Kingdom of Great Britain and Northern Ireland image

Could you elaborate.. some more examples?
What language are you using? Where is this data stored? In a file??

>> IM
Avatar of assaad
assaad

ASKER

this is prolog language.

?- partition([5,1,anything,-2,-3,10], L1, L2, L3). --> this is the question that the user should ask

the program should give him the following answer:

L1= [5,1,10]
L2=[-2,-3]
L3=[anything]

another example:
?- partition([5,1,anything,-2,whatever,10], L1, L2, L3).

L1= [5,1,10]
L2=[-2]
L3=[anything,whatever]

by the way nothing should be stored in a file. it's only a simple interaction with the user.
the user will give the words including positive and negative numbers and we have to differenciate between them and put them in lists L1, L2, L3


ASKER CERTIFIED SOLUTION
Avatar of gabeso
gabeso
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of assaad

ASKER

did you try this to see if it's working?