Question: The only functions you may use are: print, str, int, float, bool, len, list, range, abs, round, and pow . Note that you may not
The only functions you may use are: print, str, int, float, bool, len, list, range, abs, round, and pow. Note that you may not use list slicing (AKA colons in your indicies). We will not deduct for the use of str(), but you do not actually need it. Do not import libraries.
[50 points] Design a recursive algorithm that will display whether it is possible to choose two integers from a list of integers such that the difference of the two equals a given value. Hint: You may wish to invoke another algorithm, (i.e., function), that accepts more parameters which performs the recursion. Submit a python function is_diff_two(values,diff) that take a list and the desired difference as a non-negative integer and returns true or false.
Examples:
is_diff_two([2, 4, 8], 4) # returns True is_diff_two([1, 2, 4, 8, 1], 7) # returns True is_diff_two([2, 4, 4, 8], 7) # returns False is_diff_two([], 7) # returns False is_diff_two([-1,-3,5,8,10],11) #returns True
P2: -50 for using forbidden functions.
P2: -25 for not using any recursion. (up to -50 no matter what this missing recursion is in combination with)*
P2: -25 for using for or while loops.
P2: -25 for using slicing.
P2: -10 for list functions such as append(), prepend(), pop(), etc.
P2: -10 for a complex solution that is quite hard to follow. ( use good commenting, good variables names, and concise code that clearly progresses towards the solution)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
