Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: simplifying ulam spiral code

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56478] Re: simplifying ulam spiral code
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Tue, 26 Apr 2005 21:52:33 -0400 (EDT)
  • Organization: The University of Western Australia
  • References: <d4cmlr$39e$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Further to my previous message, improved code for Ulam's spiral appeared 
in the third issue of The Mathematica Journal, 1(3): 57 (1991). It used

  IntegerSpiral[n_] := {Re[#],Im[#]}& /@ 
    Fold[Join[#1, Last[#1]+I^#2 Range[#2/2]]&, {0}, Range[n]]

and explained that 

the idea is that the length of the limbs of the spiral follow the 
pattern 1,1,2,2,3,3,4,4,5,5,... and that each limb is at a 90 degree 
angle to the previous limb (multiplication by I in the complex plane). 
This is also a nontrivial use of Fold in the sense that the second 
argument to Fold is really used. 

Also, instead of using Pick, to select those points that have prime 
index from, say

 spiral = IntegerSpiral[60];

one can use

  primes = spiral[[ Prime[Range[PrimePi[Length[spiral]]]] ]];

Cheers,
Paul

-- 
Paul Abbott                                   Phone: +61 8 6488 2734
School of Physics, M013                         Fax: +61 8 6488 1014
The University of Western Australia      (CRICOS Provider No 00126G)         
35 Stirling Highway
Crawley WA 6009                      mailto:paul at physics.uwa.edu.au 
AUSTRALIA                            http://physics.uwa.edu.au/~paul


  • Prev by Date: Converting a mapping into a well-defined function
  • Next by Date: Re: odd mathematica blindspot
  • Previous by thread: Re: Re: simplifying ulam spiral code
  • Next by thread: Re: simplifying ulam spiral code