Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- collatz[x_, y_] := If[x == 3*y || x == 2*y + 1 || y == 3*x || y == 2*x + 2, 2, 0]
- GraphPlot3D[collatz[#1, #2] &, {40, 40}]
- Collatz[1] := {1}
- Collatz[n_Integer] := Prepend[Collatz[3 n + 1], n] /; OddQ[n] && n > 0
- Collatz[n_Integer] := Prepend[Collatz[n/2], n] /; EvenQ[n] && n > 0
- Graph[(DirectedEdge @@@ Partition[Collatz[#], 2, 1]) & /@ Range[500] // Flatten // Union,
- EdgeShapeFunction -> GraphElementData[{"Arrow", "ArrowSize" -> .005}],
- GraphLayout -> "LayeredDrawing"]
- Graph[(DirectedEdge @@@ Partition[Collatz[#], 2, 1]) & /@ Range[100] //
- Flatten // Union, GraphLayout -> "RadialEmbedding",
- VertexLabels -> "Name"]
- Collatz[1] := {1}
- Collatz[n_Integer] := Collatz[n] = Prepend[Collatz[3 n + 1], n] /; OddQ[n] && n > 0
- Collatz[n_Integer] := Collatz[n] = Prepend[Collatz[n/2], n] /; EvenQ[n] && n > 0
- CollatzSequence[list_] := Module[{memory, tmp, chain, result = Internal`Bag[]},
- memory[1] = False;
- memory[n_] := (memory[n] = False; True);
- Do[
- chain = Internal`Bag[];
- tmp = l;
- While[memory[tmp],
- Internal`StuffBag[chain, tmp];
- tmp = If[EvenQ[tmp], tmp/2, 3 tmp + 1];
- ];
- Internal`StuffBag[chain, tmp];
- Internal`StuffBag[result, chain],
- {l, list}];
- Internal`BagPart[#, All] & /@ Internal`BagPart[result, All]
- ]
- CollatzSequence[{10, 11, 12}]
- (* {{10, 5, 16, 8, 4, 2, 1}, {11, 34, 17, 52, 26, 13, 40, 20,
- 10}, {12, 6, 3, 10}} *)
- Graph[
- Flatten[(Rule @@@ Partition[#, 2, 1]) & /@
- CollatzSequence[Range[50000]]],
- PerformanceGoal -> "Speed",
- GraphLayout -> {"PackingLayout" -> "ClosestPacking"},
- VertexStyle -> Opacity[0.2, RGBColor[44/51, 10/51, 47/255]],
- EdgeStyle -> RGBColor[38/255, 139/255, 14/17]]
- SetAttributes[Collatz, {Listable}];
- Collatz[n_, e_, a_, f_] := Module[{nn = n, bag = Internal`Bag[]},
- While[nn =!= 1, Internal`StuffBag[bag, nn];
- nn = If[EvenQ[nn], nn/2, 3 nn + 1]
- ];
- Internal`StuffBag[bag, nn];
- With[{seq = Reverse[Internal`BagPart[bag, All]]},
- AnglePath[Transpose[{seq/(1 + seq^e), a*(f - 2 Mod[seq, 2])}]]]];
- astroIntensity[l_, s_, r_, h_, g_] :=
- With[{psi = 2 Pi (s/3 + r l), a = h l^g (1 - l^g)/2},
- l^g + a*{{-0.14861, 1.78277}, {-0.29227, -0.90649}, {1.97294,
- 0.0}}.{Cos[psi], Sin[psi]}];
- Manipulate[
- DynamicModule[{seq},
- seq = ControlActive[Collatz[Range[5000, 5020], e, a, f],
- Collatz[RandomInteger[1000000, {n}], e, a, f]];
- Graphics[{Opacity[o], Thickness[ControlActive[0.01, 0.003]],
- Line[seq,
- VertexColors -> (Table[
- astroIntensity[l, s, r, h, g], {l, 0, 1,
- 1/(Length[#] - 1)}] & /@ seq)]}, ImageSize -> 500]
- ]
- , "Colors", {{s, 2.49}, 0, 3}, {{r, 0.76}, 0, 5}, {{h, 1.815}, 0,
- 2}, {{g, 1.3}, 0.1, 2}, {{o, 0.5}, 0.1, 1},
- Delimiter,
- "Structure",
- {{e, 1.3}, 0.9, 1.8},
- {{a, 0.19}, 0.1, 0.3},
- {{f, 0.7}, 0.1, 1.5},
- {n, 300, 5000, 1}
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement