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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:24:05+00:00 2026-05-29T09:24:05+00:00

So i have an assignment in which i have to make a guessing game

  • 0

So i have an assignment in which i have to make a guessing game (bulls and cows).
Firstly i made i little program where you enter two numbers and it checks
if they have the same length and then if they are equal.
*The numbers have have to be in lists, in order to be able to give in every guess the number of bulls and cows (see the rules of the game).

    equal([],[]).
    equal([Ha|Ta],[Hb|Tb]) :-
        Ha = Hb, equal(Ta,Tb).
    
    check_length(List1,List2):-
            same_length(List1,List2),writeln('The Lists have the same length!').
    
    check_equality(List1,List2):-
            equal(List1,List2),writeln('The Lists are equal!').
start:-
    write('give 1st list:'), read(X),atom_chars(X, List1),
    write('give 2nd list:'), read(Y),atom_chars(Y, List2),
    check_length(List1,List2),
    check_equality(List1,List2).

So far so good. It works fine. Then i went on to the next step and altered it, so it generates a list with 4 random integers and then it waits for the user to make a guess and compares the two lists like before. *Obviously i print the generated number to the screen in order to know if the program works ok.

start:-
    A is random(9),
    B is random(9),
    C is random(9),
    D is random(9),
    List2=[A,B,C,D],
    write('Generated number:'),writeln(List2),
    write('Make a guess:'), read(Guess),atom_chars(Guess, List1),
    nl,
    check_length(List1,List2),
    check_equality(List1,List2).

The problem is that this time even if you type the right number, the program does figure out if the lists (numbers) have the same length but fails in equality check.
What am i doing wrong?

Thanks in advance.

  • 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-29T09:24:06+00:00Added an answer on May 29, 2026 at 9:24 am

    Here is the trace from a run:

    [trace] 42 ?- start.
       Call: (6) start ? creep
    ^  Call: (7) _G537 is random(9) ? creep
    ^  Exit: (7) 6 is random(9) ? creep
    ^  Call: (7) _G539 is random(9) ? creep
    ^  Exit: (7) 6 is random(9) ? creep
    ^  Call: (7) _G541 is random(9) ? creep
    ^  Exit: (7) 1 is random(9) ? creep
    ^  Call: (7) _G543 is random(9) ? creep
    ^  Exit: (7) 4 is random(9) ? creep
       Call: (7) _G555=[6, 6, 1, 4] ? creep
       Exit: (7) [6, 6, 1, 4]=[6, 6, 1, 4] ? creep
       Call: (7) write('Generated number:') ? creep
    Generated number:
       Exit: (7) write('Generated number:') ? creep
       Call: (7) writeln([6, 6, 1, 4]) ? creep
    [6,6,1,4]
       Exit: (7) writeln([6, 6, 1, 4]) ? creep
       Call: (7) write('Make a guess:') ? creep
    Make a guess:
       Exit: (7) write('Make a guess:') ? creep
       Call: (7) read(_G555) ? creep    
    |    6614.
       Exit: (7) read(6614) ? creep
       Call: (7) atom_chars(6614, _G556) ? creep
       Exit: (7) atom_chars(6614, ['6', '6', '1', '4']) ? creep
       Call: (7) nl ? creep
       Exit: (7) nl ? creep
       Call: (7) check_length(['6', '6', '1', '4'], [6, 6, 1, 4]) ? creep
       Call: (8) length(['6', '6', '1', '4'], _G568) ? creep
       Exit: (8) length(['6', '6', '1', '4'], 4) ? creep
       Call: (8) length([6, 6, 1, 4], 4) ? creep
       Exit: (8) length([6, 6, 1, 4], 4) ? creep
       Call: (8) writeln('The Lists have the same length!') ? creep
    The Lists have the same length!
       Exit: (8) writeln('The Lists have the same length!') ? creep
       Exit: (7) check_length(['6', '6', '1', '4'], [6, 6, 1, 4]) ? creep
       Call: (7) check_equality(['6', '6', '1', '4'], [6, 6, 1, 4]) ? creep
       Call: (8) equal(['6', '6', '1', '4'], [6, 6, 1, 4]) ? creep
       Call: (9) '6'=6 ? creep
       Fail: (9) '6'=6 ? creep
       Fail: (8) equal(['6', '6', '1', '4'], [6, 6, 1, 4]) ? creep
       Fail: (7) check_equality(['6', '6', '1', '4'], [6, 6, 1, 4]) ? creep
       Fail: (6) start ? creep
    false.
    

    the important part is this:

       Call: (9) '6'=6 ? creep
       Fail: (9) '6'=6 ? creep
    

    so the problem is that the char ‘6’ is not equal with the number 6
    another issue is that zeroes in the beginning will be deleted

    23 ?- atom_chars(0042,L).
    L = ['4', '2'].
    

    so I would suggest to get rid of atom_chars/2 and do something else; read the four numbers one by one or split the number manually

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

Sidebar

Related Questions

We have as an assignment to make a compiler. We have already made the
For a school assignment we have to make a client server chat program in
I have a homework assignment to make a simple program in assembly language for
So I am being taught assembly and we have an assignment which is to
Are there exceptions for types which can't have thier assignment operator overloaded? Specifically, I'm
I have my first professional assignment of making a website in which a photographer's
I have an object which has both a copy constructor and assignment operator defined.
For a school assignment, we have to make a Usecase diagram. But the documentation
I have a homework assignment which asks to have the user input a date
i have a unix c programming assignment in which i do some advanced C

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.