MathGroup Archive 2005

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

Search the Archive

Re: simplifying ulam spiral code

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56419] Re: [mg56394] simplifying ulam spiral code
  • From: DrBob <drbob at bigfoot.com>
  • Date: Sun, 24 Apr 2005 03:29:16 -0400 (EDT)
  • References: <200504230516.BAA03185@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

I wouldn't call this "functional", but it's an improvement:

x = 0;
test = list = First@Last@Reap@
             While[(shift = 1 - 2x; num = shift(shift - 1)) â?¤ 20000,
               Do[PrimeQ[i] && Sow@{x +
                   i - num, x}, {i, num + 1, num + shift}];
               num = shift^2;
               Do[PrimeQ[
               i] && Sow@{x + shift, x + i - num}, {i, num + 1, num + shift}];
               num = shift(shift + 1);
               Do[PrimeQ[i] && Sow@{x + shift - i + num, x +
               shift}, {i, num + 1, num + shift + 1}];
               num = (shift + 1)^2;
               Do[PrimeQ[i] && Sow@{x - 1, x + shift - i + num}, {i, num +
                 1, num + shift + 1}];
               x--];
ListPlot[list, PlotStyle -> PointSize[
               0.007], AspectRatio -> Automatic, Axes -> True];

Bobby

On Sat, 23 Apr 2005 01:16:49 -0400 (EDT), zak <chocolatez at gmail.com> wrote:

> 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
>
>
>
>



-- 
DrBob at bigfoot.com


  • Prev by Date: Re: simplifying ulam spiral code
  • Next by Date: Re: simplifying ulam spiral code
  • Previous by thread: simplifying ulam spiral code
  • Next by thread: Re: simplifying ulam spiral code