MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

simplifying ulam spiral code

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56394] simplifying ulam spiral code
  • From: zak <chocolatez at gmail.com>
  • Date: Sat, 23 Apr 2005 01:16:49 -0400 (EDT)
  • Reply-to: zak <chocolatez at gmail.com>
  • Sender: owner-wri-mathgroup at wolfram.com

hi
in the site:
http://teachers.crescentschool.org/weissworld/m3/spiral/spiral.html
there is a mathematica code for drawing ULAM'S SPIRAL
the code is:

dat = Table[i, {i, 20000}];
x := 0; y := 0; num := 1; shift := 1;
point := {x, y}; list = {}
 While[num <= 20000,
  i := 1;
  While[i <= shift,
    x = x + 1;
    If[PrimeQ[dat[[num]]] == True, list = Flatten[{list, point}]]; num++; 
    i++;]; i := 1; While[i <= shift,
    y = y + 1;
    If[PrimeQ[dat[[num]]] == True, list = Flatten[{list, point}]]; num++; 
    i++;]; shift++;
  i := 1;
  While[i <= shift,
    x = x - 1;
    If[PrimeQ[dat[[num]]] == True, list = Flatten[{list, point}]]; num++; 
    i++;]; i := 1;
  While[i <= shift,
    y = y - 1;
    If[PrimeQ[dat[[num]]] == True, list = Flatten[{list, point}]]; num++; 
    i++;]; shift++;]
 ListPlot[Partition[list, 2], PlotStyle -> PointSize[0.007], 
    AspectRatio -> Automatic, Axes -> True];


or see text in:
http://sr1.mytempdir.com/15902


Please i hope someone transform it to a functional programming code.
thanks
zak


  • Prev by Date: Re: symbolic matrix calculation doesn't work
  • Next by Date: Re: Adding new rules to Simplify
  • Previous by thread: Re: Working with huge text files with mathematica
  • Next by thread: Re: simplifying ulam spiral code