2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1 +1 @@
|
|||
HailstoneFP[n_Integer] := Most[FixedPointList[Which[# == 1, 1, EvenQ[#] , #/2, OddQ[#], (3*# + 1)] &, n]]
|
||||
HailstoneF[n_] := NestWhileList[If[OddQ@#, 3 # + 1, #/2] &, n, # > 1 &]
|
||||
|
|
|
|||
|
|
@ -1,3 +1 @@
|
|||
HailstoneR[1] := {1}
|
||||
HailstoneR[n_Integer] := Prepend[HailstoneR[3 n + 1], n] /; OddQ[n] && n > 0
|
||||
HailstoneR[n_Integer] := Prepend[HailstoneR[n/2], n] /; EvenQ[n] && n > 0
|
||||
HailstoneFP[n_] := Most@FixedPointList[Switch[#, 1, 1, _?OddQ , 3# + 1, _, #/2] &, n]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
hailstone[n_Integer] := Block[{sequence = {}, c = n},
|
||||
While[c > 1, c = If[EvenQ[c], c/2, 3 c + 1];
|
||||
AppendTo[sequence, c]];
|
||||
sequence]
|
||||
HailstoneR[1] = {1}
|
||||
HailstoneR[n_?OddQ] := Prepend[HailstoneR[3 n + 1], n]
|
||||
HailstoneR[n_] := Prepend[HailstoneR[n/2], n]
|
||||
|
|
|
|||
|
|
@ -1,12 +1,2 @@
|
|||
Hailstone[n_] :=
|
||||
NestWhileList[Which[Mod[#, 2] == 0, #/2, True, ( 3*# + 1) ] &, n, # != 1 &];
|
||||
c27 = Hailstone@27;
|
||||
Print["Hailstone sequence for n = 27: [", c27[[;; 4]], "...", c27[[-4 ;;]], "]"]
|
||||
Print["Length Hailstone[27] = ", Length@c27]
|
||||
|
||||
longest = -1; comp = 0;
|
||||
Do[temp = Length@Hailstone@i;
|
||||
If[comp < temp, comp = temp; longest = i],
|
||||
{i, 100000}
|
||||
]
|
||||
Print["Longest Hailstone sequence at n = ", longest, "\nwith length = ", comp];
|
||||
HailstoneP[n_] := Module[{x = {n}, s = n},
|
||||
While[s > 1, x = {x, s = If[OddQ@s, 3 s + 1, s/2]}]; Flatten@x]
|
||||
|
|
|
|||
|
|
@ -1 +1,14 @@
|
|||
With[{seq = HailstoneFP[27]}, { Length[seq], Take[seq, 4], Take[seq, -4]}]
|
||||
Hailstone[n_] :=
|
||||
NestWhileList[Which[Mod[#, 2] == 0, #/2, True, ( 3*# + 1) ] &, n, # != 1 &];
|
||||
|
||||
|
||||
c27 = Hailstone@27;
|
||||
Print["Hailstone sequence for n = 27: [", c27[[;; 4]], "...", c27[[-4 ;;]], "]"]
|
||||
Print["Length Hailstone[27] = ", Length@c27]
|
||||
|
||||
longest = -1; comp = 0;
|
||||
Do[temp = Length@Hailstone@i;
|
||||
If[comp < temp, comp = temp; longest = i],
|
||||
{i, 100000}
|
||||
]
|
||||
Print["Longest Hailstone sequence at n = ", longest, "\nwith length = ", comp];
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Short[HailstoneFP[27],0.45]
|
||||
With[{seq = HailstoneFP[27]}, { Length[seq], Take[seq, 4], Take[seq, -4]}]
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
MaximalBy[Table[{i, Length[HailstoneFP[i]]}, {i, 100000}], Last]
|
||||
Short[HailstoneFP[27],0.45]
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
MaximalBy[Table[{i, Length[HailstoneFP[i]]}, {i, 100000}], Last]
|
||||
Loading…
Add table
Add a link
Reference in a new issue