Question

In: Computer Science

Use logical language Prolog. Use SWISH (SWI Prolog for Sharing) Write a Prolog program that finds...

Use logical language Prolog. Use SWISH (SWI Prolog for Sharing)

Write a Prolog program that finds the maximum of a list of numbers. Submission file should include a screenshot with tracing a program execution when a list only has 2 members and execution without tracing when a list has 8 elements.

Solutions

Expert Solution

%max in list
maxlist([X|L],M):- max(L,X,M). % call accumulator to find max
max([],X,X).
max([X|L],C,M):- C =< X ,
           M1 is X,
           max(L,M1,M).
max([_|L],C,M):- max(L,C,M).

% tracing and output with 2 elements

% ouput with 8 elements

/* PLEASE UPVOTE */


Related Solutions

In C program, Use "do...while" and "for" loops to write a program that finds all prime...
In C program, Use "do...while" and "for" loops to write a program that finds all prime numbers less than a specified value.
Write this program in C++ language. Use the concept of structures. DO NOT use vectors. Q...
Write this program in C++ language. Use the concept of structures. DO NOT use vectors. Q (4) Create a structure called time. Its three members, all type int, should be called hours, minutes, and seconds. Write a program that prompts the user to enter a time value in hours, minutes, and seconds. This should be in 12:59:59 format. This entire input should be assigned first to a string variable. Then the string should be tokenized thereby assigning the 1st token...
C language <stdio.h> use double and const Write a program that asks the user for the...
C language <stdio.h> use double and const Write a program that asks the user for the radius of a circle (as a double) and displays the diameter, circumference, and area of the circle. Use a constant of 3.14159 as the value of pi. Have a blank line between the input and the output. Follow the 3 steps in the Information Processing Cycle - Input, Processing, and Output. The formulas needed are: diameter = 2 * radius circumference = 2 *...
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function....
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function. The program should ask for a user's input and print the length of the user's input. Write the main function to call strlen. The main function should: - Prompt the user for input - Pass that input to strlen using registers $a0. - Preserve (i.e. push onto the stack) any T registers that the main function uses. The strlen function should: - Preserve any...
Use "do...while" loops to write a program that finds all prime numbers less than a specified...
Use "do...while" loops to write a program that finds all prime numbers less than a specified value.
Write a program in C++ to implement Lamport’s logical clocks. Your program should take as input...
Write a program in C++ to implement Lamport’s logical clocks. Your program should take as input a description of several process schedules (i.e., lists of send, receive or print operations). The output of your program will be a linearization of these events in the order actually performed, annotated with Lamport clock values. The input of the program will be a collection of processes, each with a list of operations to perform. The processes are named p1...pn for some n (you...
Write JAVA program that finds 3 students with the best scores. The program asks users for...
Write JAVA program that finds 3 students with the best scores. The program asks users for scores of 5 students. The program prints the first, second, third place students and scores. You can assume that there is no two students with the same score. <EXAMPLE> enter the score of each student score of student 1: 50 score of student 2: 70 score of student 3: 30 score of student 4: 90 score of student 5: 40 1st place is student...
Please use Java language with comments! Thanks! Write a program that will display multiple dots move...
Please use Java language with comments! Thanks! Write a program that will display multiple dots move across the Frame and randomly change direction when they hit the edge of the screen. Do this by creating a Dot class and making each dot an object of that class. You may reuse code written in class for this part of the assignment. Create a subclass of the Dot class called PlayerDot that is controlled by the player through keyboard input (arrow keys)...
Write a program to create a tree randomly. You can use C++ programming language. The input...
Write a program to create a tree randomly. You can use C++ programming language. The input is the number of vertices in the tree, and the output is an adjacent list of the tree. (Managed to complete this assignment with a binary tree. But, was told I needed a general tree instead)
Write an assembly language program that prints your first name in the output. Use immediate addressing...
Write an assembly language program that prints your first name in the output. Use immediate addressing with a hexadecimal constant to designate the operand of CHARO for each letter of your name. Comment each line except STOP and END. Cut and paste the Assembler Listing into your document and paste a screen shot of the Output area of the Pep8. Use the name "Kevin" as example Assembler Listing Screen Shot of Output area of the Pep8 program
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT