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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:32:24+00:00 2026-05-28T01:32:24+00:00

I am new to Prolog and I have some probably simple issue with a

  • 0

I am new to Prolog and I have some probably simple issue with a piece of code. This is a real world problem that arose last Friday and believe me this is not a CS Homework.

We want to print business cards and these can only be printed in blocks of 900 cards (100 sheets with 9 cards per sheet). The cards for anybody should not be distributed over several blocks. People ordered different amount of cards, E.G:

% "braucht" is german and means "needs"
braucht(anton,400).
braucht(berta,200).
braucht(claudia,400).
braucht(dorothee,100).
braucht(edgar,200).
braucht(frank,400).
braucht(georg,100).

I put together the following definition to find an appropriate block of 900 business cards:

block(0,[]).
block(N,[H|T]) :-
    braucht(H,Nh),
%   \+(member(H,T)),
    D is N - Nh,
    D >= 0,
    block(D,T).

This produces a nice list of blocks of people whose cards fit together on a 900 cards block. But it stops working if I activate the commented line “\+member….” and just gives me a “false”. But I need to assure that nobody is getting more than once on that block. What am I doing wrong here?

  • 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-28T01:32:24+00:00Added an answer on May 28, 2026 at 1:32 am

    It seems that what you want to achieve is to set a constraint that H does not appear in the tail T of the list. However, T is still unbound when you call member/2, so that member(H, T) will succeed and hence \+ member(H,T) will fail.

    If you don’t want to use Constraint Programming, but use pure Prolog instead, you should use the check in the other direction and check whether H is already present in the list of people that has been aggregated up to that point. Something like:

    block(0, List, List).
    block(N, Rest, List) :-
      braucht(H, Nh),
      \+(memberchk(H, Rest)), % will fail when H is already in Rest
      D is N-Nh,
      D >= 0,
      block(D, [H|Rest], List).
    

    The predicate block/3 can be called from a predicate block/2:

    block(N, List) :-
      block(N, [], List).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NEW EDIT: I have narrowed my problem to this - i have a view
I am new to prolog and i want to solve this problem. Suppose I
I am new in Prolog and I am stucked in a problem. I have
I'm building some relatively simple functions in PROLOG that take one input and one
I am new to Prolog and I'm trying to to create function that will
New day, new problem :-) Code: Client Side: void abw_Closed(object sender, EventArgs e) {
I am new to Prolog. I need to write an integer adder that will
I'm new to prolog and I just can't figure this out. I'm trying to
I am new to Prolog and I have so far learned how to define
I'm trying to understand lists in prolog when I stumbpled over this problem: there's

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.