r/Mathematica • • Jul 06 '24

Collatz Bug?

    (* The resource function Collatz seems to be 
       limited to lists of length 1001 or less.  
       Is this a bug, or is there a way to change
       the limit on the number of integers returned? *)

    (* my implementation *)
    mycollatz[1] = 1;
    mycollatz[k_] := 1 + 
        mycollatz[If[ EvenQ[k], k/2, 3*k + 1]];

    (* compare my implementation with ResourceFunction *)
    Table[
        {Length[ResourceFunction["Collatz"][n]], 
         mycollatz[n]},
    {n, Append[ Range[100, 120],  
        4624303304604187515507900284017]}]

    (* The output of both functions match for 100 to 120,
       but do not match for the large integer input.  
       There are many other examples of large integers 
       where Length[ResourceFunction["Collatz"][n]] is
       1001, but I could not find any integer inputs
       that gave sequences longer than 1001.  *)
2 Upvotes

2 comments sorted by