[pstricks] Sieve

Thomas Glass walkinn at gmail.com
Thu May 28 20:32:20 CEST 2009


Wow.

2009/5/27 Herbert Voss <Herbert.Voss at fu-berlin.de>

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/pstricks/attachments/20090528/2a81dda1/attachment.html>


More information about the PSTricks mailing list