Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2005-03-03
4
Medium Priority
?
364 Views
Last Modified: 2010-05-18
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????
0
Comment
Question by:assaad
  • 2
4 Comments
 
LVL 25

Expert Comment

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

>> IM
0
 

Author Comment

by:assaad
ID: 13451869
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


0
 
LVL 9

Accepted Solution

by:
gabeso earned 1500 total points
ID: 13457019
You would want something like this:

partition( [H | T], [ H | L1 ], L2, L3 ) :- H > 0.
partition( [H | T], L1,[ H |  L2], L3 ) :- H <= 0.
partition( [H | T], L1, L2, [H | L3] ) :- if H is something else ....


0
 

Author Comment

by:assaad
ID: 13462078
did you try this to see if it's working?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
Progress
Loops Section Overview

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question