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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:57:37+00:00 2026-05-15T03:57:37+00:00

I am new to Prolog. I need to write an integer adder that will

  • 0

I am new to Prolog. I need to write an integer adder that will add numbers between 0-9 to other numbers 0-9 and produce a solution 0-18. This is what I want to do:

% pseudo code
add(in1, in2, out) :-
    in1 < 10,
    in2 < 10,
    out < 18.

I would like to be able to call it like this:

To check if it is a valid addition:

?- add(1,2,3).
true.
?- add(1,2,4).
false.

With one missing variable:

?- add(X,2,3).
X = 1.
?- add(1,4,X).
X = 5.

With multiple missing variables:

?- add(X,Y,Z).
% Some output that would make sense.  Some examples could be:
X=1, Y=1, Z=2 ;
X=2, Y=1, Z=3 ......

I realize that this is probably a pretty simplistic question and it is probably very straightforward. However, according to the Prolog tutorial I am using:

“Unlike unification Arithmetic Comparison Operators operators cannot be used to give values to a variable. The can only be evaluated when every term on each side have been instantiated.”

  • 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-15T03:57:38+00:00Added an answer on May 15, 2026 at 3:57 am

    Solution:

    lessThanTen(9).
    lessThanTen(8).
    lessThanTen(7).
    lessThanTen(6).
    lessThanTen(5).
    lessThanTen(4).
    lessThanTen(3).
    lessThanTen(2).
    lessThanTen(1).
    lessThanTen(0).
    
    addSimple(Add1,Add2,Sol) :-
        lessThanTen(Add1),
        lessThanTen(Add2),
        Sol is Add1+Add2.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Prolog and I'm trying to to create function that will
I am new in Prolog and I was just thinking that why this rule
I'm new to prolog and I just can't figure this out. I'm trying to
I'm trying to write a predicate that divides a list into N parts. This
I am new to prolog. I need to convert the prolog input which is
In many Prolog systems it is easy to add a new search path for
How do I write a procedure in Prolog that clears a list of integers
I am new to prolog and i want to solve this problem. Suppose I
I'm new to Prolog. Using this basic 'database' structure, I thought I would be
I am new into the world of Prolog, and I would like to write

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.