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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:40:05+00:00 2026-05-26T20:40:05+00:00

I need to define divide so that List [1,2,3,4,5] divides into: a = [1,2,3}

  • 0

I need to define divide so that List [1,2,3,4,5] divides into:

a = [1,2,3}

b = [4,5]

I’m getting an error that says "Arguments are not sufficiently instantiated", and I don’t know enough about the language to figure out what my problem is, or if my design is even right. Any guidance would be appreciated.

So here’s what I have so far:

append([],L2,L2).
append([H|T],L2,[H|L3]) :- append(T,L2,L3).

lengthIs([],N).
lengthIs([H|T],N) :- lengthIs(T,M), N is M+1.

divide([],[],[]).
divide([H|T],L2,L3) :-
   (  lengthIs(L2, M) < lengthIs(L1,N)/2
   -> divide(T, append(L2, H, X), L3)
   ;  divide(T, L2, append(L3,H,Y))
   ).
  • 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-26T20:40:06+00:00Added an answer on May 26, 2026 at 8:40 pm

    Let’s give the predicate a more relational name: list_half_half/3

    list_half_half(Xs, Ys, Zs) :-
       length(Xs, N),
       H is N - N // 2,
       length(Ys, H),
       append(Ys, Zs, Xs).
    

    length/2 and append/3 are predefined in practically all recent Prologs.

    This is GNU Prolog:

    | ?- append(L,_,[a,b,c,d]), list_half_half(L,H1,H2).
    
    H1 = []
    H2 = []
    L = [] ? ;
    
    H1 = [a]
    H2 = []
    L = [a] ? ;
    
    H1 = [a]
    H2 = [b]
    L = [a,b] ? ;
    
    H1 = [a,b]
    H2 = [c]
    L = [a,b,c] ? ;
    
    H1 = [a,b]
    H2 = [c,d]
    L = [a,b,c,d]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to define a Wix file component that may not exist in certain
I need to divide a C string into tokens. I thought that strtok will
I need to define a rake task that can handle any amount of arguments,
I need to define the constant in the module that use the method from
I need to define an appender for log4net in a way that I get
I need to define some constant strings that will be used only by one
hello all, need to define a function that can be divided term by term
I need to handle the ORA-01400 error (cannot insert NULL into (SCHEMA.TABLE_NAME.COLUMN_NAME) ) using
I need to define a class that represents a real-life event -- like a
I need to design a framework that computes the result of a divide-et-conquer algorithm

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.