<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" id="owaParaStyle"></style>
</head>
<body fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">
<pre><font color="#666666"><i>Hello</i></font></pre>
<pre><font color="#666666"><i>I would like to know if there is a way to compute the Sieve of erastothenes with pure data </i></font></pre>
<pre><font color="#666666"><i>and spit out numbers which can be used for MIDI notes.</i></font></pre>
<pre><font color="#666666"><i>There used to be a simple unix program that i used but it no longer is available.</i></font></pre>
<pre><font color="#666666"><i>Has anyone tried this with pd? I found some Java code for it.</i></font></pre>
<pre><font color="#666666"><i><br></i></font></pre>
<pre><font color="#666666"><i>pp</i></font></pre>
<pre style="color: rgb(0, 0, 15);"><tt><span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"><br></span></tt></pre>
<pre style="color: rgb(0, 0, 15);"><tt><span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"><br class="Apple-interchange-newline">/*************************************************************************</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *  Compilation:  javac PrimeSieve.java</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *  Execution:    java -Xmx1100m PrimeSieve N</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *  </span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *  Computes the number of primes less than or equal to N using</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *  the Sieve of Eratosthenes.</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *  % java PrimeSieve 25</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *  The number of primes <= 25 is 9</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *  % java PrimeSieve 100</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *  The number of primes <= 100 is 25</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *  % java -Xmx100m PrimeSieve 100000000</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *  The number of primes <= 100000000 is 5761455</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *  % java PrimeSieve -Xmx1100m 1000000000 </span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *  The number of primes <= 1000000000 is 50847534</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> * </span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *  The 110MB and 1100MB is the amount of memory you want to allocate</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *  to the program. If your computer has less, make this number smaller,</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *  but it may prevent you from solving the problem for very large</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *  values of N.</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *                  N     Primes <= N</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *  ---------------------------------</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *                 10               4   </span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *                100              25  </span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *              1,000             168  </span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *             10,000           1,229  </span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *            100,000           9,592  </span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *          1,000,000          78,498  </span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *         10,000,000         664,579  </span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *        100,000,000       5,761,455  </span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *      1,000,000,000      50,847,534  </span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *</span>
<span class="comment" style="color: rgb(102, 102, 102); font-style: italic;"> *************************************************************************/</span>


<span class="keyword" style="color: rgb(0, 102, 204);">public</span><span class="normal"> </span><span class="keyword" style="color: rgb(0, 102, 204);">class</span><span class="normal"> PrimeSieve </span><span class="cbracket">{</span>
<span class="normal">    </span><span class="keyword" style="color: rgb(0, 102, 204);">public</span><span class="normal"> </span><span class="keyword" style="color: rgb(0, 102, 204);">static</span><span class="normal"> </span><span class="type" style="color: rgb(0, 102, 204);">void</span><span class="normal"> </span><span class="function" style="font-weight: bold;">main</span><span class="symbol" style="color: rgb(139, 0, 0);">(</span><span class="normal">String</span><span class="symbol" style="color: rgb(139, 0, 0);">[]</span><span class="normal"> args</span><span class="symbol" style="color: rgb(139, 0, 0);">)</span><span class="normal"> </span><span class="cbracket">{</span><span class="normal"> </span>
<span class="normal">        </span><span class="type" style="color: rgb(0, 102, 204);">int</span><span class="normal"> N </span><span class="symbol" style="color: rgb(139, 0, 0);">=</span><span class="normal"> Integer</span><span class="symbol" style="color: rgb(139, 0, 0);">.</span><span class="function" style="font-weight: bold;">parseInt</span><span class="symbol" style="color: rgb(139, 0, 0);">(</span><span class="normal">args</span><span class="symbol" style="color: rgb(139, 0, 0);">[</span><span class="number" style="color: purple;">0</span><span class="symbol" style="color: rgb(139, 0, 0);">]);</span>

<span class="normal">        </span><span class="comment" style="color: rgb(102, 102, 102); font-style: italic;">// initially assume all integers are prime</span>
<span class="normal">        </span><span class="type" style="color: rgb(0, 102, 204);">boolean</span><span class="symbol" style="color: rgb(139, 0, 0);">[]</span><span class="normal"> isPrime </span><span class="symbol" style="color: rgb(139, 0, 0);">=</span><span class="normal"> </span><span class="keyword" style="color: rgb(0, 102, 204);">new</span><span class="normal"> </span><span class="type" style="color: rgb(0, 102, 204);">boolean</span><span class="symbol" style="color: rgb(139, 0, 0);">[</span><span class="normal">N </span><span class="symbol" style="color: rgb(139, 0, 0);">+</span><span class="normal"> </span><span class="number" style="color: purple;">1</span><span class="symbol" style="color: rgb(139, 0, 0);">];</span>
<span class="normal">        </span><span class="keyword" style="color: rgb(0, 102, 204);">for</span><span class="normal"> </span><span class="symbol" style="color: rgb(139, 0, 0);">(</span><span class="type" style="color: rgb(0, 102, 204);">int</span><span class="normal"> i </span><span class="symbol" style="color: rgb(139, 0, 0);">=</span><span class="normal"> </span><span class="number" style="color: purple;">2</span><span class="symbol" style="color: rgb(139, 0, 0);">;</span><span class="normal"> i </span><span class="symbol" style="color: rgb(139, 0, 0);"><=</span><span class="normal"> N</span><span class="symbol" style="color: rgb(139, 0, 0);">;</span><span class="normal"> i</span><span class="symbol" style="color: rgb(139, 0, 0);">++)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">            isPrime</span><span class="symbol" style="color: rgb(139, 0, 0);">[</span><span class="normal">i</span><span class="symbol" style="color: rgb(139, 0, 0);">]</span><span class="normal"> </span><span class="symbol" style="color: rgb(139, 0, 0);">=</span><span class="normal"> </span><span class="keyword" style="color: rgb(0, 102, 204);">true</span><span class="symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="normal">        </span><span class="cbracket">}</span>

<span class="normal">        </span><span class="comment" style="color: rgb(102, 102, 102); font-style: italic;">// mark non-primes <= N using Sieve of Eratosthenes</span>
<span class="normal">        </span><span class="keyword" style="color: rgb(0, 102, 204);">for</span><span class="normal"> </span><span class="symbol" style="color: rgb(139, 0, 0);">(</span><span class="type" style="color: rgb(0, 102, 204);">int</span><span class="normal"> i </span><span class="symbol" style="color: rgb(139, 0, 0);">=</span><span class="normal"> </span><span class="number" style="color: purple;">2</span><span class="symbol" style="color: rgb(139, 0, 0);">;</span><span class="normal"> i</span><span class="symbol" style="color: rgb(139, 0, 0);">*</span><span class="normal">i </span><span class="symbol" style="color: rgb(139, 0, 0);"><=</span><span class="normal"> N</span><span class="symbol" style="color: rgb(139, 0, 0);">;</span><span class="normal"> i</span><span class="symbol" style="color: rgb(139, 0, 0);">++)</span><span class="normal"> </span><span class="cbracket">{</span>

<span class="normal">            </span><span class="comment" style="color: rgb(102, 102, 102); font-style: italic;">// if i is prime, then mark multiples of i as nonprime</span>
<span class="normal">            </span><span class="comment" style="color: rgb(102, 102, 102); font-style: italic;">// suffices to consider mutiples i, i+1, ..., N/i</span>
<span class="normal">            </span><span class="keyword" style="color: rgb(0, 102, 204);">if</span><span class="normal"> </span><span class="symbol" style="color: rgb(139, 0, 0);">(</span><span class="normal">isPrime</span><span class="symbol" style="color: rgb(139, 0, 0);">[</span><span class="normal">i</span><span class="symbol" style="color: rgb(139, 0, 0);">])</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">                </span><span class="keyword" style="color: rgb(0, 102, 204);">for</span><span class="normal"> </span><span class="symbol" style="color: rgb(139, 0, 0);">(</span><span class="type" style="color: rgb(0, 102, 204);">int</span><span class="normal"> j </span><span class="symbol" style="color: rgb(139, 0, 0);">=</span><span class="normal"> i</span><span class="symbol" style="color: rgb(139, 0, 0);">;</span><span class="normal"> i</span><span class="symbol" style="color: rgb(139, 0, 0);">*</span><span class="normal">j </span><span class="symbol" style="color: rgb(139, 0, 0);"><=</span><span class="normal"> N</span><span class="symbol" style="color: rgb(139, 0, 0);">;</span><span class="normal"> j</span><span class="symbol" style="color: rgb(139, 0, 0);">++)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">                    isPrime</span><span class="symbol" style="color: rgb(139, 0, 0);">[</span><span class="normal">i</span><span class="symbol" style="color: rgb(139, 0, 0);">*</span><span class="normal">j</span><span class="symbol" style="color: rgb(139, 0, 0);">]</span><span class="normal"> </span><span class="symbol" style="color: rgb(139, 0, 0);">=</span><span class="normal"> </span><span class="keyword" style="color: rgb(0, 102, 204);">false</span><span class="symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="normal">                </span><span class="cbracket">}</span>
<span class="normal">            </span><span class="cbracket">}</span>
<span class="normal">        </span><span class="cbracket">}</span>

<span class="normal">        </span><span class="comment" style="color: rgb(102, 102, 102); font-style: italic;">// count primes</span>
<span class="normal">        </span><span class="type" style="color: rgb(0, 102, 204);">int</span><span class="normal"> primes </span><span class="symbol" style="color: rgb(139, 0, 0);">=</span><span class="normal"> </span><span class="number" style="color: purple;">0</span><span class="symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="normal">        </span><span class="keyword" style="color: rgb(0, 102, 204);">for</span><span class="normal"> </span><span class="symbol" style="color: rgb(139, 0, 0);">(</span><span class="type" style="color: rgb(0, 102, 204);">int</span><span class="normal"> i </span><span class="symbol" style="color: rgb(139, 0, 0);">=</span><span class="normal"> </span><span class="number" style="color: purple;">2</span><span class="symbol" style="color: rgb(139, 0, 0);">;</span><span class="normal"> i </span><span class="symbol" style="color: rgb(139, 0, 0);"><=</span><span class="normal"> N</span><span class="symbol" style="color: rgb(139, 0, 0);">;</span><span class="normal"> i</span><span class="symbol" style="color: rgb(139, 0, 0);">++)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">            </span><span class="keyword" style="color: rgb(0, 102, 204);">if</span><span class="normal"> </span><span class="symbol" style="color: rgb(139, 0, 0);">(</span><span class="normal">isPrime</span><span class="symbol" style="color: rgb(139, 0, 0);">[</span><span class="normal">i</span><span class="symbol" style="color: rgb(139, 0, 0);">])</span><span class="normal"> primes</span><span class="symbol" style="color: rgb(139, 0, 0);">++;</span>
<span class="normal">        </span><span class="cbracket">}</span>
<span class="normal">        System</span><span class="symbol" style="color: rgb(139, 0, 0);">.</span><span class="normal">out</span><span class="symbol" style="color: rgb(139, 0, 0);">.</span><span class="function" style="font-weight: bold;">println</span><span class="symbol" style="color: rgb(139, 0, 0);">(</span><span class="string" style="color: rgb(17, 102, 17);">"The number of primes <= "</span><span class="normal"> </span><span class="symbol" style="color: rgb(139, 0, 0);">+</span><span class="normal"> N </span><span class="symbol" style="color: rgb(139, 0, 0);">+</span><span class="normal"> </span><span class="string" style="color: rgb(17, 102, 17);">" is "</span><span class="normal"> </span><span class="symbol" style="color: rgb(139, 0, 0);">+</span><span class="normal"> primes</span><span class="symbol" style="color: rgb(139, 0, 0);">);</span>
<span class="normal">    </span><span class="cbracket">}</span>
<span class="cbracket">}</span></tt></pre>
<div><br>
<div style="font-family:Tahoma; font-size:13px">
<div><font size="3"><i>Patrick Pagano B.S, M.F.A</i></font></div>
<div>Audio and Projection Design Faculty</div>
<div>Digital Worlds Institute</div>
<div>University of Florida, USA</div>
<div>(352)294-2020</div>
</div>
</div>
</div>
</body>
</html>