Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BeginPackage["Collatz`"]
- Collatz::usage = "Collatz[n] gives a list of the iterates in the 3n+1
- problem,
- starting from n. The conjecture is that this sequence always
- terminates."
- Begin["`Private`"]
- 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
- End[]
- EndPackage[]
- Get["DesktopCollatz.m"]
- (* ::Package:: *)
- (* ::Input:: *)
- (*BeginPackage["Collatz`"]*)
- (**)
- (*Collatz::usage="Collatz[n] gives a list of the iterates in the 3n+1 problem,*)
- (* starting from n. The conjecture is that this sequence always*)
- (* terminates."*)
- (**)
- (*Begin["`Private`"]*)
- (**)
- (*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*)
- (**)
- (*End[]*)
- (**)
- (*EndPackage[]*)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement