Question: Collatz conjecture procedure take 2

Hi MaplePrimes,

 

I try again to ask about a procedure I wrote.  Maybee someone can spot my error.

 

collatz_conjecture_2.mw

Here is the broken procedure - 

cs := proc (n::integer)::integer;
local count;
description "Find the number of steps for a Collatz sequence to reach 1";
count := 1;
while 1 < n do
if `mod`(n, 2) = 0 then n := (1/2)*n else n := 3*n+1 end if;
count := count+1
end do;
return count
end proc

Regards,

Matt

 

Please Wait...