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 8877467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:28:31+00:00 2026-06-14T19:28:31+00:00

Please help me! I do not understand SWI-Prolog From the list L1 to list

  • 0

Please help me!
I do not understand SWI-Prolog

From the list L1 to list L2, another element which is equal to the arithmetic average of the next three items in the list L1. If the number of L1 elements are not divisible by 3, then the last item in the list L2 is obtained by dividing by 3 the sum of one or two recent items list L1. List L1 is introduced for prompt screen. As a result, the program should output input L1 and L2 resulting lists.

List items are available under request.

  • 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-14T19:28:33+00:00Added an answer on June 14, 2026 at 7:28 pm

    This question translates to Prolog almost word-for-word.

    First, add the base case, saying that an empty list translates to an empty list:

    by_three([], []).
    

    Now add the main rule for grabbing the initial items, H1, H2, and H3, in groups of three, and averaging them:

    by_three([H1,H2,H3|T],[A|RT]) :- A is (H1+H2+H3) / 3, by_three(T, RT).
    

    Note the recursive invocation here: the tail T of the original list is converted to RT in the call of by_three/2 at the end of the rule.

    Finally, add two more cases for one-element list and for two-element list:

    by_three([H],[A]) :- A is H / 3.
    by_three([H1,H2],[A]) :- A is (H1+H2) / 3.
    

    That’s it, you are done!

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

Sidebar

Related Questions

the following code is not behaving like I would expect. Please help me understand
I could not understand how the below program code outputs that value.Please help me
please help not able to understand this concept. Thanks
Could you please help me to understand the difference from a private method and
Please help with my script is not working. @echo off echo Printing repeated character
Please help me with my understanding. Also I am not talking about SSL or
Can anyone please help me with this...I'm not very good with regular expressions and
can you please help me with this issue the String class does not have
I am wondering why this is not working please help me. Here is my
Don't know why but font is not displaying.Please help. CSS(in css folder): style.css: @font-face

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.