Question: Implement the function magic _ math ( ) using the functions map ( ) , filter ( ) , and reduce ( ) . magic

Implement the function magic_math() using the functions map(), filter(), and reduce().
magic_hash() receives a list of integers, and returns an integer of the following algorithm:
1) Map each value. If the value n is odd, replace it with 3n+1
2) Map each value. If the value n is even, replace it with n/2
3) Filter each value, keeping only values not divisible by 3.
4) Reduce the list:
a) Start with zero
(Hint: You have to add an element 0 as the first element of the filtered list)
b) Add the number if it is odd
c) Add half the number if it is even.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!