Code for #1
(define (absDiff lstA lstB)
(if
(and (null? lstA) (null? lstB))
'(0)
(if (eq? (length lstA) (length lstB))
(map (lambda (number1 number2)
(- number1 number2))
lstA
lstB)
'(0))
)
)
(display (absDiff '(10 25) '(12 5)))
(newline)
output:

a)
(define (absDiffA lstA lstB)
(if
(and (null? lstA) (null? lstB))
'(0)
(if (> (length lstA) (length lstB))
(for ([number1 lstA]
[number2 lstB])
(- number1 number2)
)
(if (eq? (length lstA) (length lstB))
(map (lambda (number1 number2)
(- number1 number2))
lstA
lstB))
)
)
)
b)
(define (absDiffB lstA lstB)
(if
(and (null? lstA) (null? lstB))
'(0)
(if (< (length lstA) (length lstB))
(for ([number1 lstA]
[number2 lstB])
(- number1 number2)
)
(if (eq? (length lstA) (length lstB))
(map (lambda (number1 number2)
(- number1 number2))
lstA
lstB))
)
)
)
Using Scheme: Write a function absDiff that calculates the absolute difference of the corresponding elements of...
PYTHON: MUST NOT USE PYTHONS BUILT IN FUNCTIONS SUCH AS result.append MUST BE SOLVED OUT WITHOUT SUCH FUNCTIONS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 1. Write a function interleave(vals1, vals2) that takes as inputs two lists vals1 and vals2 and uses recursion to construct and return a new string that is formed by interleaving the elements in the lists vals1 and vals2 to create a single list. In other words, the new list should alternate elements from the two input lists: the first element from vals1,...
Using PYTHON (LOOPS, IF STATEMENTS ) I should write a function buckets that takes two arguments: (bucketCount, an integer specifying the number of “buckets” to return and numberLs, a list of numbers ) buckets should split the range of values in numberLs into bucketCount sub-ranges. Specifically buckets should return a list-of-lists of length bucketCount. Each list in the returned list-of-lists represents a “bucket”. Each bucket should contain the numbers from numberLs whose values are greater than or equal to min(numberLs) +...
ANSWER USING PYTHON Write a recursive function that takes 2 sorted lists as arguments and returns a single, merged sorted list as a result. For example, if the two input lists are [0, 2, 4, 6, 8] and [1, 3, 5, 7, 9], the returned result should be [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]. Remember that you can add lists in Python using the + operator ([0] + [1,2,3] = [0,1,2,3]) and can take slices of...
Write a c program that finds the uncommon elements from two array elements using pointers only . For example : Enter the length of the array one : 5 Enter the elements of the array one: 9 8 5 6 3 Enter the length of the array two: 4 Enter the elements of the array two: 6 9 2 1 output: 8 5 3 2 1 void uncommon_ele(int *a, int n1, int *b, int n2, int *c, int*size); The function...
Python. Write a function swap_lists that takes in two lists and swap their elements in place. You can not use another list. You can not return lists. Input lists have the same size. def swap_lists(alist1, alist2): """Swaps content of two lists. Does not return anything. >>> list1 = [1, 2] >>> list2 = [3, 4] >>> swap_lists(list1, list2) >>> print(list1) [3, 4] >>> print(list2) [1, 2] >>> list1 = [4, 2, 6, 8, 90, 45] >>> list2 = [30, 41,...
Write a function using c that combines two lists by alternatingly taking elements from the two lists that are passed to it. e.g. [a,b,c], [1,2,3] → [a,1,b,2,c,3].
In LISP write one function using length that gets the last atom in a list and another function that triples all the elements in a list (triple-value '(1 2 3 4 5)) so the result should be (1 8 27 64 125)
Help with solution using Python
test using
def riffle_generator(seed):
random.seed(seed)
for i in range(1000):
n = random.randint(0, 100)
items = [random.randint(0, 10**6) for j in range(2 * n)]
yield (items, True)
yield (items, False)
Riffle def riffle(items, out True): Given a list of items that is guaranteed to contain an even number of elements (note that the integer zero is an even number), create and return a list produced by performing a perfect riffle to the items by interleaving the...
Python 2.7 Write a function cumsum() that takes a list l as argument and returns the cumulative sum (also known as the prefix sum) of l, which is a list, say cs of the same length as l such that each element cs[i] is equal to the sum of the first i + 1 elements of l, i.e., cs[i] == l[0] + l[1] + l[2] + ... + l[i] You should not modify the argument list l in any way....
Write a method called alternate that accepts two Lists as its parameters and returns a new List containing alternating elements from the two lists, in the following order: • First element from first list • First element from second list • Second element from first list • Second element from second list • Third element from first list • Third element from second list If the lists do not contain the same number of elements, the remaining elements from the...