Question

The predicate minim(IntList,Min) is true if Min is the minimum of the integers in a given...

The predicate minim(IntList,Min) is true if Min is the minimum of the integers in a given non-empty list IntList. For example, a query ?- minim([29,1,8,167], X). Returns the answer X = 1, a query ?- minim([12,123,456,12,78,999,123,12],X), returns the answer X = 12, but a query ?- minim([99,2,17,155],17), must return the answer no. Write a recursive program that implements this predicate using any arithmetical operators, but you cannot use any auxiliary predicates. (Must use PROLOG)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

minim([X], X).
minim([X | Y], X) :-
   minim(Y, L_Ans),
   X =< L_Ans, !.
minim([_X | Y], Ans) :-
   minim(Y, Ans).

Add a comment
Know the answer?
Add Answer to:
The predicate minim(IntList,Min) is true if Min is the minimum of the integers in a given...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Logic Programming An important type of programming language is designed to reason using the rules of...

    Logic Programming An important type of programming language is designed to reason using the rules of predicate logic. Prolog (from Programming in Logic), developed in the 1970s by computer scientists working in the area of artificial intelligence, is an example of such a language. Prolog programs include a set of declarations consisting of two types of statements, Prolog facts and Prolog rules. Prolog facts define predicates by specifying the elements that satisfy these predicates. Prolog rules are used to define...

  • Write a recursive function sum-odds that takes a non-empty list of integers

    in python Part I: Sum of Odd Integers Write a recursive function sum-odds that takes a non-empty list of integers as an argument and returns the sum of only the odd integers in the list. In class we explored a recursive function called rsum that recursively computes the sum of a list of integers use it as a model to get started. Your function must be recursive and must not use any loops

  • Assignment #9 will be the construction of a program that reads in a sequence of integers...

    Assignment #9 will be the construction of a program that reads in a sequence of integers from standard input until 0 is read, and store them in an array (including 0). This is done using iteration (choose one of for, while, or do while loop). You may assume that there will not be more than 100 numbers. Then compute the minimum number, compute the largest number among the numbers that are divisible by 2, count even numbers, and compute the...

  • PROGRAM DESCRIPTION Using the given class definitions for either C++, create a minimum heap that stores...

    PROGRAM DESCRIPTION Using the given class definitions for either C++, create a minimum heap that stores integers and and implements a minimum priority queue. (Your program can be "hard coded" for integers - it does not need to use templates, generics, or polymorphism.) Your data structure must always store its internal data as a heap. Your toString function should return a string with the heap values as a comma separated list, also including the size of the heap as well....

  • In Java, Implement a class MyArray as defined below, to store an array of integers (int)....

    In Java, Implement a class MyArray as defined below, to store an array of integers (int). Many of its methods will be implemented using the principle of recursion. Users can create an object by default, in which case, the array should contain enough space to store 10 integer values. Obviously, the user can specify the size of the array s/he requires. Users may choose the third way of creating an object of type MyArray by making a copy of another...

  • Here is the IntegerLinkedList_incomplete class: public class IntegerLinkedList { static class Node { /** The element...

    Here is the IntegerLinkedList_incomplete class: public class IntegerLinkedList { static class Node { /** The element stored at this node */ private int element; // reference to the element stored at this node /** A reference to the subsequent node in the list */ private Node next; // reference to the subsequent node in the list /** * Creates a node with the given element and next node. * * @param e the element to be stored * @param n...

  • 1 Overview For this assignment you are required to write a Java program that plays (n,...

    1 Overview For this assignment you are required to write a Java program that plays (n, k)-tic-tac-toe; (n, k)-tic- tac-toe is played on a board of size n x n and to win the game a player needs to put k symbols on adjacent positions of the same row, column, or diagonal. The program will play against a human opponent. You will be given code for displaying the gameboard on the screen. 2 The Algorithm for Playing (n, k)-Tic-Tac-Toe The...

  • Add a recursive Boolean function called checkRecurse to class IntegerLinkedList to check if any two consecutive...

    Add a recursive Boolean function called checkRecurse to class IntegerLinkedList to check if any two consecutive integers in the linked list are equal (return true in this case, false otherwise). You may assume that the list is not empty. A recursion “helper” function is already included in class IntegerLinkedList. You only need to write the recursive function. For example, checkRecurseHelper() should return true for the linked list shown below. A main function (prob3.cpp) is given to you to add data...

  • CAN SOMEONE HELP WITH THIS? Part 1: power() method We want to write a method that...

    CAN SOMEONE HELP WITH THIS? Part 1: power() method We want to write a method that will enable us to calculate a number to a given power. In other words, we are writing a method to mimic what the Math.pow() method we have seen before does. To write this method use the following requirements: The method should return an integer. It should have two parameters x and y both integers. The name of this method will be power(). For the...

  • Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate...

    Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT