<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>

		<title>jtolds.com</title>
		<link>http://www.jtolds.com/</link>
		<description>JT Olds' RSS Feed</description>

		<language>en-us</language>
		<copyright>Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License</copyright>

<item>
	<title><![CDATA[More TV]]></title>
	<author>JT Olds</author>

	<link><![CDATA[http://www.jtolds.com/newsletter/2008/12/19/more-tv]]></link>

	<guid>1229662461</guid>
	<pubDate>Fri, 19 Dec 2008 04:54:21 +0000</pubDate>
	<description><![CDATA[<p>Haha, I just found episodes of a TV show I grew up watching. I love <a href="http://en.wikipedia.org/wiki/Cro">this show</a>.</p>

<ul><li><a href="http://www.youtube.com/watch?v=gkX1MlIpkZY">Cro - Lever In A Million Years, Part 1</a></li>
<li><a href="http://www.youtube.com/watch?v=105Pj89xE9E">Cro - Lever In A Million Years, Part 2</a></li>
<li><a href="http://www.youtube.com/watch?v=_DiRK9c4ni4">Cro - Lever In A Million Years, Part 3</a></li>
</ul><ul>
<li><a href="http://www.youtube.com/watch?v=leGZc-S4frY">Cro - Play It Again, Cro... NOT! Part 1</a></li>
<li><a href="http://www.youtube.com/watch?v=n42yfnrXBoM">Cro - Play It Again, Cro... NOT! Part 2</a></li>
<li><a href="http://www.youtube.com/watch?v=wBd6zj48YJc">Cro - Play It Again, Cro... NOT! Part 3</a></li>
</ul>
]]></description>
</item>

<item>
	<title><![CDATA[Chuck]]></title>
	<author>JT Olds</author>

	<link><![CDATA[http://www.jtolds.com/newsletter/2008/12/10/chuck]]></link>

	<guid>1228877245</guid>
	<pubDate>Wed, 10 Dec 2008 02:47:25 +0000</pubDate>
	<description><![CDATA[<p>I have a confession to make. Over the past few weeks, maybe actually over the past month or so, I have gotten incredibly hooked on the TV show <a href="http://www.hulu.com/chuck">Chuck</a>.</p>

<p>Now, I have to say, it's not that great of a show. In fact, some of the plot and character developments are downright terrible. As my friend Zach put it, the eponymous character is really more of a cartoon: incredibly one dimensional.</p>

<p>I don't want to say that it's anywhere near National Treasure as far as believability goes (because I can't stand National Treasure for the same reason), but it might be in the same order of magnitude. I think that says something.</p>

<p>Here's the kicker: boy am I hooked. I've watched every episode released so far. And the reason I bring this up is two-fold:</p>

<ol><li><a href="http://www.hulu.com/">Hulu</a> is amazing. I have seen the future of TV, and it's here. <a href="http://www.hulu.com/">Hulu</a>, <a href="http://www.sling.com/">Sling</a>, <a href="http://www.roku.com/">Roku</a>,  <a href="http://www.boxee.tv/">Boxee</a>, <a href="http://www.lala.com/">Lala</a>, <a href="http://www.pandora.com/">Pandora</a>, <a href="http://listen.grooveshark.com/">Grooveshark</a>, all of these services are spelling the end of traditional broadcast mediums. Forget about radio, cable, or satellite TV; don't worry about the new DTV upgrade this February. Just make sure you have broadband: the media of the future will stream over <a href="http://en.wikipedia.org/wiki/Transmission_Control_Protocol">TCP/IP</a>.</li>

<li>My life is so boring. What an awesome TV show. Like seriously, what am I doing with my life? :( I'm having a quarter-life crisis or something over here, all because of an unbelievable spy show. Also unbelievably awesome, but mostly unbelievable. I've totally lost interest in personal projects in favor of figuring out how to get into Stanford so I can be recruited by the CIA.</li>

</ol>]]></description>
</item>

<item>
	<title><![CDATA[Okay, let's get this straight]]></title>
	<author>JT Olds</author>

	<link><![CDATA[http://www.jtolds.com/newsletter/2008/12/4/okay-lets-get-this-straight]]></link>

	<guid>1228430780</guid>
	<pubDate>Thu, 4 Dec 2008 22:46:20 +0000</pubDate>
	<description><![CDATA[<p>Today, the tech news world is freaking out over two announcements:</p>
<ol><li>Google released <a href="http://www.google.com/friendconnect/">Friend Connect</a>, which is a way for web developers to "sprinkle" their existing sites with social features.</li>
<li>Facebook released <a href="http://developers.facebook.com/connect.php">Facebook Connect</a>, which is a way for web developers to allow users to log in to their existing sites using Facebook credentials.</li>
</ol>

<p>Now, admittedly, there is a lot of overlap here, but let's get one thing straight. These are not direct competitors. TechCrunch says "it's mano-a-mano." <i>Please.</i> Give me a break. They have very different feature sets.</p>

<p>I've looked at both sites for all of 5 minutes (and enough to enable some Friend Connect features <a href="/newsletter/2008/12/4/google-friend-connect">on my own site</a>), and they're not even all that subtly different.</p>

<p>Facebook Connect is a clear competitor to <a href="http://openid.net/">OpenID</a>. Both are attempting to solve the user-credential nightmare. Facebook Connect also has features such that you can post some of your actions on the site back to Facebook (and have it show up in your minifeed, say).</p>

<p>Google Friend Connect is a not-so-clear competitor to Facebook itself. Instead of trying to tie websites in to the existing Facebook platform, which web developers will subconsciously fight (who wants to move their content inside of Facebook when it's already free from their walled garden?), Friend Connect allows developers to put widgets on their existing pages. Users can log in or not, but now web developers can drop in a Facebook-wall like feature on any of their <i>own</i> pages (not Facebook's pages), and even allow anonymous posts. Friend Connect clearly has an emphasis on hosting social widgets and making social website features a breeze for existing sites.</p>

<p>Now, it's true that both products' feature sets will probably begin to converge, but right now? At release? Not the case. Facebook Connect is an authentication platform with some pizazz. Friend Connect is Facebook for the rest of the web.</p>]]></description>
</item>

<item>
	<title><![CDATA[Google Friend Connect]]></title>
	<author>JT Olds</author>

	<link><![CDATA[http://www.jtolds.com/newsletter/2008/12/4/google-friend-connect]]></link>

	<guid>1228426931</guid>
	<pubDate>Thu, 4 Dec 2008 21:42:11 +0000</pubDate>
	<description><![CDATA[<p>My website now uses <a href="http://www.google.com/friendconnect/">Google Friend Connect</a> to manage comments on selected posts.</p>

<p>You may have noticed earlier this month that I turned on comments for a few newsletter entries using <a href="http://js-kit.com/">JS-Kit</a>. Now, I've moved that all over to Friend Connect, which launched today.</p>

<p>If you didn't notice the JS-Kit business earlier, yes, now on some of my newsletter entries you can leave comments. I pick the ones on which I feel like allowing comments. :P</p>

<p>Specifically, I've enabled comments on this entry so you can try it out if you want.</p>

<p><i><b>Update:</b> stupidly, it looks like I don't get email notifications when comments are left, so I may be slow at getting back to you. Or just switch back to JS-Kit.</i></p>]]></description>
</item>

<item>
	<title><![CDATA[Back the F:\ up!]]></title>
	<author>JT Olds</author>

	<link><![CDATA[http://www.jtolds.com/newsletter/2008/12/2/back-the-f-up]]></link>

	<guid>1228238784</guid>
	<pubDate>Tue, 2 Dec 2008 17:26:24 +0000</pubDate>
	<description><![CDATA[<p><b>Hard drive primer</b></p>

<p>First, a bit about how hard drives work.</p>

<p>A hard drive is simply a circular disk (or a collection of them), kind of like a CD, except the data is stored magnetically instead of optically. To read the magnetic data, a little arm with a magnet on the end sticks out over the disk while the disk spins. The little arm reads data off the disk as the disk spin past.</p>

<p>The disk is moving <i>very</i> fast (common disks spin at 7,200 rpm, or about 86 miles per hour at the edge of a 3.5" disk). The arm is also <i>very</i> close to the disk (the head of the arm is 3-7 millionths of an inch away from the disk in modern drives, floating on a pocket of air). Scaled up, hard drives move at speeds similar to an airplane traveling nearly 16 times the speed of sound (mach 16) a width of a human hair (18 micrometers) above the ground!</p>

<p>So, as you can imagine, the worst thing that could possibly happen to a hard drive is for this drive head to crash into the disk, <i>destroying</i> your ability to read the data and scratching up the disk platter. I suppose it's worse if you shoot the drive with a shotgun.</p>

<p><i>But only barely.</i></p>

<p>It's very hard for hard drive manufacturers to make disks that don't crash when they're dropped while spinning. They try, but it's just hard to do. Recent laptop drives have gone as far as putting motion detection in so the drive head can be locked away from the disk platter if the drive detects that it's falling. Laptop makers generally recommend that you keep your laptop off (thereby locking the disk head) during any traveling. I sort of think that's silly though. What's the point of a laptop?</p>

<p><b>Calamity!</b></p>

<p>So, this week, my sister's laptop suffered an untimely and completely accidental calamity. As the laptop hit the ground, I thought, "boy, it's a good thing it's off."</p>

<p>It wasn't.</p>

<p>Then I thought, "boy, it's a good thing her brother <a href="http://www.mozy.com/">works for a backup company</a> and backed up all her homework for her."</p>

<p>I didn't.</p>

<p>I mean, I work for <a href="http://www.mozy.com/">Mozy</a>, but I'm one of those crazy <a href="http://en.wikipedia.org/wiki/Linux">Linux</a> guys, and Mozy currently doesn't have a Linux client. As a result, I don't use Mozy on my own laptop, and therefore often forget to recommend it to others. I'm a big fan of the adage "practice what you preach;" in this case, I argue software companies should eat their own dogfood and use their own products. Whoops! I guess I'm the odd man out here. I am totally practicing some of the things I'm preaching already: building incredibly distributed, fault tolerant, relational metadata management systems to increase performance for Mozy's backend is fun! But I haven't been practicing or preaching "<a href="http://backthefup.net/">Back the F:\ up!</a>".</p>

<p>Well, this week, that changed. Be safe, use <a href="http://www.mozy.com/">Mozy</a>.</p>]]></description>
</item>

<item>
	<title><![CDATA[Pre-cooked bacon?!?]]></title>
	<author>JT Olds</author>

	<link><![CDATA[http://www.jtolds.com/newsletter/2008/11/27/pre-cooked-bacon]]></link>

	<guid>1227810534</guid>
	<pubDate>Thu, 27 Nov 2008 18:28:54 +0000</pubDate>
	<description><![CDATA[<p>Oh my goodness. How I have lived my life without this?</p>

<p>Seriously, pre-cooked bacon? Either I blacked out due to the awesomeness last time I heard about this, or I have somehow never heard about this in my life.</p>

<p>I'm going to have to rebudget my monthly expenses now.</p>]]></description>
</item>

<item>
	<title><![CDATA[Crazy Dream]]></title>
	<author>JT Olds</author>

	<link><![CDATA[http://www.jtolds.com/newsletter/2008/11/21/crazy-dream]]></link>

	<guid>1227250421</guid>
	<pubDate>Fri, 21 Nov 2008 06:53:41 +0000</pubDate>
	<description><![CDATA[<p>I just wanted to quickly share a book cover from a dream I had a few nights ago that I attempted to reconstruct as best I could. All I can say is that, evidently, the war in Iraq had a pretty seriously good reason: dinosaurs aren't extinct and it's been a massive government cover-up. Or so I tell myself while sleeping.</p>

<p><img src="/newsletter/images/spontaneous_raptors.jpg" alt="Dr. Andrew Weil's Spontaneous Raptor Attacks"/><br/>Yes, I seriously dreamed this.</p>

<p>Dr. Weil's advice was to wear white, not to avoid the raptors, but to assist doctors in quickly locating the inevitable flesh wounds.</p>]]></description>
</item>

<item>
	<title><![CDATA[Erdos number idea]]></title>
	<author>JT Olds</author>

	<link><![CDATA[http://www.jtolds.com/newsletter/2008/11/8/erdos-number-idea]]></link>

	<guid>1226131038</guid>
	<pubDate>Sat, 8 Nov 2008 07:57:18 +0000</pubDate>
	<description><![CDATA[<p>One of the ways to know how high up on the famous-mathematician ladder you are is to calculate your <a href="http://en.wikipedia.org/wiki/Erd%C5%91s_number">Erdos number</a>. <a href="http://en.wikipedia.org/wiki/Paul_Erd%C5%91s">Paul Erdos</a> was certainly very prolific. It's basically a game of <a href="http://en.wikipedia.org/wiki/Bacon_number">six degrees of Kevin Bacon</a>, but played with math papers, instead of movies, and Paul Erdos, instead of Kevin Bacon.</p><p>What's interesting (or not, if you realize the ubiquity of <a href="http://en.wikipedia.org/wiki/Small-world_network">small-world networks</a>), is that the median Erdos number is just 5. What's even more interesting is that, according to the <a href="http://www.oakland.edu/enp/trivia.html">Erdos number project</a>, the highest finite Erdos number is 13, with only 5 people in that state!</p><p>So, here's a more interesting game to me. Obviously I can't get an Erdos number of 1 (Paul Erdos is no longer among the living), and I suppose if I really dedicated my academic life to such a pursuit, I could probably reach some similarly low number. However, my interest sort of tapers off near the median (5), since that's common. What would be better is to be the 1 person with an Erdos number of 14! So, I need to write a paper with one of the 5 people that have an Erdos number of 13. More importantly, once I do, I can't screw it up by writing any papers with anyone else. Furthermore, I should probably choose the least likely of those 5 people to write more papers. I suppose I still have the problem in which any sub-path in the supposed full path from me to Erdos might collapse into a smaller path at any time. Hmm.</p><p>On a slightly related note, another interesting dimension is the intersection of the <a href="http://en.wikipedia.org/wiki/Erd%C5%91s-Bacon_number">Erdos number and the Bacon number</a>. The Erdos-Bacon number is the sum of someone's Erdos number and their Bacon number. Evidently the lowest such number is 3. <a href="http://en.wikipedia.org/wiki/Erd%C5%91s-Bacon_number#Methodology">Wikipedia's discussion</a> on how a lower number could be achieved is hilarious. Observe:</p><pre>The only way a lower number could be achieved would be:

    * for an individual who had co-authored an academic paper with Paul Erdos to
      appear in a movie with Kevin Bacon;
    * for Bacon to co-author an academic paper with someone with an Erdos number
      of 1, which would give Bacon an Erdos-Bacon number of 2;
    * for anyone who appeared in the documentary N is a Number along with Erdos
      to appear in a film with Bacon, which would posthumously give Erdos an
      Erdos-Bacon number of 2;
    * for Kevin Bacon to appear in a film that also uses stock footage of Erdos,
      giving Erdos an Erdos-Bacon number of 1;
    * for a heretofore unknown joint academic paper by Bacon and Erdos to be
      published, giving Bacon an Erdos-Bacon number of 1.</pre>]]></description>
</item>

<item>
	<title><![CDATA[Website ported to Google App Engine]]></title>
	<author>JT Olds</author>

	<link><![CDATA[http://www.jtolds.com/newsletter/2008/10/31/website-ported-to-google-app-engine]]></link>

	<guid>1225483780</guid>
	<pubDate>Fri, 31 Oct 2008 20:09:40 +0000</pubDate>
	<description><![CDATA[<p>I just converted my website to Google App Engine (you can tell if any website is running on GAE if the <a href="/form">/form</a> URL returns a Google error). As you may notice, there is now a <a href="/feeds/">feeds</a> page. Furthermore, the categories for my "newsletter" are now more useful. A newsletter entry can be in more than one category, and there is an RSS feed for each category. So, if, say, you want to subscribe to my website's feeds about <a href="/newsletter/category/math">math</a> and <a href="/newsletter/category/programming">programming</a> but not <a href="/newsletter/category/politics">politics</a>, you are now able to do so.</p>
]]></description>
</item>

<item>
	<title><![CDATA[Primes]]></title>
	<author>JT Olds</author>

	<link><![CDATA[http://www.jtolds.com/newsletter/2008/10/7/primes]]></link>

	<guid>1223419334</guid>
	<pubDate>Tue, 7 Oct 2008 22:42:14 +0000</pubDate>
	<description><![CDATA[<i><b>Update:</b> oh my goodness. Had I just checked the Wikipedia's entry on <a href="http://en.wikipedia.org/wiki/Prime_number">Prime numbers</a>, I would have been reminded of fundamental things like the <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes">Sieve of Eratosthenes</a> (which I of course forgot the name of, but the idea is featured prominently in my parallel algorithm, mentioned at the end of this post) and <a href="http://en.wikipedia.org/wiki/Sieve_of_Atkin">newer improvements</a>, along with a <a href="http://en.wikipedia.org/wiki/Prime_gap">ton</a> <a href="http://en.wikipedia.org/wiki/Formula_for_primes">of</a> <a href="http://en.wikipedia.org/wiki/Primality_test">other</a> <a href="http://en.wikipedia.org/wiki/Prime-counting_function">incredibly</a> <a href="http://en.wikipedia.org/wiki/Prime_number_theorem">interesting</a> <a href="http://en.wikipedia.org/wiki/Perfect_number#Even_perfect_numbers">facts</a>, and even <a href="http://en.wikipedia.org/wiki/Image:PrimeNumbersSmall.png">a prime distribution graph</a>! Wikipedia: +1, JT: 0</i><br/>
<br/>
In my static analysis meeting, my professor noted that indexing objects with primes led to an easy set representation scheme, in which a set is simply the product of the prime indices of the objects in that set. I thought this was pretty fascinating. I started wondering about the constraints involved in implementing such a scheme, and inevitably this led to rather worthless homework procrastination that I thought I'd share here.<br/>
<br/>
First, I was curious about prime number distribution over the integers. I made a graph.<br/>
<img src="/newsletter/images/primes.png" alt="prime number distribution"/><br/>
So, how to read the graph. At a given point X on the X-axis, there are Y-many prime numbers within a diameter of 100,000 around X. In other words, it's a histogram of all primes below 1 billion, displayed with 10,000 buckets.<br/>
<br/>
Second (but really a prerequisite to the first), I wrote a program to quickly generate as many prime numbers as possible.<br/>
<style type="text/css"><!-- /**  * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann  * (http://qbnz.com/highlighter/ and http://geshi.org/)  */ .cpp.cpp .de1, .cpp.cpp .de2 {font-family: monospace; font-weight: normal; font-style: normal; margin:0; padding:0; background:inherit;color: #000020;} .cpp.cpp  {font-family:monospace;color: #006; border: 1px solid #d0d0d0; background-color: #f0f0f0; font-size: 10px; padding-left: 20px;} .cpp.cpp a:link {color: #000060;} .cpp.cpp a:hover {background-color: #f0f000;} .cpp.cpp .imp {font-weight: bold; color: red;} .cpp.cpp li, .cpp.cpp .li1 {font-weight: normal;font: normal normal 130% 'Courier New', Courier, monospace; color: #003030;} .cpp.cpp .ln {width:1px;font-weight: normal;text-align:right;margin:0;padding:0 2px;} .cpp.cpp .li2 {font-weight: bold;font-weight: bold; color: #006060;} .cpp.cpp .kw1 {color: #0000ff;} .cpp.cpp .kw2 {color: #0000ff;} .cpp.cpp .kw3 {color: #0000dd;} .cpp.cpp .kw4 {color: #0000ff;} .cpp.cpp .co1 {color: #666666;} .cpp.cpp .co2 {color: #339900;} .cpp.cpp .coMULTI {color: #ff0000; font-style: italic;} .cpp.cpp .es_h {color: #666666; font-weight: bold;} .cpp.cpp .br0 {color: #008000;} .cpp.cpp .sy0 {color: #008000;} .cpp.cpp .sy1 {color: #000080;} .cpp.cpp .sy2 {color: #000040;} .cpp.cpp .sy3 {color: #000040;} .cpp.cpp .sy4 {color: #008080;} .cpp.cpp .st0 {color: #FF0000;} .cpp.cpp .nu0 {color: #0000dd;} .cpp.cpp .nu6 {color: #208080;} .cpp.cpp .nu8 {color: #208080;} .cpp.cpp .nu12 {color: #208080;} .cpp.cpp .nu16 {color:#800080;} .cpp.cpp .nu17 {color:#800080;} .cpp.cpp .nu18 {color:#800080;} .cpp.cpp .nu19 {color:#800080;} .cpp.cpp .me1 {color: #007788;} .cpp.cpp .me2 {color: #007788;} .cpp.cpp span.xtra { display:block; }  --!></style><div class="cpp cpp" style="font-family:monospace;color: #006; border: 1px solid #d0d0d0; background-color: #f0f0f0;"><ol><li class="li1"><div class="de1"><span class="co2">#include &lt;iostream&gt;</span></div></li> <li class="li1"><div class="de1"><span class="co2">#include &lt;list&gt;</span></div></li> <li class="li1"><div class="de1"><span class="co2">#include &lt;math.h&gt;</span></div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li2"><div class="de2"><span class="kw2">using</span> <span class="kw2">namespace</span> std;</div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li1"><div class="de1"><span class="co1">// this program finds all primes &lt;= 1 billion and notes if they are twin primes</span></div></li> <li class="li1"><div class="de1"><span class="co1">// or mersenne primes.</span></div></li> <li class="li1"><div class="de1"><span class="co1">// compile with (on JT's machine):</span></div></li> <li class="li2"><div class="de2"><span class="co1">// g++ -O3 -march=nocona -funroll-loops -fomit-frame-pointer -o primes primes.cpp</span></div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li1"><div class="de1"><span class="kw2">inline</span> <span class="kw4">bool</span> is_mersenne<span class="br0">&#40;</span><span class="kw4">int</span> val<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="co1">// so, ((x - 1) &amp; x) is 0 iff x is a power of 2. See</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="co1">// http://www.cprogramming.com/tutorial/powtwosol.html for a good</span></div></li> <li class="li2"><div class="de2">&nbsp; &nbsp; <span class="co1">// explanation of why.</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="co1">// since a mersenne number should be of the form 2^n - 1,</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="co1">// (x &amp; (x + 1)) is 0 iff x is of form 2^n - 1.</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="sy3">!</span><span class="br0">&#40;</span>val <span class="sy3">&amp;</span> <span class="br0">&#40;</span>val <span class="sy2">+</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div></li> <li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li> <li class="li2"><div class="de2">&nbsp;</div></li> <li class="li1"><div class="de1"><span class="kw4">int</span> main<span class="br0">&#40;</span><span class="kw4">int</span> argc, <span class="kw4">char</span><span class="sy2">**</span> argv<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="co1">// strategy: as we calculate primes, we store previous primes so we only</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="co1">// have to check divisibility by known primes to know if a new number is</span></div></li> <li class="li2"><div class="de2">&nbsp; &nbsp; <span class="co1">// prime.</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; list<span class="sy1">&lt;</span><span class="kw4">int</span><span class="sy1">&gt;</span> primes;</div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="co1">// largest_number is the largest number we will check for primeness</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="kw4">int</span> largest_number <span class="sy1">=</span> <span class="nu0">1000000000</span>; <span class="co1">// 1,000,000,000</span></div></li> <li class="li2"><div class="de2">&nbsp;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="co1">// we use last_prime to keep track of if the last number we checked was</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="co1">// prime. this way determining twin primes is easy.</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="kw4">bool</span> last_prime <span class="sy1">=</span> <span class="kw2">true</span>;</div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li2"><div class="de2">&nbsp; &nbsp; <span class="co1">// book keeping</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="kw4">bool</span> factor_found;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="kw4">int</span> sqrt_i;</div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="co1">// we start with 3, because 3 and every prime after is odd, so we can</span></div></li> <li class="li2"><div class="de2">&nbsp; &nbsp; <span class="co1">// increment by 2.</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; primes.<span class="me1">push_back</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span>;</div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="co1">// we don't check divisibility by 1, since that's always true, but we output</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="co1">// it and 2 as primes.</span></div></li> <li class="li2"><div class="de2">&nbsp; &nbsp; <span class="kw3">cout</span> <span class="sy1">&lt;&lt;</span> <span class="nu0">1</span> <span class="sy1">&lt;&lt;</span> endl <span class="sy1">&lt;&lt;</span> <span class="nu0">2</span> <span class="sy1">&lt;&lt;</span> endl;</div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="co1">// check all odd numbers starting with 3 until the largest number</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw4">int</span> i <span class="sy1">=</span> <span class="nu0">3</span>; i <span class="sy1">&lt;=</span> largest_number; i <span class="sy2">+</span><span class="sy1">=</span> <span class="nu0">2</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li2"><div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// no factor found yet.</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; factor_found <span class="sy1">=</span> <span class="kw2">false</span>;</div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// store the square root of the number we're checking. we only need to</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// check up to the square root.</span></div></li> <li class="li2"><div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; sqrt_i <span class="sy1">=</span> <span class="kw3">sqrt</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>;</div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// iterate over previously calculated primes up to the square root of</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// the current number. note that we don't have to check if the iterator</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// is primes.end() because there is empirically always a prime stored</span></div></li> <li class="li2"><div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// greater than the square root of the number we're checking. i wonder</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// if there's a proof there. it would probably be of the form of proving</span></div></li><li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// that for a given integer i, a prime p exists such that i &lt;= p &lt; i^2</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span>list<span class="sy1">&lt;</span><span class="kw4">int</span><span class="sy1">&gt;</span><span class="sy4">::</span><span class="me2">iterator</span> it<span class="br0">&#40;</span>primes.<span class="me1">begin</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>; <span class="sy2">*</span>it <span class="sy1">&lt;=</span> sqrt_i; <span class="sy2">++</span>it<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li2"><div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// if the current number mod the current prime is 0, we found a</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// factor. not prime, break out.</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>i <span class="sy2">%</span> <span class="sy2">*</span>it <span class="sy1">==</span> <span class="nu19">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; factor_found <span class="sy1">=</span> <span class="kw2">true</span>;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div></li> <li class="li2"><div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="sy3">!</span>factor_found<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li> <li class="li2"><div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// no factor found! this is a prime. store it.</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; primes.<span class="me1">push_back</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>;</div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// output the prime</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">cout</span> <span class="sy1">&lt;&lt;</span> i;</div></li> <li class="li2"><div class="de2">&nbsp;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// is it a twin prime? (p, p+2)</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>last_prime<span class="br0">&#41;</span> <span class="kw3">cout</span> <span class="sy1">&lt;&lt;</span> <span class="st0">&quot; *&quot;</span>;</div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// is it a mersenne prime? (2^n-1)</span></div></li> <li class="li2"><div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>is_mersenne<span class="br0">&#40;</span>i<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw3">cout</span> <span class="sy1">&lt;&lt;</span> <span class="st0">&quot; +&quot;</span>;</div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">cout</span> <span class="sy1">&lt;&lt;</span> endl;</div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// keep track of if the last number was prime.</span></div></li> <li class="li2"><div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; last_prime <span class="sy1">=</span> <span class="kw2">true</span>;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span></div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; last_prime <span class="sy1">=</span> <span class="kw2">false</span>;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li2"><div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div></li> <li class="li1"><div class="de1">&nbsp;</div></li> <li class="li1"><div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="nu19">0</span>;</div></li> <li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li> </ol></div><br/>
Third, I think I've figured out a pretty clever algorithm for parallelizing the computation of primes. I was inspired by <a href="http://en.wikipedia.org/wiki/Software_pipelining">software pipelining</a>. I hope to actually write up the algorithm to check its effectiveness. I'll post it here if/when I do. Stay tuned.]]></description>
</item>

	</channel>
</rss>
