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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:29:24+00:00 2026-06-16T10:29:24+00:00

I need to solve a logic problem using Prolog. I have just one problem:

  • 0

I need to solve a logic problem using Prolog. I have just one problem:

In the answer, the name of the attributes doesn’t appear. My code to generate the attributes is:

gera(p(Prof, AlunosProf, Tema, AlunosTema)) :-
       member(Prof, [palmira, roberta, selma]),
       member(AlunosProf, [40, 45, 50]),
       member(Tema, [transito, culinaria, reciclagem]);
       member(AlunosTema, [40, 45, 50]).

But after doing the query it looks like this:

S = [p(palmira, _G2046, transito, 45),
    p(roberta, 50, reciclagem, _G2053),
    p(selma, _G2056, culinaria, _G2058)]

Where is “_G*something” I want to appear the name of the attribute (in this case only the number of students).

Edit:

Adding the entire code:

gera(p(Prof, AlunosProf, Tema, AlunosTema)) :-
       member(Prof, [palmira, roberta, selma]),
       member(AlunosProf, [40, 45, 50]),
       member(Tema, [transito, culinaria, reciclagem]),
       member(AlunosTema, [40, 45, 50]).


dif(p(P1, Q1, T1, Q12), p(P2, Q2, T2, Q22)) :-
    P1 \= P2, Q1 \= Q2, Q12 \= Q22, T1 \= T2.

tudoDif(P1, P2, P3) :-
    dif(P1, P2), dif(P1, P3), dif(P2, P3).

gera_ef(P1, P2, P3) :-
    P1 = p(palmira, _, _, _),
    P2 = p(roberta, _, _, _),
    P3 = p(selma, _, _, _).
    gera(P1), gera(P2), gera(P3),
    tudoDif(P1,P2,P3).

solucao(S) :-
        S = [P1, P2, P3],
    gera_ef(P1, P2, P3),
    member(p(palmira, X, transito, 45), S),
        member(p(selma, Z, culinaria, W), S),
        member(p(roberta, 50, reciclagem, R), S), 
    !.
  • 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-16T10:29:26+00:00Added an answer on June 16, 2026 at 10:29 am

    You are relaxing the constraint of you statement when you use ; instead of ,.
    When you use ; you’re stating that, either what came before or what is coming now is acceptable.

    Since when you start saying “what is coming now” you only define the values of AlunosTema, the other values will receive any value, represented by what you saw — “_G233…”.

    Try the following:

    gera(p(Prof, AlunosProf, Tema, AlunosTema)) :-
           member(Prof, [palmira, roberta, selma]),
           member(AlunosProf, [40, 45, 50]),
           member(Tema, [transito, culinaria, reciclagem]),
           member(AlunosTema, [40, 45, 50]).
    

    Edit:

    Considering the whole code you posted, you may change some couple of things:

    ...
    
    gera_ef(P1, P2, P3) :-
        P1 = p(palmira, _, _, _),
        P2 = p(roberta, _, _, _),
        P3 = p(selma, _, _, _),
        gera(P1),
        gera(P2),
        gera(P3),
        tudoDif(P1,P2,P3).
    
    solucao(S) :-
        S = [P1, P2, P3],
        gera_ef(P1, P2, P3),
        member(p(palmira, _, transito, 45), S),
        member(p(selma, _, culinaria, _), S),
        member(p(roberta, 50, reciclagem, _), S),
        !.
    

    The problem here is that you had a . instead of a , in:

    gera_ef(P1, P2, P3) :-
        ...,
        P3 = p(selma, _, _, _).
        ...
    

    that wouldn’t allow the rest of the code to execute.

    Another change was the replacement of the unbounded variables in solucao with _; note X, W, R have been removed.

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

Sidebar

Related Questions

I need to solve a problem within job booking software and am hoping to
I need to solve a job affectation problem and I would like to find
I need to solve a locking problem for this scenario: A multi CPU system.
I need to solve such a problem. There is a base class and two
I have a few weird issues I need to solve. First, let me show
I don't like JSF but I need to solve this problem with it, I
I rarely use SQL and have a unique issue I need to solve. I
I'm doing video processing tasks and one of the problems I need to solve
i'm trying to solve a seemingly simple problem, but just can't quite get my
I'm using hsql and another 3rd party library. To solve a certain problem I

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.