Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Haskell program for the following: The function collatz :: Int -> Int is defined by collatz(n) = n/2 if n is even and

Write a Haskell program for the following:

image text in transcribed

The function collatz :: Int -> Int is defined by collatz(n) = n/2 if n is even and collatz(n) = 3n + 1 if n is odd. It is believed that if collatz is applied repeatedly, then eventually one will see the num- ber 1. For example, collatz (5) = 16, and collatz (16) = 8, and collatz (8) = 4, and collatz (4) = 2, and collatz (2) = 1. The Collatz index of a num- ber is the minimum number of times that collatz needs to be applied to obtain 1. For example, the Collatz index of 5 is 5, and the Collatz index of 7 is 16 (the sequence is [7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10,5, 16,8, 4, 2, 1). Write a Haskell function collatzIndex :: Int -> SF [Int] which computes the Collatz "index" of a number by calculating the sequence ending in 1. What happens if a number has no Collatz index? The function collatz :: Int -> Int is defined by collatz(n) = n/2 if n is even and collatz(n) = 3n + 1 if n is odd. It is believed that if collatz is applied repeatedly, then eventually one will see the num- ber 1. For example, collatz (5) = 16, and collatz (16) = 8, and collatz (8) = 4, and collatz (4) = 2, and collatz (2) = 1. The Collatz index of a num- ber is the minimum number of times that collatz needs to be applied to obtain 1. For example, the Collatz index of 5 is 5, and the Collatz index of 7 is 16 (the sequence is [7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10,5, 16,8, 4, 2, 1). Write a Haskell function collatzIndex :: Int -> SF [Int] which computes the Collatz "index" of a number by calculating the sequence ending in 1. What happens if a number has no Collatz index

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

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions

Question

Have you ever had an epiphany?

Answered: 1 week ago