Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5962619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:07:51+00:00 2026-05-22T19:07:51+00:00

I have a prolog homework, which should work like this: singles([1,2,3,2,2,4,1], [3,4]). true Now

  • 0

I have a prolog homework, which should work like this:

  singles([1,2,3,2,2,4,1], [3,4]).
  true

Now I’ve figured out I should test if one element is single in the list then put all the single element together..then I wrote down:

singles(L,SL):-findall(X,isSingle(X,L),SL).
isSingle(X,L):-member(X,L),append(Y,[X|Z],L),not(member(X,L1)),append(Y,Z,L1).

in the isSingle function the X should be in List L but not in the new List L1 without X, like 1 is in [2,1,3] but not in [2,3], but sadly the whole thing doesn’t work like I thought 🙁

I think the problem is in the isSingle part, can anyone help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:07:52+00:00Added an answer on May 22, 2026 at 7:07 pm

    Switch the order of not(member(X,L1)) and append(Y,Z,L1) and your code works. I’m no Prolog expert, so I’m not entirely sure about this, but, going through the trace, it seems to have to do with the subtleties of using not. You’re forcing the evaluation of member on L1 before it has been unified in append(Y,Z,L1) bit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Prolog code: pick_number_simple([],[]). pick_number_simple([H|T],[H|T2]):- number(H), pick_number_simple(T,T2). pick_number_simple([H|T],T2):- not(number(H)), pick_number_simple(T,T2). which gets
i have a prolog list like this: [p(X,Y,Z),r(H,G,K)] and i want convert it into
I have Prolog statements like this verb('part_of-8'). noun('doctor_investigation_system-2'). noun('dis-4'). berelation('be-6'). verb('be-6'). noun('hospital_information_system-11'). noun('his-13'). rel('part_of-8',
Okay, so I have another question on a prolog homework problem I am struggling
I have some prolog. The lessThanTen and example predicates work as expected however the
I have the following Prolog definite clause grammar: s-->[a],s,[b]. s-->[]. This will result in
I have been progressing through Learn Prolog Now! as self-study and am now learning
I have this program in Prolog, it removes elements at each nth element from
What does .. mean in Prolog? I have this code: Goal=.. [GoalPredicate|Pos] and I
hi everyone I'm here again, this week I got this Homework: I should find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.