March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
|
|
@ -1 +1 @@
|
|||
HailstoneFP[n_] := Drop[FixedPointList[If[# != 1, Which[Mod[#, 2] == 0, #/2, True, ( 3*# + 1) ], 1] &, n], -1]
|
||||
HailstoneFP[n_Integer] := Most[FixedPointList[Which[# == 1, 1, EvenQ[#] , #/2, OddQ[#], (3*# + 1)] &, n]]
|
||||
|
|
|
|||
|
|
@ -1,12 +1,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];
|
||||
hailstone[n_Integer] := Block[{sequence = {}, c = n},
|
||||
While[c > 1, c = If[EvenQ[c], c/2, 3 c + 1];
|
||||
AppendTo[sequence, c]];
|
||||
sequence]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
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];
|
||||
Loading…
Add table
Add a link
Reference in a new issue