Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

Students also viewed these Databases questions

Question

=+C&B (especially taxation) laws, regulations, and practices?

Answered: 1 week ago