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

  • Home
  • SEARCH
  • 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 8754925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:44:23+00:00 2026-06-13T13:44:23+00:00

I just learned prolog for a week and I have to write a prolog

  • 0

I just learned prolog for a week and I have to write a prolog program that counts the number of times an element appearing in a list L at even positions.

I have try to figure out the problem for the from am 12:00 to now (am 4:00 last 16 hours) and fail.

1.What I have tried until now is like

count(_,[],0).
count(E,[E|L],C):-!,count(E,L,C1),C is C1+1.
count(E,[A|L],C):-atom(A),count(E,L,C),!.
count(E,[A|L],C):-count(E,A,C1),count(E,L,C2),C is C1+C2.

It just can count the occurence of the whole list within the element is a list.

2.The second is takeoutsecond occurence element in list

What I have tried until now is like but fail

takeout(A,[A|B],B). 
takeout(A,[B|C],[B|D]) :- takeout(A,C,D). 
takeoutSecond(A,[B|C],[B|D]):- takeoutSecond(A,C,D). 
takeoutSecond(A,[A|B],[A|C]):- takeout(A,B,C). 

3.Can you give me some hint if takeoutsecondlast without reverse? I will appreciate it!

Can you give me some hint, I do my all effort on it.

I will reply not now because I stay up late, and I apology for it.
Thank for reading my question.

  • 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-06-13T13:44:24+00:00Added an answer on June 13, 2026 at 1:44 pm

    you miss a very simple use of Prolog pattern matching: namely, to match the second element just ignore the first

    match_second(E, [_,E|Rest], Rest).
    

    You can use that as ‘building block’ for your assignment, but it’s so simple that really you’ll be better to integrate it in your efforts. Use that pattern in the head of your predicates.

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

Sidebar

Related Questions

I just learned (the hard way) that Java Component s can only have one
I just learned that OCAML have to have a . postfix for doing float
I just learned that an object can have only one ID, so I'm not
I just learned how to program in C++ this last week, and I wrote
I just learned about ngrep , a cool program that lets you easily sniff
I have just learned Java in my college. However, in that I can just
I'm doing a javascript assignment and have just learned that I can do it
Just learned Python 3 in 7 days, and I have the feeling that there's
I just learned the hard way that IntPtr.Zero cannot be compared to default(IntPtr). Can
I just learned about ThreadLocal this morning. I read that it should always be

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.