Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. BeginPackage["Collatz`"]
  2.  
  3. Collatz::usage = "Collatz[n] gives a list of the iterates in the 3n+1
  4. problem,
  5. starting from n. The conjecture is that this sequence always
  6. terminates."
  7.  
  8. Begin["`Private`"]
  9.  
  10. Collatz[1] := {1}
  11.  
  12. Collatz[n_Integer] := Prepend[Collatz[3 n + 1], n] /; OddQ[n] && n > 0
  13.  
  14. Collatz[n_Integer] := Prepend[Collatz[n/2], n] /; EvenQ[n] && n > 0
  15.  
  16. End[]
  17.  
  18. EndPackage[]
  19.  
  20. Get["DesktopCollatz.m"]
  21.  
  22. (* ::Package:: *)
  23.  
  24. (* ::Input:: *)
  25. (*BeginPackage["Collatz`"]*)
  26. (**)
  27. (*Collatz::usage="Collatz[n] gives a list of the iterates in the 3n+1 problem,*)
  28. (* starting from n. The conjecture is that this sequence always*)
  29. (* terminates."*)
  30. (**)
  31. (*Begin["`Private`"]*)
  32. (**)
  33. (*Collatz[1]:={1}*)
  34. (**)
  35. (*Collatz[n_Integer]:=Prepend[Collatz[3 n+1],n]/;OddQ[n]&&n>0*)
  36. (**)
  37. (*Collatz[n_Integer]:=Prepend[Collatz[n/2],n]/;EvenQ[n]&&n>0*)
  38. (**)
  39. (*End[]*)
  40. (**)
  41. (*EndPackage[]*)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement