Question

a) You must write a recursive function that takes something of the form: ([(Int, Int, Int), Int, Int) as an argument and returns something of the form: LE(Int, Int, Int)]] which should be interpreted as a list of lists of 3-tuples of RGB values. You may use helper functions if you wish, but your solution must be recursive. You must document the name of your function at the beginning of your code using a comment like -- foo :: ([(Int, Int, Int)], Int, Int) -> [[(Int, Int, Int)]] -- foo is the function I have written to address requirement (a)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Without the context of the complete usage of function it is confusion as to what end the recursion is required. Though a sample script is being provided here. This script takes in a list along with a constant value and a list index. The function must recursively reduce the value of constant c from all the indexed location index in list between the very first i.e. '0' and the given value index.

#===============================================

def foo(list1,int1,int2):

if(int2>=0):

list1[int2]=list1[int2]-int1;

foo(list1,int1,int2-1); # Recursively reducing the index value and passing it on

return list1;

# Passing sample arguments

final_list = foo([1,2,3,4,5,6],6,2);

# Printing the returned values

print(final_list);

#===============================================

Output:

[-5, -4, -3, 4, 5, 6]

Hope this helps! PLEASE THUMBS UP!!!!!!!!!!!!!!!!!!!!!!!!

In case of any clarification, please comment!

Add a comment
Know the answer?
Add Answer to:
a) You must write a recursive function that takes something of the form: ([(Int, Int, Int),...
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
  • C++ 9) Write a recursive function printAll that takes an int num argument and prints all...

    C++ 9) Write a recursive function printAll that takes an int num argument and prints all the numbers in the range [num, 0]. The function returns nothing. e.g. printAll(5) prints 5, 4, 3, 2, 1, 0. Call your function in the main

  • (a) Write a program in Java to implement a recursive search function int terSearch(int A[], int...

    (a) Write a program in Java to implement a recursive search function int terSearch(int A[], int l, int r, int x) that returns the location of x in a given sorted array of n integers A if x is present, otherwise -1. The terSearch search function, unlike the binary search, must consider two dividing points int d1 = l + (r - l)/3 int d2 = d1 + (r - l)/3 For the first call of your recursive search function...

  • 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

  • 7) Recursion Write a recursive function max_tuple(a tree which takes a tree as a parameter and...

    7) Recursion Write a recursive function max_tuple(a tree which takes a tree as a parameter and returns the max values of the right and left subtree. You can assume that the parameter is a full binary tree (in a pyramid shape like with more than 3 nodes. Your solution should not have any iteration. You can use a helper function if needed. Your code should be indented correctly. The expected return value of max_tuple(tree) for the tree below should be(...

  • In python please 6 annoying_int_sequence(n) In annoying_recursion.py, write the function annoying_int_sequence(n) which takes a single integer...

    In python please 6 annoying_int_sequence(n) In annoying_recursion.py, write the function annoying_int_sequence(n) which takes a single integer parameter (which must be non-negative). It must return a list of intgers. The contents of the integers are defined recursively. Basically, each version of this sequence is made up of the next-smaller one, repeated n times - and with the number n in-between. For instance, the sequence for n = 3 is: ???? 3 ???? 3 ???? Just drop in the the sequence for...

  • Write a function isaset which takes a list of any equality type2 and returns true if...

    Write a function isaset which takes a list of any equality type2 and returns true if the list is a set (each element appears exactly once). So, the type of isaset is ' 'a list -> bool. Hints: • Do not try for efficiency. A brute-force O(n2 ) solution is appropriate to this exercise. 3 • You might find it easier to develop an algorithm if you consider how to determine the list is not a set. • A recursive...

  • Write a ML language function stripmin of type int list -> int list that will return...

    Write a ML language function stripmin of type int list -> int list that will return a list from which every instance of the lowest value has been removed. Hints: • Only stripmin itself should be visible at the top level; •You should have two recursive helper functions tucked away inside a let … in … end; structure • Also include a val to avoid having to pass a value that never changes to one of these functions. • Use...

  • (C++) You are tasked with implementing a recursive function void distanceFrom(int key) on the IntList class...

    (C++) You are tasked with implementing a recursive function void distanceFrom(int key) on the IntList class (provided). The function will first search through the list for the provided key, and then, recursively, change all previous values in the list to instead be their distance from the node containing the key value. Do not update the node containing the key value or any nodes after it. If the key does not exist in the list, each node should contain its distance...

  • Write a function isaset which takes a list of any equality type2 and returns true if the list is a set (each element app...

    Write a function isaset which takes a list of any equality type2 and returns true if the list is a set (each element appears exactly once). So, the type of isaset is ' 'a list -> bool. Hints: • Do not try for efficiency. A brute-force O(n2 ) solution is appropriate to this exercise. 3 • You might find it easier to develop an algorithm if you consider how to determine the list is not a set. • A recursive...

  • a. Write a function arrayToMap that takes an array of strings and returns a std::map<int, string>...

    a. Write a function arrayToMap that takes an array of strings and returns a std::map<int, string> such that the values in the map are the string values in the array of strings, and the keys in the map are the corresponding array indices of the string values. You may assume all necessary libraries have been included in your program and your solution must be syntactically correct in order to receive full credit. map<int, string> arrayToMap(string arr[], int arrSize) { b....

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