Skip to content

Instantly share code, notes, and snippets.

@VitamintK
Forked from anonymous/gist:133b308380d7aba376bc
Last active August 29, 2015 14:24
Show Gist options
  • Save VitamintK/ce48f4aaf32b90515691 to your computer and use it in GitHub Desktop.
Save VitamintK/ce48f4aaf32b90515691 to your computer and use it in GitHub Desktop.
cf3 =
Compile[
{},
Module[
{n1, l, max = 0, maxN = 0},
Do[
n1 = n;
l = 1;
While[
n1 != 1,
n1 = If[EvenQ[n1], n1~Quotient~2, 3 n1 + 1];
l++];
If[l > max, max = l; maxN = n];,
{n, 1, 10^4}];
{max, maxN}]]
cf =
Compile[
{},
Module[
{n1, l, maxLength = 0, maxStart = 0},
Do[
n1 = n;
l = 1;
While[
n1 != 1,
n1 = If[EvenQ[n1], n1/2, 3 n1 + 1];
l++];
If[l > maxLength, maxLength = l; maxStart = n];,
{n, 1, 10^4}];
{maxLength, maxStart}]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment