A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
|
|
@ -0,0 +1 @@
|
|||
HailstoneFP[n_] := Drop[FixedPointList[If[# != 1, Which[Mod[#, 2] == 0, #/2, True, ( 3*# + 1) ], 1] &, n], -1]
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
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
|
||||
|
|
@ -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