?
Solved

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

Posted on 2005-03-03
4
Medium Priority
?
358 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
A short article about problems I had with the new location API and permissions in Marshmallow
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Progress
Suggested Courses

770 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