Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C + + Given any positive integer n , define f ( n ) : = { n 2 i s e v e n

C++
Given any positive integer n, define
f(n):={n2iseven3n+1,nisodd.
The Collatz conjecture states that the sequence
ai:={n,i=0f(ai-1),i>0
eventually reaches 1. Write a function int collatzLength (int n) that
determines the first i for which ai=1 for a given n. For example, when n=
17, the sequence ai begins
17,52,26,13,40,20,10,5,16,8,4,2,1,dots
and a12=1. Thus, collatzLength (17) should return 12.
image text in transcribed

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

Implementing Ai And Machine Learning For Business Optimization

Authors: Robert K Wiley

1st Edition

B0CPQJW72N, 979-8870675855

More Books

Students also viewed these Databases questions