Assuming x and y each are a list of integers, answer the following questions. Use a as a running variable. If necessary use b as an additional running variable. Do not use any other variables as you do not need.
a. Write a Python statement using lambda calculus map to map x to y where every element of y is incremented by 1.
b. Write a Python statement using lambda calculus reduce to reduce x to s, where s is the sum of x. Do not use sum function.
c. Write a Python statement using lambda calculus filter to filter out odd integers from x such that y has only even integers.
SOURCE CODE: *Please follow the comments to better understand the code. **Please look at the Screenshot below and use this code to copy-paste. ***The code in the below screenshot is neatly indented for better understanding. This is a big question. I have solved all of them. Please give me an upvote dear, Much Appreciated.!! from functools import reduce # (a) Write a Python statement using lambda calculus map # to map x to y where every element of y is incremented by 1. y = [10, 20, 30, 40, 50] # Now, use a map function and lambda to increment each value of y by 1 x = map(lambda a: a + 1, y) # Print the result print("Result of map is", list(x)) # (b) Write a Python statement using lambda calculus reduce # to reduce x to s, where s is the sum of x. x = [1, 2, 3, 4, 5] # Use reduce and lambda here s = reduce(lambda a, b: a + b, x) # Print the result print("Sum of values in", x, "is", s) # (c) Write a Python statement using lambda calculus filter # to filter out odd integers from x such that y has only even integers. x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # Use filter and lambda here y = filter(lambda a: a % 2 == 0, x) # Print the result print("Result of filter is", list(y))
Assuming x and y each are a list of integers, answer the following questions. Use a...
(+30) Provide a python program which will Populate an array(list) of size 25 with integers in the range -100 (negative 100) to +100 inclusive Display the array and its length (use the len function) Display the average of all the integers in the array Display the number of even integers (how many) Display the number of odd integers (how many) Display the number of integers > 0 (how many) Display the number of integers < 0 (how many) Display the...
please answer questions #7-13
7. Use a direct proof to show every odd integer is the difference of two squares. [Hint: Find the difference of squares ofk+1 and k where k is a positive integer. Prove or disprove that the products of two irrational numbers is irrational. Use proof by contraposition to show that ifx ty 22 where x and y are real numbers then x 21ory 21 8. 9. 10. Prove that if n is an integer and 3n...
Write a program that initializes an array with ten random integers and then prints out the following: Every element at an even index; Every even element All elements in reverse order; Only the first and last elements; The minimum and maximum element The sum of all elements The alternating sum of all elements, where the alternating sum contains all elements at even index added, and the elements at odd index subtracted. Please write comments above the piece of code that...
Problem 3. Functional Code with Random Number Sequences Write a generator gen_rndtup(n) that creates an infinite sequence of tuples (a, b) where a and b are random integers, with 0 < a,b < n. If n == 7, then a and b could be the numbers on a pair of dice. Use the random module. a) Use lambda expressions, the itertools.islice function (https://docs.python.org/3/library/itertools.html#itertools.islice), and the filter function to display the first 10 generated tuples (a, b) from gen_rndtup(7) that have...
Map, Filter, and Reduce are three functions commonly used in functional programming. For this assignment you will be implementing all three, along with three minor functions that can be passed to them. Map The map function takes as arguments a function pointer and a integer vector pointer. It applies the function to every element in the vector, storing the results in-order in a new vector. It then returns a pointer to a new vector. You should pass your square function...
Code has already been provided to generate two random integers with values between 0 and 10 that are assigned to the variables X and Y. Write a script to create the following two string variables: • The first string should be assigned to the variable Xandy and should present the values of the two numbers by filling in the blank in "The value of X is -, and the value of Y is _." The second string should be assigned...
Write a complete program that: 1) declares two local integers x and y 2) defines a global structure containing two pointers (xptr,yptr) and an integer (z) 3) Declares a variable (mst) by the type of previous structure 4) requests the values of x and y from the user using only one scanf statement 5) sets the first pointer in the struct to point to x 6) sets the second pointer in the struct to point to y 7) uses the...
need question 3 assap using cin and cout outputs please
Ctrl CSC 270 Final Exam-Spring2 1) [10 pts] Create anarray x which includes integers fron ltos obtain the array y which, even formula. Display both arrays x and y in a table with labeled column headings. 0 y- 2x+1 2) 120 pts] Consider the following 2D array. 01 2 -1 X-3 5 0 6 -3 7 -15 Use the standard notation and obtain the following (a) Create and display array...
(a) Write a C program to print a list of all integers between 1 and 1,000 (inclusive) which are divisible by 7 but not by 13. The list should be printed to a file called "output.dat". Remember to close the file after use. (35%) (b) Explain what is meant by the C preprocessor. Explain the effect of the following line of code: #define SQUARE (x) (x) * (x) (25%) (c) Explain the concept of an array in C. Write down...
Suppose there are two non-empty list variables of equal length in Python called coords and sides. The variable coords contains sub-lists of size 2, with each of these values representing an x and a y co-ordinate. The variable sides also contains sub-lists of size 2, with each of these values representing firstly the length thern the width of a rectangle. Also assume there is also a function in Python called draw_rectangle which takes as its parameters two integers representing firstly...