Write two clauses in PROLOG that determines if there are three values in a list that sum up to a value of N.
The output should be a single true if there exist three values whose sum is N or a single false if there are not.
If there are multiple values whose sum is N then the program should only print true once.
We just need to find that are there elements present in the list that add up to our sum
If the elements are present then we check if the size of that list is 3 if yes then our answer is true else false.
Code :
Function Call :
Result :
Code :
findthree(Sum,Answer,List) :-
Answer = [_,_,_], % This is to ensure that our final answer
only
findAny(Sum,Answer,List). % contains three elements
findAny(0,[],_L). % Base Case to ensure Zero sum of
elements
findAny(Sum,[H|T1],[H|T2]) :-
Currsum is Sum-H, % Take the current element in our answer
and
findAny(Currsum,T1,T2). % Make a recursive call to find
furthur.
findAny(Sum,Answer,[_H|T]) :- % This will help skipping the
elements
dif(Answer,[]), % so that a sublist can be formed
findAny(Sum,Answer,T).
Write two clauses in PROLOG that determines if there are three values in a list that sum up to a ...
Write a Prolog program to find the maximum, minimum, and range of values in a list of numbers. Please also provide the program with output.
In Python: Write a program that determines whether two circles intersect. The input should consist of six numbers, x1, y1, r1 and x2, y2, r2, given as command-line arguments, and representing the center and radius of the two circles. Your program should print True if the two circles intersect, and False otherwise. As a reminder, the two circles intersect if and only if the distance of their two centers is less than or equal to the sum of their two...
C programming! Write a program that reads integers until 0 and prints the sum of values on odd positions minus the sum of values on even positions. Let ?1, ?2, … , ??, 0 be the input sequence. Then the program prints the value of ?1 − ?2 + ?3 − ?4 + ⋯ ??. The input is a sequence of integers that always contains at least 0 and the output will be a single number. For example, for input...
CSE 240 Homework 5- Programming with PROLOG Due: Monday, April 22, 11:59 PM A. What This Assignment Is About: Facts, Rules, Goals Prolog execution model Arithmetic operations . Recursive Rules B. Use the following Guidelines Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc.) Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of...
MODIFY THIS LINK LIST USING C++: Write a function which determines if the values in the queue is divisible by 5 or 10 if true the value is divided by 5 void NumberList::listDivisibleBy5or10() ListNode* currentNode = head; //Pointer for current value in the link list if(!head) // checks for an empty link list { std::cout<<"The list is empty \n"; // tells user that the link list is empty } else { ...
write a python program which finds three consecutive odd numbers whose sum adds up to 45 and return a list of the numbers in ascending order do not use any other packages such as numpy or math
Write a program that reads two integer values. It then calculates and displays the sum and average of all values between them, Le. if the first value is vi and the second value is 2, then the program calculates and displays the sum and average of all values in the closed range Iv1,2 Your Program must satisfy the following constraints: A. make sure that v1 is less than 2 B. Use a function named getStats(that takes two integer yalues as...
Create a C++ program. Include comment, input and output file. STACK IMPLEMENTATION USING AN link list IMPLEMENT THE FOLLOWING STACK OPERATIONS using a TEMPLATED CLASS. WRITE ALL THE FULL-FUNCTION DEFINITIONS NEEDED for the OPERATIONS. OUTPUT: PRINT ALL THE ELEMENTS ON THE STACK. Stack Operations initializestack: Initializes the stack to an empty state. isEmptyStack: Determines whether the stack is empty. If the stack is empty, it returns the value true; otherwise, it returns the value false. isFul1stack: Determines whether the stack...
Write a Java program called EqualSubsets that reads a text file, in.txt, that contains a list of positive and negative integers (duplicates are possible) separated by spaces and/or line breaks. Zero may be included. After reading the integers, the program saves them in a singly linked list in the same order in which they appear in the input file. Then, without changing the linked list, the program should print whether there exists two subsets of the list whose sums are...
Write in C Program.... Write a multi-threaded program that calculates various statistical values for a list of numbers. This program will be passed a series of numbers on the command line and will then create three separate worker threads. One thread will determine the average of the numbers, the second will determine the maximum value, and the third will determine the minimum value. For example, suppose your program is passed the integers 90 81 78 95 79 72 85. The...