[pstricks] Sieve

David Arnold dwarnold45 at suddenlink.net
Wed May 27 20:49:41 CEST 2009


Wow!

D.

On May 27, 2009, at 11:36 AM, Herbert Voss wrote:

> David Arnold schrieb:
>> Nice solution. I wound up with following. Brute force, but it worked.
>
> you can calculate anything in PS ...
>
> Herbert
>
> \documentclass{article}
> \usepackage{pstricks-add}
> \begin{document}
>
> \pstVerb{
> /prime? {
>  /n exch def
>  n 1 eq {false} { % 1 is not prime
>    n 2 mod 0 eq {n 2 eq} {
>      /divide? false def
>      3 2 n sqrt {
>        n exch div dup ceiling eq {/divide? true def exit} if
>      } for
>      divide? not } ifelse } ifelse
> } bind def
> }
> \makeatletter
> \begin{pspicture}(0,0)(10,-10)
> \psgrid[subgriddiv=1,gridlabels=0pt]
> \multido{\iA=2+1}{99}{%
>  \rput(! \iA\space 2 sub 10 mod /xVal ED
>          \iA\space 2 sub 10 div cvi neg /yVal ED
>          \iA\space prime? not {
>            gsave xVal yVal \tx at ScreenCoor translate
>            0 0 moveto 1 -1 \tx at ScreenCoor lineto
>            0 -1 \tx at ScreenCoor moveto 1 0 \tx at ScreenCoor lineto
>            1 setlinewidth 1 0 0 setrgbcolor stroke grestore } if
>          xVal 0.5 add yVal 0.5 sub ){\iA}}
> \end{pspicture}
>
> \end{document}
>
>
> Herbert
>
> _______________________________________________
> PSTricks mailing list
> PSTricks at tug.org
> http://tug.org/mailman/listinfo/pstricks



More information about the PSTricks mailing list