<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Chris Ballance - a blog about stuff - Programming</title>
    <link>http://blog.chrisballance.com/</link>
    <description>The writings of Web Developer - Chris Ballance</description>
    <language>en-us</language>
    <copyright>Chris Ballance</copyright>
    <lastBuildDate>Wed, 25 Aug 2010 01:42:27 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>ballance@gmail.com</managingEditor>
    <webMaster>ballance@gmail.com</webMaster>
    <item>
      <trackback:ping>http://blog.chrisballance.com/Trackback.aspx?guid=1064e09f-87ee-4af8-a2b8-9d7904d91340</trackback:ping>
      <pingback:server>http://blog.chrisballance.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.chrisballance.com/PermaLink,guid,1064e09f-87ee-4af8-a2b8-9d7904d91340.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://blog.chrisballance.com/CommentView,guid,1064e09f-87ee-4af8-a2b8-9d7904d91340.aspx</wfw:comment>
      <wfw:commentRss>http://blog.chrisballance.com/SyndicationService.asmx/GetEntryCommentsRss?guid=1064e09f-87ee-4af8-a2b8-9d7904d91340</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://hotpotato.com">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="spuddies" border="0" alt="spuddies" align="left" src="http://blog.chrisballance.com/content/binary/WindowsLiveWriter/d8d2bb961f4c_120D2/spuddies_3.png" width="240" height="160" />
          </a>With
its acquisition of <a href="http://blog.hotpotato.com/post/982892868/weve-moved-to-facebook" target="_blank">Hot
Potato</a>, Facebook Places follows the footsteps of <a href="http://foursquare.com/user/-22075" target="_blank">Foursquare</a>, <a href="http://gowalla.com/users/ballance" target="_blank">Gowalla</a>,
et al. and makes its foray into location-aware social media.  
</p>
        <p>
Since advertising is part of its core business model, adding the ability to make your
posts geo-aware gives them a strategic advantage in this realm.  
</p>
        <p>
Let’s say you’re checking out a new restaurant this evening.  If you enjoy the
experience, the owners might offer you incentives to return if you checked-in with
Facebook places.  Foursquare has already integrated these sort of incentives
into its service.  
</p>
        <p>
Foodies will love this.  Some time ago I started sharing photos of <a href="http://twitter.com/ballance/status/19928107642" target="_blank">interesting
meals</a> (hat-tip to <a href="http://twitpic.com/2huqcg" target="_blank">Jin Yang</a> for
the idea.)  No doubt, conversations sparked by the post have led to additional
business for the restaurants whose food photographs well.
</p>
        <p>
Unfortunately, Mark Zuckerburg’s egregious ineptitude with anything privacy related
is glaring in the functionality built into Places, specifically its default settings. 
While I’m fairly active on social media, some would say that I’m <a href="http://tweetingtoohard.com/" target="_blank">“Tweeting
too hard.”</a> Places really miffed me with its roll-out reminiscent of <a href="http://mashable.com/2010/02/09/google-buzz/" target="_blank">Google
Buzz</a> when it invades my private email with public status updates.  
</p>
        <p>
The problem is easy enough to reproduce.
</p>
        <ul>
          <li>
Update to the latest version of Facebook Mobile on your device du jour. 
</li>
          <li>
Check-in to any place using Facebook Places (a new icon with a map pin) 
</li>
          <li>
Tag any of your friends, regardless of their privacy settings, and immediately, the
internet knows exactly where you claim they are. 
</li>
        </ul>
        <p>
Why is this a problem?  This person didn’t give you permission to tell the world
that they’re playing hooky from work to spend the day at the beach surfing with you. 
I had a look on the friend’s settings who I tagged in a location and sure enough –
the ability to tag them in Places was NOT enabled.  The circle of friends most
people keep on Facebook is often much broader than anyone should feel comfortable
sharing their location with on a regular basis.
</p>
        <p>
Is this just a simple oversight?  I think not.  It is a shortcut taken to
push the adoption of an add-on to an established service with an established user
base at the expense and disregard of privacy of those users.
</p>
        <p>
So I’m keeping my Foursquare account and will continue to share my location with friends
I know and have explicitly granted access to my location.  Facebook’s offering
needs some work before I’ll take a second look.
</p>
        <img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=1064e09f-87ee-4af8-a2b8-9d7904d91340" />
      </body>
      <title>Oh the places you’ll go</title>
      <guid isPermaLink="false">http://blog.chrisballance.com/PermaLink,guid,1064e09f-87ee-4af8-a2b8-9d7904d91340.aspx</guid>
      <link>http://blog.chrisballance.com/2010/08/25/OhThePlacesYoullGo.aspx</link>
      <pubDate>Wed, 25 Aug 2010 01:42:27 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://hotpotato.com"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="spuddies" border="0" alt="spuddies" align="left" src="http://blog.chrisballance.com/content/binary/WindowsLiveWriter/d8d2bb961f4c_120D2/spuddies_3.png" width="240" height="160" /&gt;&lt;/a&gt;With
its acquisition of &lt;a href="http://blog.hotpotato.com/post/982892868/weve-moved-to-facebook" target="_blank"&gt;Hot
Potato&lt;/a&gt;, Facebook Places follows the footsteps of &lt;a href="http://foursquare.com/user/-22075" target="_blank"&gt;Foursquare&lt;/a&gt;, &lt;a href="http://gowalla.com/users/ballance" target="_blank"&gt;Gowalla&lt;/a&gt;,
et al. and makes its foray into location-aware social media.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
Since advertising is part of its core business model, adding the ability to make your
posts geo-aware gives them a strategic advantage in this realm.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
Let’s say you’re checking out a new restaurant this evening.&amp;#160; If you enjoy the
experience, the owners might offer you incentives to return if you checked-in with
Facebook places.&amp;#160; Foursquare has already integrated these sort of incentives
into its service.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
Foodies will love this.&amp;#160; Some time ago I started sharing photos of &lt;a href="http://twitter.com/ballance/status/19928107642" target="_blank"&gt;interesting
meals&lt;/a&gt; (hat-tip to &lt;a href="http://twitpic.com/2huqcg" target="_blank"&gt;Jin Yang&lt;/a&gt; for
the idea.)&amp;#160; No doubt, conversations sparked by the post have led to additional
business for the restaurants whose food photographs well.
&lt;/p&gt;
&lt;p&gt;
Unfortunately, Mark Zuckerburg’s egregious ineptitude with anything privacy related
is glaring in the functionality built into Places, specifically its default settings.&amp;#160;
While I’m fairly active on social media, some would say that I’m &lt;a href="http://tweetingtoohard.com/" target="_blank"&gt;“Tweeting
too hard.”&lt;/a&gt; Places really miffed me with its roll-out reminiscent of &lt;a href="http://mashable.com/2010/02/09/google-buzz/" target="_blank"&gt;Google
Buzz&lt;/a&gt; when it invades my private email with public status updates.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
The problem is easy enough to reproduce.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Update to the latest version of Facebook Mobile on your device du jour. 
&lt;/li&gt;
&lt;li&gt;
Check-in to any place using Facebook Places (a new icon with a map pin) 
&lt;/li&gt;
&lt;li&gt;
Tag any of your friends, regardless of their privacy settings, and immediately, the
internet knows exactly where you claim they are. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Why is this a problem?&amp;#160; This person didn’t give you permission to tell the world
that they’re playing hooky from work to spend the day at the beach surfing with you.&amp;#160;
I had a look on the friend’s settings who I tagged in a location and sure enough –
the ability to tag them in Places was NOT enabled.&amp;#160; The circle of friends most
people keep on Facebook is often much broader than anyone should feel comfortable
sharing their location with on a regular basis.
&lt;/p&gt;
&lt;p&gt;
Is this just a simple oversight?&amp;#160; I think not.&amp;#160; It is a shortcut taken to
push the adoption of an add-on to an established service with an established user
base at the expense and disregard of privacy of those users.
&lt;/p&gt;
&lt;p&gt;
So I’m keeping my Foursquare account and will continue to share my location with friends
I know and have explicitly granted access to my location.&amp;#160; Facebook’s offering
needs some work before I’ll take a second look.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=1064e09f-87ee-4af8-a2b8-9d7904d91340" /&gt;</description>
      <comments>http://blog.chrisballance.com/CommentView,guid,1064e09f-87ee-4af8-a2b8-9d7904d91340.aspx</comments>
      <category>General</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://blog.chrisballance.com/Trackback.aspx?guid=7e788206-3898-415e-b21e-702f12c5313a</trackback:ping>
      <pingback:server>http://blog.chrisballance.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.chrisballance.com/PermaLink,guid,7e788206-3898-415e-b21e-702f12c5313a.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://blog.chrisballance.com/CommentView,guid,7e788206-3898-415e-b21e-702f12c5313a.aspx</wfw:comment>
      <wfw:commentRss>http://blog.chrisballance.com/SyndicationService.asmx/GetEntryCommentsRss?guid=7e788206-3898-415e-b21e-702f12c5313a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <div class="csharpcode">
          <pre>
            <span class="lnum"> 1: </span>
          </pre>
          <pre>
            <span class="lnum"> 2: </span>
            <span class="kwrd">using</span> System;</pre>
          <pre>
            <span class="lnum"> 3: </span>
            <span class="kwrd">using</span> System.IO;</pre>
          <pre>
            <span class="lnum"> 4: </span>
          </pre>
          <pre>
            <span class="lnum"> 5: </span>
            <span class="kwrd">namespace</span> EnumerateDrives</pre>
          <pre>
            <span class="lnum"> 6: </span>{</pre>
          <pre>
            <span class="lnum"> 7: </span>
            <span class="kwrd">class</span> Program</pre>
          <pre>
            <span class="lnum"> 8: </span> {</pre>
          <pre>
            <span class="lnum"> 9: </span>
            <span class="kwrd">static</span>
            <span class="kwrd">void</span> Main(<span class="kwrd">string</span>[]
args)</pre>
          <pre>
            <span class="lnum"> 10: </span> {</pre>
          <pre>
            <span class="lnum"> 11: </span> var drives = DriveInfo.GetDrives();</pre>
          <pre>
            <span class="lnum"> 12: </span>
            <span class="kwrd">foreach</span> (var drive <span class="kwrd">in</span> drives)</pre>
          <pre>
            <span class="lnum"> 13: </span> {</pre>
          <pre>
            <span class="lnum"> 14: </span>
            <span class="kwrd">try</span>
          </pre>
          <pre>
            <span class="lnum"> 15: </span> {</pre>
          <pre>
            <span class="lnum"> 16: </span> Console.WriteLine(String.Format(<span class="str">"{0}:
totalspace:{1}gb free:{2}gb"</span>, </pre>
          <pre>
            <span class="lnum"> 17: </span> drive.Name, </pre>
          <pre>
            <span class="lnum"> 18: </span> drive.TotalSize/1024/1024/1024,</pre>
          <pre>
            <span class="lnum"> 19: </span> drive.TotalFreeSpace/1024/1024/1024));</pre>
          <pre>
            <span class="lnum"> 20: </span> }</pre>
          <pre>
            <span class="lnum"> 21: </span>
            <span class="kwrd">catch</span>(Exception ex)</pre>
          <pre>
            <span class="lnum"> 22: </span> {</pre>
          <pre>
            <span class="lnum"> 23: </span> Console.WriteLine(ex.Message);</pre>
          <pre>
            <span class="lnum"> 24: </span> }</pre>
          <pre>
            <span class="lnum"> 25: </span> }</pre>
          <pre>
            <span class="lnum"> 26: </span> Console.ReadKey();</pre>
          <pre>
            <span class="lnum"> 27: </span> }</pre>
          <pre>
            <span class="lnum"> 28: </span> }</pre>
          <pre>
            <span class="lnum"> 29: </span>}</pre>
        </div>
        <img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=7e788206-3898-415e-b21e-702f12c5313a" />
      </body>
      <title>C# enumerating local drives and free space - a quick hack</title>
      <guid isPermaLink="false">http://blog.chrisballance.com/PermaLink,guid,7e788206-3898-415e-b21e-702f12c5313a.aspx</guid>
      <link>http://blog.chrisballance.com/2010/04/16/CEnumeratingLocalDrivesAndFreeSpaceAQuickHack.aspx</link>
      <pubDate>Fri, 16 Apr 2010 06:06:22 GMT</pubDate>
      <description>&lt;div class="csharpcode"&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt; &lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.IO;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; &lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; EnumerateDrives&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[]
args)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt; var drives = DriveInfo.GetDrives();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt; &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var drive &lt;span class="kwrd"&gt;in&lt;/span&gt; drives)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 13: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 14: &lt;/span&gt; &lt;span class="kwrd"&gt;try&lt;/span&gt; &lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 15: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 16: &lt;/span&gt; Console.WriteLine(String.Format(&lt;span class="str"&gt;"{0}:
totalspace:{1}gb free:{2}gb"&lt;/span&gt;, &lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 17: &lt;/span&gt; drive.Name, &lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 18: &lt;/span&gt; drive.TotalSize/1024/1024/1024,&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 19: &lt;/span&gt; drive.TotalFreeSpace/1024/1024/1024));&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 20: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 21: &lt;/span&gt; &lt;span class="kwrd"&gt;catch&lt;/span&gt;(Exception ex)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 22: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 23: &lt;/span&gt; Console.WriteLine(ex.Message);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 24: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 25: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 26: &lt;/span&gt; Console.ReadKey();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 27: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 28: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 29: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=7e788206-3898-415e-b21e-702f12c5313a" /&gt;</description>
      <comments>http://blog.chrisballance.com/CommentView,guid,7e788206-3898-415e-b21e-702f12c5313a.aspx</comments>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://blog.chrisballance.com/Trackback.aspx?guid=b53bbfd2-cf59-4616-ac6a-287d526abcc8</trackback:ping>
      <pingback:server>http://blog.chrisballance.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.chrisballance.com/PermaLink,guid,b53bbfd2-cf59-4616-ac6a-287d526abcc8.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://blog.chrisballance.com/CommentView,guid,b53bbfd2-cf59-4616-ac6a-287d526abcc8.aspx</wfw:comment>
      <wfw:commentRss>http://blog.chrisballance.com/SyndicationService.asmx/GetEntryCommentsRss?guid=b53bbfd2-cf59-4616-ac6a-287d526abcc8</wfw:commentRss>
      <title>Finding the nearest object to a specified location using Latitude, Longitude and a LINQ query.</title>
      <guid isPermaLink="false">http://blog.chrisballance.com/PermaLink,guid,b53bbfd2-cf59-4616-ac6a-287d526abcc8.aspx</guid>
      <link>http://blog.chrisballance.com/2009/07/27/FindingTheNearestObjectToASpecifiedLocationUsingLatitudeLongitudeAndALINQQuery.aspx</link>
      <pubDate>Mon, 27 Jul 2009 03:34:18 GMT</pubDate>
      <description>
&lt;h1&gt;Find nearest object query with LINQ
&lt;/h1&gt;
&lt;p&gt;
&lt;i&gt;While LINQ simplifies your DAL in myriad ways, this seemingly simple query made
me stop and think about how to properly explain this to the query engine&lt;/i&gt;
&lt;/p&gt;
&lt;h2&gt;&lt;b&gt;Problem: Given an input of a current location (latitude and longitude) find
all objects in the database within a specified radius&lt;/b&gt;
&lt;/h2&gt;
&lt;p&gt;
&lt;i&gt;Disclaimer: This is using a &lt;a href="http://www.mathopenref.com/coordbounds.html"&gt;bounding
box&lt;/a&gt; hack rather than an accurate radius forumula, use at your own risk as there
is some loss of precision.&lt;/i&gt;
&lt;/p&gt;
&lt;pre class="csharpcode" style="background-color:#f4f4f4"&gt;
     &lt;span class="rem"&gt;///
Find all courts within a specified radius (in miles) to a point (latitude &amp;amp; longitude)&lt;/span&gt; &lt;span class="rem"&gt;///
&amp;lt;param name="latitude"&amp;gt;degrees(decimal)&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span class="rem"&gt;///
&amp;lt;param name="longitude"&amp;gt;degrees(decimal)&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span class="rem"&gt;///
&amp;lt;param name="radius"&amp;gt;miles&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; IQueryable&amp;lt;Court&amp;gt;
FindNearbyCourts(&lt;span class="kwrd"&gt;decimal&lt;/span&gt; latitude, &lt;span class="kwrd"&gt;decimal&lt;/span&gt; longitude, &lt;span class="kwrd"&gt;decimal&lt;/span&gt; radius); &lt;/pre&gt;
&lt;h3&gt;The first order of business is to convert miles to degrees of latitude and longitude,
respectively.
&lt;/h3&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;b&gt;Latitude:&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Factor out &lt;a href="http://en.wikipedia.org/wiki/Equatorial_bulge"&gt;Equatorial
bulge&lt;/a&gt;, and a degree of latitude is simply &lt;b&gt;69.04 statute miles&lt;/b&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;b&gt;Longitude:&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;On the other hand, longitude varies in length depending
on your current latitude. For this example, I am assuming 30&amp;deg;N. Thus, one degree
of longitude is &lt;b&gt;59.96 statute miles&lt;/b&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;pre class="csharpcode" style="background-color:#f4f4f4"&gt;
     &lt;span class="kwrd"&gt;decimal&lt;/span&gt; radiusLatitude
= radius / 69.04; &lt;span class="kwrd"&gt;decimal&lt;/span&gt; radiusLongitude = radius / 59.96; &lt;/pre&gt;
&lt;h3&gt;Once we have these conversions in place, we are ready to build our LINQ query:
&lt;/h3&gt;
&lt;pre class="csharpcode" style="background-color:#f4f4f4"&gt;
     &lt;span class="kwrd"&gt;IQueryable&lt;/span&gt;&amp;lt;&lt;span class="kwrd"&gt;Court&lt;/span&gt;&amp;gt;
nearbyCourts = &lt;span class="kwrd"&gt;from&lt;/span&gt; court &lt;span class="kwrd"&gt;in&lt;/span&gt; _db.Courts &lt;span class="kwrd"&gt;
&lt;br /&gt;
where&lt;/span&gt; (&lt;span class="kwrd"&gt;Math&lt;/span&gt;.&lt;span class="kwrd"&gt;Abs&lt;/span&gt;(court.latitude
- latitude) &amp;lt; radiusLatitude) 
&lt;br /&gt;
&lt;span class="kwrd"&gt;where&lt;/span&gt; (&lt;span class="kwrd"&gt;Math&lt;/span&gt;.&lt;span class="kwrd"&gt;Abs&lt;/span&gt;(court.longitude
- longitude) &amp;lt; radiusLongitude) 
&lt;br /&gt;
&lt;span class="kwrd"&gt;select&lt;/span&gt; court; &lt;/pre&gt;
&lt;h3&gt;Return the &lt;span style="color:#0000ff"&gt;IQueryable&lt;/span&gt; object &lt;b&gt;nearbyCourts&lt;/b&gt; you
just generated and you're all set.
&lt;/h3&gt;
&lt;img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=b53bbfd2-cf59-4616-ac6a-287d526abcc8" /&gt;</description>
      <comments>http://blog.chrisballance.com/CommentView,guid,b53bbfd2-cf59-4616-ac6a-287d526abcc8.aspx</comments>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://blog.chrisballance.com/Trackback.aspx?guid=6004d5cb-03a2-4413-be2a-b1b9918f4eac</trackback:ping>
      <pingback:server>http://blog.chrisballance.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.chrisballance.com/PermaLink,guid,6004d5cb-03a2-4413-be2a-b1b9918f4eac.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://blog.chrisballance.com/CommentView,guid,6004d5cb-03a2-4413-be2a-b1b9918f4eac.aspx</wfw:comment>
      <wfw:commentRss>http://blog.chrisballance.com/SyndicationService.asmx/GetEntryCommentsRss?guid=6004d5cb-03a2-4413-be2a-b1b9918f4eac</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Google provides a <a href="http://code.google.com/apis/chart/">Charting API</a> with
a host of useful charts. I spent a few minutes playing around with the <a href="http://code.google.com/apis/chart/types.html#maps">map
chart</a> section to create a color-coded map of the states I have visited in the
USA.<br /></p>
        <p>
          <img src="http://chart.apis.google.com/chart?chs=440x220&amp;chd=s:_&amp;cht=t&amp;chtm=usa&amp;chco=FFFFFF,00FF00,FFFF00,FF0000&amp;chld=NCSCGAFLVAWVMDPATNOHCAAZCOWAWIMIDCILINKYALNYTXMAHIAK&amp;chd=t:0,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,60,60,60,60,90,90,90,90,90&amp;chf=bg,s,EAF7FE" alt="chart" />
        </p>
        <p>
The Venn Diagram was an interesting option that I had not expected, but good stuff.
</p>
        <p>
          <img src="http://chart.apis.google.com/chart?cht=v&amp;chs=400x300&amp;chd=t:100,100&amp;chdl=Times%20I%20am%20truly%20happy|Times%20I%20am%20wearing%20shoes&amp;chco=ff0000,0000ff&amp;&amp;chf=c,lg,0,cccccc,1,FFFFFF,0|bg,s,EFEFEF&amp;chdlp=b" alt="chart" />
        </p>
        <p>
If you are building a dashboard, the Google-o-meter might come in handy<br /></p>
        <img src="http://chart.apis.google.com/chart?chs=400x300&amp;cht=gom&amp;chd=t:40&amp;chl=Milk%20left%20in%20refrigerator" alt="chart" />
        <img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=6004d5cb-03a2-4413-be2a-b1b9918f4eac" />
      </body>
      <title>Google Charts API and States I`ve travelled to</title>
      <guid isPermaLink="false">http://blog.chrisballance.com/PermaLink,guid,6004d5cb-03a2-4413-be2a-b1b9918f4eac.aspx</guid>
      <link>http://blog.chrisballance.com/2009/03/01/GoogleChartsAPIAndStatesIveTravelledTo.aspx</link>
      <pubDate>Sun, 01 Mar 2009 18:32:00 GMT</pubDate>
      <description>&lt;p&gt;
Google provides a &lt;a href="http://code.google.com/apis/chart/"&gt;Charting API&lt;/a&gt; with
a host of useful charts. I spent a few minutes playing around with the &lt;a href= "http://code.google.com/apis/chart/types.html#maps"&gt;map
chart&lt;/a&gt; section to create a color-coded map of the states I have visited in the
USA.&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img src= "http://chart.apis.google.com/chart?chs=440x220&amp;amp;chd=s:_&amp;amp;cht=t&amp;amp;chtm=usa&amp;amp;chco=FFFFFF,00FF00,FFFF00,FF0000&amp;amp;chld=NCSCGAFLVAWVMDPATNOHCAAZCOWAWIMIDCILINKYALNYTXMAHIAK&amp;amp;chd=t:0,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,60,60,60,60,90,90,90,90,90&amp;amp;chf=bg,s,EAF7FE" alt="chart" /&gt;
&lt;/p&gt;
&lt;p&gt;
The Venn Diagram was an interesting option that I had not expected, but good stuff.
&lt;/p&gt;
&lt;p&gt;
&lt;img src= "http://chart.apis.google.com/chart?cht=v&amp;amp;chs=400x300&amp;amp;chd=t:100,100&amp;amp;chdl=Times%20I%20am%20truly%20happy|Times%20I%20am%20wearing%20shoes&amp;amp;chco=ff0000,0000ff&amp;amp;&amp;amp;chf=c,lg,0,cccccc,1,FFFFFF,0|bg,s,EFEFEF&amp;amp;chdlp=b" alt="chart" /&gt;
&lt;/p&gt;
&lt;p&gt;
If you are building a dashboard, the Google-o-meter might come in handy&lt;br /&gt;
&lt;/p&gt;
&lt;img src= "http://chart.apis.google.com/chart?chs=400x300&amp;amp;cht=gom&amp;amp;chd=t:40&amp;amp;chl=Milk%20left%20in%20refrigerator" alt="chart" /&gt;&lt;img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=6004d5cb-03a2-4413-be2a-b1b9918f4eac" /&gt;</description>
      <comments>http://blog.chrisballance.com/CommentView,guid,6004d5cb-03a2-4413-be2a-b1b9918f4eac.aspx</comments>
      <category>General</category>
      <category>Personal</category>
      <category>Programming</category>
      <category>Travel</category>
    </item>
    <item>
      <trackback:ping>http://blog.chrisballance.com/Trackback.aspx?guid=3d2afa34-b66d-4b43-9f82-bb4a496c4367</trackback:ping>
      <pingback:server>http://blog.chrisballance.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.chrisballance.com/PermaLink,guid,3d2afa34-b66d-4b43-9f82-bb4a496c4367.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://blog.chrisballance.com/CommentView,guid,3d2afa34-b66d-4b43-9f82-bb4a496c4367.aspx</wfw:comment>
      <wfw:commentRss>http://blog.chrisballance.com/SyndicationService.asmx/GetEntryCommentsRss?guid=3d2afa34-b66d-4b43-9f82-bb4a496c4367</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I find myself spending quite a bit of my spare time on <a href="http://stackoverflow.com">Stackoverflow</a> in
recent weeks, and decided I wanted to display my current rep on my blog.  A few
days ago I built a dynamically generated (and cached for 2 hours for traffic's sake)
user ranking report, since my request for this on <a href="http://stackoverflow.uservoice.com">Uservoice</a> was
not approved.
</p>
        <p>
          <a href="http://www.codeplex.com/htmlagilitypack">HtmlAgilityPack</a> has been my
weapon of choice in recent days.  It was a good fit for this project and the
end result looks like this:
</p>
        <p>
          <img border="0" src="/content/binary/stackoverflowBadge.png" alt="stack overflow badge" />
        </p>
        <p>
And in case you might ask "<strong>Show me the code!"</strong> here you are. 
Feel free to use it for your own project if you like.
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">&lt;%@
WebHandler Language=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"C#"</span> Class=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"Badge"</span> %&gt; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">using</span> System; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">using</span> System.Web; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">class</span> Badge
: IHttpHandler { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">void</span> ProcessRequest
(HttpContext context) { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> includeLogo <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> !<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>.IsNullOrEmpty(context.Request.QueryString[<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"useLogo"</span>])
? 
<br />
context.Request.QueryString[<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"useLogo"</span>]
: <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>.Empty; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> userId <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> !<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>.IsNullOrEmpty(context.Request.QueryString[<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"userid"</span>])
? 
<br />
context.Request.QueryString[<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"userid"</span>]
: <span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"1551"</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> jsMode <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> !<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>.IsNullOrEmpty(context.Request.QueryString[<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"jsMode"</span>])
? 
<br />
context.Request.QueryString[<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"jsMode"</span>]
: <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>.Empty;
PageRetriever pr <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> PageRetriever(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"http://stackoverflow.com/users/"</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">+</span> userId <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">+</span><span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"/"</span>);
pr.GetPage(); User userBadges <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> pr.ExtractBadge(); <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">if</span> (!<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>.IsNullOrEmpty(jsMode))
{ context.Response.ContentType <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"text/javascript"</span>;
context.Response.Write(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"document.getElementById('stackoverflowRep').innerHTML
= '"</span>); } <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">else</span> {
context.Response.ContentType <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"text/html"</span>;
} <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">if</span> (!<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>.IsNullOrEmpty(includeLogo))
{ context.Response.Write(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"&lt;div
style=\"height:40px\"&gt;&lt;div style=\"float:left\"&gt;&lt;/div&gt;&lt;div style=\"float:left;\"&gt;</span>");<br />
context.Response.Write(<font style="BACKGROUND-COLOR: #e4e4e4" color="#666666">&lt;img
src=\"http://www.chrisballance.com/so/resources/stackoverflow-logo-250.png\" /&gt;</font>");</span>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"> }
context.Response.Write(userBadges.Rep); <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">if</span> (!<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>.IsNullOrEmpty(includeLogo))
{ context.Response.Write(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"&lt;br
/&gt;&lt;a href=\"http://stackoverflow.com/users/"</span>); context.Response.Write(userId);
context.Response.Write(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"\"&gt;"</span>);
context.Response.Write(userBadges.Username); context.Response.Write(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;"</span>);
} <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">if</span> (!<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>.IsNullOrEmpty(jsMode))
{ context.Response.Write(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"';\n"</span>);
} } <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">bool</span> IsReusable
{ get { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">false</span>;
} } }</span>
        </pre>
        <p>
 
</p>
        <img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=3d2afa34-b66d-4b43-9f82-bb4a496c4367" />
      </body>
      <title>Show your Stackoverflow.com badge on your blog</title>
      <guid isPermaLink="false">http://blog.chrisballance.com/PermaLink,guid,3d2afa34-b66d-4b43-9f82-bb4a496c4367.aspx</guid>
      <link>http://blog.chrisballance.com/2009/02/23/ShowYourStackoverflowcomBadgeOnYourBlog.aspx</link>
      <pubDate>Mon, 23 Feb 2009 04:10:06 GMT</pubDate>
      <description>&lt;p&gt;
I find myself spending quite a bit of my spare time on &lt;a href= "http://stackoverflow.com"&gt;Stackoverflow&lt;/a&gt; in
recent weeks, and decided I wanted to display my current rep on my blog.&amp;nbsp; A few
days ago I built a dynamically generated (and cached for 2 hours for traffic's sake)
user ranking report, since my request for this on &lt;a href="http://stackoverflow.uservoice.com"&gt;Uservoice&lt;/a&gt;&amp;nbsp;was
not approved.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.codeplex.com/htmlagilitypack"&gt;HtmlAgilityPack&lt;/a&gt; has been my
weapon of choice in recent days.&amp;nbsp; It was a good fit for this project and the
end result looks like this:
&lt;/p&gt;
&lt;p&gt;
&lt;img border="0" src="/content/binary/stackoverflowBadge.png" alt="stack overflow badge" /&gt;
&lt;/p&gt;
&lt;p&gt;
And in case you might ask "&lt;strong&gt;Show me the code!"&lt;/strong&gt; here you are.&amp;nbsp;
Feel free to use it for your own project if you like.
&lt;/p&gt;
&lt;pre&gt;
&lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&amp;lt;%@
WebHandler Language=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"C#"&lt;/span&gt; Class=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"Badge"&lt;/span&gt; %&amp;gt; &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;using&lt;/span&gt; System; &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;using&lt;/span&gt; System.Web; &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;class&lt;/span&gt; Badge
: IHttpHandler { &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;void&lt;/span&gt; ProcessRequest
(HttpContext context) { &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; includeLogo &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; !&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;.IsNullOrEmpty(context.Request.QueryString[&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"useLogo"&lt;/span&gt;])
? 
&lt;br /&gt;
context.Request.QueryString[&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"useLogo"&lt;/span&gt;]
: &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;.Empty; &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; userId &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; !&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;.IsNullOrEmpty(context.Request.QueryString[&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"userid"&lt;/span&gt;])
? 
&lt;br /&gt;
context.Request.QueryString[&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"userid"&lt;/span&gt;]
: &lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"1551"&lt;/span&gt;; &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; jsMode &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; !&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;.IsNullOrEmpty(context.Request.QueryString[&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"jsMode"&lt;/span&gt;])
? 
&lt;br /&gt;
context.Request.QueryString[&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"jsMode"&lt;/span&gt;]
: &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;.Empty;
PageRetriever pr &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; PageRetriever(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"http://stackoverflow.com/users/"&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;+&lt;/span&gt; userId &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;+&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"/"&lt;/span&gt;);
pr.GetPage(); User userBadges &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; pr.ExtractBadge(); &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;if&lt;/span&gt; (!&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;.IsNullOrEmpty(jsMode))
{ context.Response.ContentType &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"text/javascript"&lt;/span&gt;;
context.Response.Write(&lt;span style= "BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"document.getElementById('stackoverflowRep').innerHTML
= '"&lt;/span&gt;); } &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;else&lt;/span&gt; {
context.Response.ContentType &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"text/html"&lt;/span&gt;;
} &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;if&lt;/span&gt; (!&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;.IsNullOrEmpty(includeLogo))
{ context.Response.Write(&lt;span style= "BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"&amp;lt;div
style=\"height:40px\"&amp;gt;&amp;lt;div style=\"float:left\"&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div style=\"float:left;\"&amp;gt;&lt;/span&gt;");&lt;br /&gt;
context.Response.Write(&lt;font style="BACKGROUND-COLOR: #e4e4e4" color= "#666666"&gt;&amp;lt;img
src=\"http://www.chrisballance.com/so/resources/stackoverflow-logo-250.png\" /&amp;gt;&lt;/font&gt;");&lt;/span&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; }
context.Response.Write(userBadges.Rep); &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;if&lt;/span&gt; (!&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;.IsNullOrEmpty(includeLogo))
{ context.Response.Write(&lt;span style= "BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"&amp;lt;br
/&amp;gt;&amp;lt;a href=\"http://stackoverflow.com/users/"&lt;/span&gt;); context.Response.Write(userId);
context.Response.Write(&lt;span style= "BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"\"&amp;gt;"&lt;/span&gt;);
context.Response.Write(userBadges.Username); context.Response.Write(&lt;span style= "BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;"&lt;/span&gt;);
} &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;if&lt;/span&gt; (!&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;.IsNullOrEmpty(jsMode))
{ context.Response.Write(&lt;span style= "BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"';\n"&lt;/span&gt;);
} } &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;bool&lt;/span&gt; IsReusable
{ get { &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;false&lt;/span&gt;;
} } }&lt;/span&gt; &lt;/pre&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=3d2afa34-b66d-4b43-9f82-bb4a496c4367" /&gt;</description>
      <comments>http://blog.chrisballance.com/CommentView,guid,3d2afa34-b66d-4b43-9f82-bb4a496c4367.aspx</comments>
      <category>General</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://blog.chrisballance.com/Trackback.aspx?guid=e45b4313-cf50-46ca-a3c0-6a65c33c1bdc</trackback:ping>
      <pingback:server>http://blog.chrisballance.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.chrisballance.com/PermaLink,guid,e45b4313-cf50-46ca-a3c0-6a65c33c1bdc.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://blog.chrisballance.com/CommentView,guid,e45b4313-cf50-46ca-a3c0-6a65c33c1bdc.aspx</wfw:comment>
      <wfw:commentRss>http://blog.chrisballance.com/SyndicationService.asmx/GetEntryCommentsRss?guid=e45b4313-cf50-46ca-a3c0-6a65c33c1bdc</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Since I could not find a chart of some sort showing current rankings on StackOverflow.com,
I decided to roll my own.  The link that follows points to a static cached version
of the page that will only update manually for now.  Enjoy, and feel free to
give your feedback or suggestions for improvements.
</p>
        <p>
          <a href="http://so.chrisballance.com">Current StackOverflow.com Rankings</a>
        </p>
        <img onclick="javascript:window.location='http://so.chrisballance.com';" border="0" src="/content/binary/StackOverflowRankings.png" alt="Stackoverflow.com Rankings" />
        <img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=e45b4313-cf50-46ca-a3c0-6a65c33c1bdc" />
      </body>
      <title>Finding your rank on Stackoverflow.com</title>
      <guid isPermaLink="false">http://blog.chrisballance.com/PermaLink,guid,e45b4313-cf50-46ca-a3c0-6a65c33c1bdc.aspx</guid>
      <link>http://blog.chrisballance.com/2009/02/17/FindingYourRankOnStackoverflowcom.aspx</link>
      <pubDate>Tue, 17 Feb 2009 06:16:09 GMT</pubDate>
      <description>&lt;p&gt;
Since I could not find a chart of some sort showing current rankings on StackOverflow.com,
I decided to roll my own.&amp;nbsp; The link that follows points to a static cached version
of the page that will only update manually for now.&amp;nbsp; Enjoy, and feel free to
give your feedback or suggestions for improvements.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://so.chrisballance.com"&gt;Current StackOverflow.com Rankings&lt;/a&gt;
&lt;/p&gt;
&lt;img onclick="javascript:window.location='http://so.chrisballance.com';" border="0" src="/content/binary/StackOverflowRankings.png" alt="Stackoverflow.com Rankings" /&gt;&lt;img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=e45b4313-cf50-46ca-a3c0-6a65c33c1bdc" /&gt;</description>
      <comments>http://blog.chrisballance.com/CommentView,guid,e45b4313-cf50-46ca-a3c0-6a65c33c1bdc.aspx</comments>
      <category>General</category>
      <category>Personal</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://blog.chrisballance.com/Trackback.aspx?guid=704c3a47-0006-4f22-9155-18ff796a6ab2</trackback:ping>
      <pingback:server>http://blog.chrisballance.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.chrisballance.com/PermaLink,guid,704c3a47-0006-4f22-9155-18ff796a6ab2.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://blog.chrisballance.com/CommentView,guid,704c3a47-0006-4f22-9155-18ff796a6ab2.aspx</wfw:comment>
      <wfw:commentRss>http://blog.chrisballance.com/SyndicationService.asmx/GetEntryCommentsRss?guid=704c3a47-0006-4f22-9155-18ff796a6ab2</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font color="#006400" size="3">F# has 'easy button' for finding large primes! 
29 lines of code!  Thanks to <a href="http://blogs.msdn.com/chrsmith/archive/2008/04/29/sieve-of-eratosthenes-in-f.aspx">Chris
Smith</a> and his 'completely unique view' on the Sieve of Eratosthenes</font>
        </p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">#light
open System.Collections.Generic open System let findPrimes <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> seq
{ yield 2 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">//2
is a known prime</span> let knownComposites <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> HashSet&lt;<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span>&gt;() <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">//Visit
each odd</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">for</span> i <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">in</span> 3
.. 2 .. <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> 1E6 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">do</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">//
Check known composites, if not present, it is prime.</span> let found <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> knownComposites.Contains(i) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">if</span> not
found then yield i <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">//
Add all multiples of i to our sieve, starting </span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">//
at i and irecementing by i. </span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">do</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">for</span> j <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">in</span> i
.. i .. <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> 1E6 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">do</span> knownComposites.Add(j)
|&gt; ignore } printfn <span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"Here
are the first 10001 primes:"</span> Seq.iter (fun p -&gt; printf <span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"\t%d"</span> p)
(Seq.take 10001 findPrimes) Console.ReadKey(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">true</span>)</span>
        </pre>
        <img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=704c3a47-0006-4f22-9155-18ff796a6ab2" />
      </body>
      <title>Finding Prime numbers faster than I thought possible with this little bit of code - Euler #7</title>
      <guid isPermaLink="false">http://blog.chrisballance.com/PermaLink,guid,704c3a47-0006-4f22-9155-18ff796a6ab2.aspx</guid>
      <link>http://blog.chrisballance.com/2009/02/10/FindingPrimeNumbersFasterThanIThoughtPossibleWithThisLittleBitOfCodeEuler7.aspx</link>
      <pubDate>Tue, 10 Feb 2009 05:15:23 GMT</pubDate>
      <description>
&lt;p&gt;
&lt;font color="#006400" size="3"&gt;F# has 'easy button' for finding large primes!&amp;nbsp;
29 lines of code!&amp;nbsp; Thanks to &lt;a href= "http://blogs.msdn.com/chrsmith/archive/2008/04/29/sieve-of-eratosthenes-in-f.aspx"&gt;Chris
Smith&lt;/a&gt; and his 'completely unique view' on the Sieve of Eratosthenes&lt;/font&gt;
&lt;/p&gt;
&lt;pre&gt;
&lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;#light
open System.Collections.Generic open System let findPrimes &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; seq
{ yield 2 &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;//2
is a known prime&lt;/span&gt; let knownComposites &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; HashSet&amp;lt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt;&amp;gt;() &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;//Visit
each odd&lt;/span&gt; &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;for&lt;/span&gt; i &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;in&lt;/span&gt; 3
.. 2 .. &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; 1E6 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;do&lt;/span&gt; &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;//
Check known composites, if not present, it is prime.&lt;/span&gt; let found &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; knownComposites.Contains(i) &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;if&lt;/span&gt; not
found then yield i &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;//
Add all multiples of i to our sieve, starting &lt;/span&gt; &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;//
at i and irecementing by i. &lt;/span&gt; &lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;do&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;for&lt;/span&gt; j &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;in&lt;/span&gt; i
.. i .. &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; 1E6 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;do&lt;/span&gt; knownComposites.Add(j)
|&amp;gt; ignore } printfn &lt;span style= "BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"Here
are the first 10001 primes:"&lt;/span&gt; Seq.iter (fun p -&amp;gt; printf &lt;span style= "BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"\t%d"&lt;/span&gt; p)
(Seq.take 10001 findPrimes) Console.ReadKey(&lt;span style= "BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;true&lt;/span&gt;)&lt;/span&gt; &lt;/pre&gt;&lt;img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=704c3a47-0006-4f22-9155-18ff796a6ab2" /&gt;</description>
      <comments>http://blog.chrisballance.com/CommentView,guid,704c3a47-0006-4f22-9155-18ff796a6ab2.aspx</comments>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://blog.chrisballance.com/Trackback.aspx?guid=ad580c1a-2e52-4d0d-92de-7fb5e79327fe</trackback:ping>
      <pingback:server>http://blog.chrisballance.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.chrisballance.com/PermaLink,guid,ad580c1a-2e52-4d0d-92de-7fb5e79327fe.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://blog.chrisballance.com/CommentView,guid,ad580c1a-2e52-4d0d-92de-7fb5e79327fe.aspx</wfw:comment>
      <wfw:commentRss>http://blog.chrisballance.com/SyndicationService.asmx/GetEntryCommentsRss?guid=ad580c1a-2e52-4d0d-92de-7fb5e79327fe</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Euler #6 is very straightforward. I was concerned about needing to work with numbers
&gt; 2^32, but this was not a factor. I initially set my bound to <strong>&lt; max</strong> instead
of <strong>&lt;= max</strong> which threw my results off my a small margin (1-99 instead
of 1-100). Runtime is &lt; 1 ms, only ~2400 ticks.
</p>
        <pre>
          <span class="c4">
            <span class="c1">using</span> System; <span class="c1">using</span> System.Diagnostics; <span class="c1">namespace</span> Euler6
{ <span class="c1">class</span> Program { <span class="c1">static</span><span class="c1">void</span> Main(<span class="c1">string</span>[]
args) { Stopwatch sw <span class="c2">=</span><span class="c1">new</span> Stopwatch();
sw.Start(); <span class="c1">long</span> result <span class="c2">=</span> SumDifference(1,
100); sw.Stop(); Console.WriteLine(<span class="c3">"Runtime was "</span><span class="c2">+</span> sw.ElapsedMilliseconds <span class="c2">+</span><span class="c3">"
ms"</span>); Console.WriteLine(<span class="c3">"Runtime was "</span><span class="c2">+</span> sw.ElapsedTicks <span class="c2">+</span><span class="c3">"
ticks"</span>); Console.WriteLine(<span class="c3">"Sum difference is: "</span><span class="c2">+</span> result);
Console.ReadLine(); } <span class="c1">static</span><span class="c1">long</span> SumDifference(<span class="c1">int</span> begin, <span class="c1">int</span> end)
{ <span class="c1">return</span> SquareOfSums(begin, end) <span class="c2">-</span> SumOfSquares(begin,
end); } <span class="c1">static</span><span class="c1">long</span> SumOfSquares(<span class="c1">int</span> begin, <span class="c1">int</span> end)
{ <span class="c1">long</span> returnValue <span class="c2">=</span> 0; <span class="c1">for</span> (<span class="c1">int</span> i <span class="c2">=</span> begin;
i &lt;= end; i++) { returnValue += Convert.ToInt64(Math.Pow(i,2)); } <span class="c1">return</span> returnValue;
} <span class="c1">static</span><span class="c1">long</span> SquareOfSums(<span class="c1">int</span> begin, <span class="c1">int</span> end)
{ <span class="c1">long</span> returnValue <span class="c2">=</span> 0; <span class="c1">for</span> (<span class="c1">int</span> i <span class="c2">=</span> begin;
i &lt;= end; i++) { returnValue += i; } <span class="c1">return</span> Convert.ToInt64(Math.Pow(returnValue,
2)); } } }</span>
        </pre>
        <img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=ad580c1a-2e52-4d0d-92de-7fb5e79327fe" />
      </body>
      <title>C# method for finding the mathematical difference between the sum of squares and square of sums - Euler #6</title>
      <guid isPermaLink="false">http://blog.chrisballance.com/PermaLink,guid,ad580c1a-2e52-4d0d-92de-7fb5e79327fe.aspx</guid>
      <link>http://blog.chrisballance.com/2009/02/10/CMethodForFindingTheMathematicalDifferenceBetweenTheSumOfSquaresAndSquareOfSumsEuler6.aspx</link>
      <pubDate>Tue, 10 Feb 2009 04:01:49 GMT</pubDate>
      <description>&lt;p&gt;
Euler #6 is very straightforward. I was concerned about needing to work with numbers
&amp;gt; 2^32, but this was not a factor. I initially set my bound to &lt;strong&gt;&amp;lt; max&lt;/strong&gt; instead
of &lt;strong&gt;&amp;lt;= max&lt;/strong&gt; which threw my results off my a small margin (1-99 instead
of 1-100). Runtime is &amp;lt; 1 ms, only ~2400 ticks.
&lt;/p&gt;
&lt;pre&gt;
&lt;span class="c4"&gt;&lt;span class="c1"&gt;using&lt;/span&gt; System; &lt;span class="c1"&gt;using&lt;/span&gt; System.Diagnostics; &lt;span class="c1"&gt;namespace&lt;/span&gt; Euler6
{ &lt;span class="c1"&gt;class&lt;/span&gt; Program { &lt;span class="c1"&gt;static&lt;/span&gt; &lt;span class="c1"&gt;void&lt;/span&gt; Main(&lt;span class="c1"&gt;string&lt;/span&gt;[]
args) { Stopwatch sw &lt;span class="c2"&gt;=&lt;/span&gt; &lt;span class="c1"&gt;new&lt;/span&gt; Stopwatch();
sw.Start(); &lt;span class="c1"&gt;long&lt;/span&gt; result &lt;span class="c2"&gt;=&lt;/span&gt; SumDifference(1,
100); sw.Stop(); Console.WriteLine(&lt;span class="c3"&gt;"Runtime was "&lt;/span&gt; &lt;span class="c2"&gt;+&lt;/span&gt; sw.ElapsedMilliseconds &lt;span class="c2"&gt;+&lt;/span&gt; &lt;span class="c3"&gt;"
ms"&lt;/span&gt;); Console.WriteLine(&lt;span class="c3"&gt;"Runtime was "&lt;/span&gt; &lt;span class="c2"&gt;+&lt;/span&gt; sw.ElapsedTicks &lt;span class="c2"&gt;+&lt;/span&gt;&lt;span class="c3"&gt;"
ticks"&lt;/span&gt;); Console.WriteLine(&lt;span class="c3"&gt;"Sum difference is: "&lt;/span&gt; &lt;span class="c2"&gt;+&lt;/span&gt; result);
Console.ReadLine(); } &lt;span class="c1"&gt;static&lt;/span&gt; &lt;span class="c1"&gt;long&lt;/span&gt; SumDifference(&lt;span class="c1"&gt;int&lt;/span&gt; begin, &lt;span class="c1"&gt;int&lt;/span&gt; end)
{ &lt;span class="c1"&gt;return&lt;/span&gt; SquareOfSums(begin, end) &lt;span class="c2"&gt;-&lt;/span&gt; SumOfSquares(begin,
end); } &lt;span class="c1"&gt;static&lt;/span&gt; &lt;span class="c1"&gt;long&lt;/span&gt; SumOfSquares(&lt;span class="c1"&gt;int&lt;/span&gt; begin, &lt;span class="c1"&gt;int&lt;/span&gt; end)
{ &lt;span class="c1"&gt;long&lt;/span&gt; returnValue &lt;span class="c2"&gt;=&lt;/span&gt; 0; &lt;span class="c1"&gt;for&lt;/span&gt; (&lt;span class="c1"&gt;int&lt;/span&gt; i &lt;span class="c2"&gt;=&lt;/span&gt; begin;
i &amp;lt;= end; i++) { returnValue += Convert.ToInt64(Math.Pow(i,2)); } &lt;span class="c1"&gt;return&lt;/span&gt; returnValue;
} &lt;span class="c1"&gt;static&lt;/span&gt; &lt;span class="c1"&gt;long&lt;/span&gt; SquareOfSums(&lt;span class="c1"&gt;int&lt;/span&gt; begin, &lt;span class="c1"&gt;int&lt;/span&gt; end)
{ &lt;span class="c1"&gt;long&lt;/span&gt; returnValue &lt;span class="c2"&gt;=&lt;/span&gt; 0; &lt;span class="c1"&gt;for&lt;/span&gt; (&lt;span class="c1"&gt;int&lt;/span&gt; i &lt;span class="c2"&gt;=&lt;/span&gt; begin;
i &amp;lt;= end; i++) { returnValue += i; } &lt;span class="c1"&gt;return&lt;/span&gt; Convert.ToInt64(Math.Pow(returnValue,
2)); } } }&lt;/span&gt; &lt;/pre&gt;&lt;img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=ad580c1a-2e52-4d0d-92de-7fb5e79327fe" /&gt;</description>
      <comments>http://blog.chrisballance.com/CommentView,guid,ad580c1a-2e52-4d0d-92de-7fb5e79327fe.aspx</comments>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://blog.chrisballance.com/Trackback.aspx?guid=359bedca-fccc-4e79-aff9-f87037cde20f</trackback:ping>
      <pingback:server>http://blog.chrisballance.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.chrisballance.com/PermaLink,guid,359bedca-fccc-4e79-aff9-f87037cde20f.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://blog.chrisballance.com/CommentView,guid,359bedca-fccc-4e79-aff9-f87037cde20f.aspx</wfw:comment>
      <wfw:commentRss>http://blog.chrisballance.com/SyndicationService.asmx/GetEntryCommentsRss?guid=359bedca-fccc-4e79-aff9-f87037cde20f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <pre>
          <span class="c2">
            <br />
            <span class="c1">This one was elusively easy since I went with a simple brute-force
approach. Execution averages 1 second.</span>
          </span>
        </pre>
        <pre>
          <span class="c6">
            <span class="c3">using</span> System; <span class="c3">using</span> System.Diagnostics; <span class="c3">namespace</span> Euler5
{ <span class="c3">class</span> Program { <span class="c3">static</span><span class="c3">void</span> Main(<span class="c3">string</span>[]
args) { Stopwatch sw <span class="c4">=</span><span class="c3">new</span> Stopwatch();
sw.Start(); <span class="c3">int</span> lcm <span class="c4">=</span> FindLeastCommonMultiple();
sw.Stop(); Console.WriteLine(<span class="c5">"Runtime was "</span><span class="c4">+</span> sw.ElapsedMilliseconds <span class="c4">+</span><span class="c5">"
ms"</span>); Console.WriteLine(<span class="c5">"Runtime was "</span><span class="c4">+</span> sw.ElapsedTicks <span class="c4">+</span><span class="c5">"
ticks"</span>); Console.WriteLine(<span class="c5">"LCM is "</span><span class="c4">+</span> lcm);
Console.ReadLine(); } <span class="c3">private</span><span class="c3">static</span><span class="c3">int</span> FindLeastCommonMultiple()
{ <span class="c3">for</span> (<span class="c3">int</span> i <span class="c4">=</span> 2520;
i &lt; <span class="c3">int</span>.MaxValue; i += 20) { <span class="c3">if</span> (IsDivisibleByRange(i,
1, 20)) <span class="c3">return</span> i; } <span class="c3">return</span> -1; } <span class="c3">static</span><span class="c3">long</span> SmallestNumber()
{ <span class="c3">return</span> factorial(20); } <span class="c3">static</span><span class="c3">long</span> factorial(<span class="c3">long</span> n)
{ <span class="c3">long</span> returnValue <span class="c4">=</span> 1; <span class="c3">for</span> (<span class="c3">int</span> i <span class="c4">=</span> 1;
i &lt; n; i++) { returnValue *= i; } <span class="c3">return</span> returnValue; } <span class="c3">static</span><span class="c3">bool</span> IsDivisibleByRange(<span class="c3">int</span> num, <span class="c3">int</span> begin, <span class="c3">int</span> end)
{ <span class="c3">for</span> (<span class="c3">int</span> i <span class="c4">=</span> begin;
i &lt;= end; i++) { <span class="c3">if</span> ((num <span class="c4">%</span> i)
!<span class="c4">=</span> 0) { <span class="c3">return</span><span class="c3">false</span>;
} } <span class="c3">return</span><span class="c3">true</span>; } } }</span>
        </pre>
        <img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=359bedca-fccc-4e79-aff9-f87037cde20f" />
      </body>
      <title>Programatically finding the least common multiple of the numbers 1 to 20 (Euler #5)</title>
      <guid isPermaLink="false">http://blog.chrisballance.com/PermaLink,guid,359bedca-fccc-4e79-aff9-f87037cde20f.aspx</guid>
      <link>http://blog.chrisballance.com/2009/02/10/ProgramaticallyFindingTheLeastCommonMultipleOfTheNumbers1To20Euler5.aspx</link>
      <pubDate>Tue, 10 Feb 2009 03:44:54 GMT</pubDate>
      <description>&lt;pre&gt;
&lt;span class="c2"&gt;
&lt;br /&gt;
&lt;span class="c1"&gt;This one was elusively easy since I went with a simple brute-force
approach. Execution averages 1 second.&lt;/span&gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre&gt;
&lt;span class="c6"&gt;&lt;span class="c3"&gt;using&lt;/span&gt; System; &lt;span class="c3"&gt;using&lt;/span&gt; System.Diagnostics; &lt;span class="c3"&gt;namespace&lt;/span&gt; Euler5
{ &lt;span class="c3"&gt;class&lt;/span&gt; Program { &lt;span class="c3"&gt;static&lt;/span&gt; &lt;span class="c3"&gt;void&lt;/span&gt; Main(&lt;span class="c3"&gt;string&lt;/span&gt;[]
args) { Stopwatch sw &lt;span class="c4"&gt;=&lt;/span&gt; &lt;span class="c3"&gt;new&lt;/span&gt; Stopwatch();
sw.Start(); &lt;span class="c3"&gt;int&lt;/span&gt; lcm &lt;span class="c4"&gt;=&lt;/span&gt; FindLeastCommonMultiple();
sw.Stop(); Console.WriteLine(&lt;span class="c5"&gt;"Runtime was "&lt;/span&gt; &lt;span class="c4"&gt;+&lt;/span&gt; sw.ElapsedMilliseconds &lt;span class="c4"&gt;+&lt;/span&gt; &lt;span class="c5"&gt;"
ms"&lt;/span&gt;); Console.WriteLine(&lt;span class="c5"&gt;"Runtime was "&lt;/span&gt; &lt;span class="c4"&gt;+&lt;/span&gt; sw.ElapsedTicks &lt;span class="c4"&gt;+&lt;/span&gt; &lt;span class="c5"&gt;"
ticks"&lt;/span&gt;); Console.WriteLine(&lt;span class="c5"&gt;"LCM is "&lt;/span&gt; &lt;span class="c4"&gt;+&lt;/span&gt; lcm);
Console.ReadLine(); } &lt;span class="c3"&gt;private&lt;/span&gt; &lt;span class="c3"&gt;static&lt;/span&gt; &lt;span class="c3"&gt;int&lt;/span&gt; FindLeastCommonMultiple()
{ &lt;span class="c3"&gt;for&lt;/span&gt; (&lt;span class="c3"&gt;int&lt;/span&gt; i &lt;span class="c4"&gt;=&lt;/span&gt; 2520;
i &amp;lt; &lt;span class="c3"&gt;int&lt;/span&gt;.MaxValue; i += 20) { &lt;span class="c3"&gt;if&lt;/span&gt; (IsDivisibleByRange(i,
1, 20)) &lt;span class="c3"&gt;return&lt;/span&gt; i; } &lt;span class="c3"&gt;return&lt;/span&gt; -1; } &lt;span class="c3"&gt;static&lt;/span&gt; &lt;span class="c3"&gt;long&lt;/span&gt; SmallestNumber()
{ &lt;span class="c3"&gt;return&lt;/span&gt; factorial(20); } &lt;span class="c3"&gt;static&lt;/span&gt; &lt;span class="c3"&gt;long&lt;/span&gt; factorial(&lt;span class="c3"&gt;long&lt;/span&gt; n)
{ &lt;span class="c3"&gt;long&lt;/span&gt; returnValue &lt;span class="c4"&gt;=&lt;/span&gt; 1; &lt;span class="c3"&gt;for&lt;/span&gt; (&lt;span class="c3"&gt;int&lt;/span&gt; i &lt;span class="c4"&gt;=&lt;/span&gt; 1;
i &amp;lt; n; i++) { returnValue *= i; } &lt;span class="c3"&gt;return&lt;/span&gt; returnValue; } &lt;span class="c3"&gt;static&lt;/span&gt; &lt;span class="c3"&gt;bool&lt;/span&gt; IsDivisibleByRange(&lt;span class="c3"&gt;int&lt;/span&gt; num, &lt;span class="c3"&gt;int&lt;/span&gt; begin, &lt;span class="c3"&gt;int&lt;/span&gt; end)
{ &lt;span class="c3"&gt;for&lt;/span&gt; (&lt;span class="c3"&gt;int&lt;/span&gt; i &lt;span class="c4"&gt;=&lt;/span&gt; begin;
i &amp;lt;= end; i++) { &lt;span class="c3"&gt;if&lt;/span&gt; ((num &lt;span class="c4"&gt;%&lt;/span&gt; i)
!&lt;span class="c4"&gt;=&lt;/span&gt; 0) { &lt;span class="c3"&gt;return&lt;/span&gt; &lt;span class="c3"&gt;false&lt;/span&gt;;
} } &lt;span class="c3"&gt;return&lt;/span&gt; &lt;span class="c3"&gt;true&lt;/span&gt;; } } }&lt;/span&gt; &lt;/pre&gt;&lt;img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=359bedca-fccc-4e79-aff9-f87037cde20f" /&gt;</description>
      <comments>http://blog.chrisballance.com/CommentView,guid,359bedca-fccc-4e79-aff9-f87037cde20f.aspx</comments>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://blog.chrisballance.com/Trackback.aspx?guid=f573980f-67cd-4060-9b39-5bd827935884</trackback:ping>
      <pingback:server>http://blog.chrisballance.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.chrisballance.com/PermaLink,guid,f573980f-67cd-4060-9b39-5bd827935884.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://blog.chrisballance.com/CommentView,guid,f573980f-67cd-4060-9b39-5bd827935884.aspx</wfw:comment>
      <wfw:commentRss>http://blog.chrisballance.com/SyndicationService.asmx/GetEntryCommentsRss?guid=f573980f-67cd-4060-9b39-5bd827935884</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font color="#006400" size="3">There is certainly a more efficient algorithm solve
Euler #4, but here is my solution.  Runtime averages around 500ms.</font>
        </p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">using</span> System; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">using</span> System.Collections.Generic; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">using</span> System.Linq; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">using</span> System.Text; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">using</span> System.Configuration; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">using</span> System.Diagnostics; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">namespace</span> Euler4
{ <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">class</span> Program
{ <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">static</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">void</span> Main(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>[]
args) { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">long</span> maxPal <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> 0; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">long</span> iMax <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> 0; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">long</span> jMax <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> 0;
Stopwatch sw <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> Stopwatch();
sw.Start(); <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">for</span> (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> i <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> 100;
i &lt;= 999; i++) { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">for</span> (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> j <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> 100;
j &lt;= 999; j++) { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">long</span> curPal <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">long</span>)(i <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">*</span> j); <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">if</span> (CheckPallindrome(curPal))
{ <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">if</span> (curPal
&gt; maxPal) { maxPal <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> curPal;
iMax <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> i;
jMax <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> j;
} } } } sw.Stop(); Console.WriteLine(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"Runtime
was "</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">+</span> sw.ElapsedMilliseconds <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">+</span><span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"
ms"</span>); Console.WriteLine(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"Runtime
was "</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">+</span> sw.ElapsedTicks <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">+</span><span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"
ticks "</span>); Console.WriteLine(iMax <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">+</span><span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"
x "</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">+</span> jMax <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">+</span><span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"
= "</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">+</span> maxPal);
Console.ReadLine(); } <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">private</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">static</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">bool</span> CheckPallindrome(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">long</span> input)
{ PallindromeChecker pc <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> PallindromeChecker();
pc.Pal <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> input; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span> pc.IsPallindrome();
} } <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">class</span> PallindromeChecker
{ <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">private</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">long</span> _pal; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">private</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> forward,
reverse; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">long</span> Pal
{ get { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span> _pal;
} set { _pal <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> value;
} } <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">bool</span> IsPallindrome()
{ GetReversedLong(); <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">if</span> (forward
== reverse) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">true</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">false</span>;
} <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">private</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">void</span> GetReversedLong()
{ forward <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> Convert.ToString(_pal);
StringBuilder temp2 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> StringBuilder(); <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">char</span>[]
arr <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">char</span>[forward.Length <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">-</span> 1];
arr <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> forward.ToCharArray(); <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">for</span> (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> i <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> forward.Length <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">-</span> 1;
i &gt;= 0; i--) { temp2.Append(arr[i]); } reverse <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> temp2.ToString();
} } }</span>
        </pre>
        <img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=f573980f-67cd-4060-9b39-5bd827935884" />
      </body>
      <title>Finding the largest pallindrome product of two three digit integers</title>
      <guid isPermaLink="false">http://blog.chrisballance.com/PermaLink,guid,f573980f-67cd-4060-9b39-5bd827935884.aspx</guid>
      <link>http://blog.chrisballance.com/2009/02/10/FindingTheLargestPallindromeProductOfTwoThreeDigitIntegers.aspx</link>
      <pubDate>Tue, 10 Feb 2009 03:26:20 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font color=#006400 size=3&gt;There is certainly a more efficient algorithm solve Euler
#4, but here is my solution.&amp;nbsp; Runtime averages around 500ms.&lt;/font&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;using&lt;/span&gt; System; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;using&lt;/span&gt; System.Collections.Generic; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;using&lt;/span&gt; System.Linq; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;using&lt;/span&gt; System.Text; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;using&lt;/span&gt; System.Configuration; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;using&lt;/span&gt; System.Diagnostics; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;namespace&lt;/span&gt; Euler4
{ &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;class&lt;/span&gt; Program
{ &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;static&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;void&lt;/span&gt; Main(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;[]
args) { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;long&lt;/span&gt; maxPal &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; 0; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;long&lt;/span&gt; iMax &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; 0; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;long&lt;/span&gt; jMax &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; 0;
Stopwatch sw &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; Stopwatch();
sw.Start(); &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;for&lt;/span&gt; (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; i &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; 100;
i &amp;lt;= 999; i++) { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;for&lt;/span&gt; (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; j &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; 100;
j &amp;lt;= 999; j++) { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;long&lt;/span&gt; curPal &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;long&lt;/span&gt;)(i &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;*&lt;/span&gt; j); &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;if&lt;/span&gt; (CheckPallindrome(curPal))
{ &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;if&lt;/span&gt; (curPal
&amp;gt; maxPal) { maxPal &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; curPal;
iMax &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; i;
jMax &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; j;
} } } } sw.Stop(); Console.WriteLine(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"Runtime
was "&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;+&lt;/span&gt; sw.ElapsedMilliseconds &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;+&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"
ms"&lt;/span&gt;); Console.WriteLine(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"Runtime
was "&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;+&lt;/span&gt; sw.ElapsedTicks &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;+&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"
ticks "&lt;/span&gt;); Console.WriteLine(iMax &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;+&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"
x "&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;+&lt;/span&gt; jMax &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;+&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"
= "&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;+&lt;/span&gt; maxPal);
Console.ReadLine(); } &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;private&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;static&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;bool&lt;/span&gt; CheckPallindrome(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;long&lt;/span&gt; input)
{ PallindromeChecker pc &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; PallindromeChecker();
pc.Pal &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; input; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; pc.IsPallindrome();
} } &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;class&lt;/span&gt; PallindromeChecker
{ &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;private&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;long&lt;/span&gt; _pal; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;private&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; forward,
reverse; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;long&lt;/span&gt; Pal
{ get { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; _pal;
} set { _pal &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; value;
} } &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;bool&lt;/span&gt; IsPallindrome()
{ GetReversedLong(); &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;if&lt;/span&gt; (forward
== reverse) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;true&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;false&lt;/span&gt;;
} &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;private&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;void&lt;/span&gt; GetReversedLong()
{ forward &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; Convert.ToString(_pal);
StringBuilder temp2 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; StringBuilder(); &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;char&lt;/span&gt;[]
arr &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;char&lt;/span&gt;[forward.Length &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;-&lt;/span&gt; 1];
arr &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; forward.ToCharArray(); &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;for&lt;/span&gt; (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; i &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; forward.Length &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;-&lt;/span&gt; 1;
i &amp;gt;= 0; i--) { temp2.Append(arr[i]); } reverse &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; temp2.ToString();
} } }&lt;/span&gt;&lt;/pre&gt;&lt;img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=f573980f-67cd-4060-9b39-5bd827935884" /&gt;</description>
      <comments>http://blog.chrisballance.com/CommentView,guid,f573980f-67cd-4060-9b39-5bd827935884.aspx</comments>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://blog.chrisballance.com/Trackback.aspx?guid=f65a9a24-eb6a-4373-ab93-90fa17ad563d</trackback:ping>
      <pingback:server>http://blog.chrisballance.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.chrisballance.com/PermaLink,guid,f65a9a24-eb6a-4373-ab93-90fa17ad563d.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://blog.chrisballance.com/CommentView,guid,f65a9a24-eb6a-4373-ab93-90fa17ad563d.aspx</wfw:comment>
      <wfw:commentRss>http://blog.chrisballance.com/SyndicationService.asmx/GetEntryCommentsRss?guid=f65a9a24-eb6a-4373-ab93-90fa17ad563d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
  In an effort to improve my algorithm design I have been working through some
of the problems in the <a href="http://projecteuler.net">Euler Project</a> and have
found some of them to be quite intriguing.
</p>
        <p>
          <font color="#008000">
            <strong>Q: What is the largest prime factor of the number 600851475143
?</strong>
          </font>
        </p>
        <p>
          <font color="#000000">I had the following issues to ponder:</font>
        </p>
        <ul>
          <li>
            <font color="#000000">How to store and manipulate a 40-bit unsigned integer?</font>
          </li>
          <li>
            <font color="#000000">To utilize recursion or not?</font>
          </li>
          <li>
            <font color="#000000">Will the algorithm run in less than a minute?</font>
            <ul>
              <li>
                <font color="#000000">If not, how do I make it more efficient?</font>
              </li>
            </ul>
          </li>
        </ul>
        <p>
          <font color="#000000">The end result was simpler and much more <a href="http://weblogs.asp.net/jgalloway/archive/2007/05/10/performant-isn-t-a-word.aspx">performant</a> than
I had expected.  The 40-bit input fit into a <a href="http://msdn.microsoft.com/en-us/library/ctetwysk.aspx">long</a> just
fine.  Recursion was not necessary, and average runtimes are in the single digit
millisecond range.  There was even an opportunity to use some very basic <a href="http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx">LINQ</a> to
retrieve the largest factor from the <a href="http://msdn.microsoft.com/en-us/library/system.collections.arraylist.aspx">List</a></font>
        </p>
        <p>
          <font color="#000000">Here is the C# code:</font>
        </p>
        <font color="#008000">
          <pre>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> System; <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> System.Collections; <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> System.Collections.Specialized; <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> System.Collections.Generic; <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> System.Linq; <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> System.Diagnostics; <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">namespace</span> Euler3
{ <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> PrimeFactorization
{ <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">const</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">long</span> ToFactor <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> 600851475143; <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span> List&lt;<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">long</span>&gt;
theFactors <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> List&lt;<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">long</span>&gt;(); <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Main(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>[]
args) { Stopwatch sw <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Stopwatch();
sw.Reset(); sw.Start(); Console.WriteLine(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Highest
prime factor of ("</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> ToFactor <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">")
is "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> HighestPrimeFactor(ToFactor));
sw.Stop(); Console.WriteLine(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Factorization
algorithm runtime was: "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> sw.ElapsedTicks <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"
ticks or "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> sw.ElapsedMilliseconds <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"ms"</span>);
Console.ReadLine(); } <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">long</span> HighestPrimeFactor(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">long</span> input)
{ <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">bool</span> searching <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">true</span>; <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">long</span> highestFactor <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> 0; <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">while</span> (searching)
{ <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">long</span> factor <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> IsPrime(input); <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (factor
!<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> -1)
{ theFactors.Add(factor); input <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> input <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">/</span> factor;
} <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (factor
== -1) { theFactors.Add(input); highestFactor <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> theFactors.Max();
searching <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">false</span>;
} } <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> highestFactor;
} <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">long</span> IsPrime(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">long</span> input)
{ <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> ((input <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">%</span> 2)
== 0) { <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> 2;
} <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">else</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> ((input
== 1)) { <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> 1;
} <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">else</span> { <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">long</span> threshold <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> (Convert.ToInt64(Math.Sqrt(input))); <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">long</span> tryDivide <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> 3; <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">while</span> (tryDivide
&lt; threshold) { <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> ((input <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">%</span> tryDivide)
== 0) { Console.WriteLine(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Found
a factor: "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> tryDivide); <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> tryDivide;
} tryDivide += 2; } Console.WriteLine(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Found
a factor: "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> input); <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> -1;
} } } }</span>
          </pre>
          <pre>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Output:<br /></span>
          </pre>
          <pre>
            <img src="/content/binary/euler3.jpg" border="0" />
          </pre>
          <pre>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            </span>
          </pre>
        </font>
        <font color="#808080">-Surely a blog entry title such as this earns
me some sort of special place in </font>
        <a href="http://www.hell.com/">
          <font color="#0000ff">Geek
Hell</font>
        </a>
        <font color="#808080">.</font>
        <img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=f65a9a24-eb6a-4373-ab93-90fa17ad563d" />
      </body>
      <title>Fun with Prime Factorization</title>
      <guid isPermaLink="false">http://blog.chrisballance.com/PermaLink,guid,f65a9a24-eb6a-4373-ab93-90fa17ad563d.aspx</guid>
      <link>http://blog.chrisballance.com/2009/01/22/FunWithPrimeFactorization.aspx</link>
      <pubDate>Thu, 22 Jan 2009 03:42:21 GMT</pubDate>
      <description>&lt;p&gt;
&amp;nbsp; In an effort to improve my algorithm design I have been working through some
of the problems in the &lt;a href="http://projecteuler.net"&gt;Euler Project&lt;/a&gt; and have
found some of them to be quite intriguing.
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#008000&gt;&lt;strong&gt;Q: What is the largest prime factor of the number 600851475143
?&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000&gt;I had the following&amp;nbsp;issues&amp;nbsp;to ponder:&lt;/font&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;font color=#000000&gt;How to store and manipulate a 40-bit unsigned integer?&lt;/font&gt; 
&lt;li&gt;
&lt;font color=#000000&gt;To utilize recursion or not?&lt;/font&gt; 
&lt;li&gt;
&lt;font color=#000000&gt;Will the algorithm run in less than a minute?&lt;/font&gt; 
&lt;ul&gt;
&lt;li&gt;
&lt;font color=#000000&gt;If not, how do I make it more efficient?&lt;/font&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;font color=#000000&gt;The end result was simpler and much more &lt;a href="http://weblogs.asp.net/jgalloway/archive/2007/05/10/performant-isn-t-a-word.aspx"&gt;performant&lt;/a&gt; than
I had expected.&amp;nbsp; The 40-bit input fit into a &lt;a href="http://msdn.microsoft.com/en-us/library/ctetwysk.aspx"&gt;long&lt;/a&gt; just
fine.&amp;nbsp; Recursion was not necessary, and average runtimes are in the single digit
millisecond range.&amp;nbsp; There was even an opportunity to use some very basic &lt;a href="http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx"&gt;LINQ&lt;/a&gt; to
retrieve the largest factor from the &lt;a href="http://msdn.microsoft.com/en-us/library/system.collections.arraylist.aspx"&gt;List&lt;/a&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000&gt;Here is the C# code:&lt;/font&gt;
&lt;/p&gt;
&lt;font color=#008000&gt;&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt; System; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt; System.Collections; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt; System.Collections.Specialized; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt; System.Collections.Generic; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt; System.Linq; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt; System.Diagnostics; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;namespace&lt;/span&gt; Euler3
{ &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; PrimeFactorization
{ &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;const&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;long&lt;/span&gt; ToFactor &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; 600851475143; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; List&amp;lt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;long&lt;/span&gt;&amp;gt;
theFactors &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; List&amp;lt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;long&lt;/span&gt;&amp;gt;(); &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; Main(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt;[]
args) { Stopwatch sw &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; Stopwatch();
sw.Reset(); sw.Start(); Console.WriteLine(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Highest
prime factor of ("&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; ToFactor &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;")
is "&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; HighestPrimeFactor(ToFactor));
sw.Stop(); Console.WriteLine(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Factorization
algorithm runtime was: "&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; sw.ElapsedTicks &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"
ticks or "&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; sw.ElapsedMilliseconds &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"ms"&lt;/span&gt;);
Console.ReadLine(); } &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;long&lt;/span&gt; HighestPrimeFactor(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;long&lt;/span&gt; input)
{ &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;bool&lt;/span&gt; searching &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;true&lt;/span&gt;; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;long&lt;/span&gt; highestFactor &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; 0; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;while&lt;/span&gt; (searching)
{ &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;long&lt;/span&gt; factor &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; IsPrime(input); &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; (factor
!&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; -1)
{ theFactors.Add(factor); input &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; input &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;/&lt;/span&gt; factor;
} &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; (factor
== -1) { theFactors.Add(input); highestFactor &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; theFactors.Max();
searching &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;false&lt;/span&gt;;
} } &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; highestFactor;
} &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;long&lt;/span&gt; IsPrime(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;long&lt;/span&gt; input)
{ &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; ((input &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;%&lt;/span&gt; 2)
== 0) { &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; 2;
} &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;else&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; ((input
== 1)) { &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; 1;
} &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;else&lt;/span&gt; { &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;long&lt;/span&gt; threshold &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; (Convert.ToInt64(Math.Sqrt(input))); &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;long&lt;/span&gt; tryDivide &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; 3; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;while&lt;/span&gt; (tryDivide
&amp;lt; threshold) { &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; ((input &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;%&lt;/span&gt; tryDivide)
== 0) { Console.WriteLine(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Found
a factor: "&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; tryDivide); &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; tryDivide;
} tryDivide += 2; } Console.WriteLine(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Found
a factor: "&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; input); &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; -1;
} } } }&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Output:&lt;br&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;img src="/content/binary/euler3.jpg" border=0&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;/span&gt;
&lt;/font&gt;&lt;font color=#808080&gt;-Surely a blog entry title&amp;nbsp;such as this earns me some
sort of special place in &lt;/font&gt;&lt;a href="http://www.hell.com/"&gt;&lt;font color=#0000ff&gt;Geek
Hell&lt;/font&gt;&lt;/a&gt;&lt;font color=#808080&gt;.&lt;/font&gt;&gt;&lt;img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=f65a9a24-eb6a-4373-ab93-90fa17ad563d" /&gt;</description>
      <comments>http://blog.chrisballance.com/CommentView,guid,f65a9a24-eb6a-4373-ab93-90fa17ad563d.aspx</comments>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://blog.chrisballance.com/Trackback.aspx?guid=4fec798a-4f16-48ce-9adc-58ab7d4e7e37</trackback:ping>
      <pingback:server>http://blog.chrisballance.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.chrisballance.com/PermaLink,guid,4fec798a-4f16-48ce-9adc-58ab7d4e7e37.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://blog.chrisballance.com/CommentView,guid,4fec798a-4f16-48ce-9adc-58ab7d4e7e37.aspx</wfw:comment>
      <wfw:commentRss>http://blog.chrisballance.com/SyndicationService.asmx/GetEntryCommentsRss?guid=4fec798a-4f16-48ce-9adc-58ab7d4e7e37</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.microsoft.com/events/teched2008/developer/default.mspx">
            <img src="http://www.chrisballance.com/Blog/content/binary/signature-DEV2.jpg" border="0" />
          </a>
          <br />
          <img src="http://farm3.static.flickr.com/2415/2397468456_449560b4d6.jpg" />
        </p>
        <img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=4fec798a-4f16-48ce-9adc-58ab7d4e7e37" />
      </body>
      <title>Tech Ed 2008</title>
      <guid isPermaLink="false">http://blog.chrisballance.com/PermaLink,guid,4fec798a-4f16-48ce-9adc-58ab7d4e7e37.aspx</guid>
      <link>http://blog.chrisballance.com/2008/04/08/TechEd2008.aspx</link>
      <pubDate>Tue, 08 Apr 2008 00:11:57 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.microsoft.com/events/teched2008/developer/default.mspx"&gt;&lt;img src="http://www.chrisballance.com/Blog/content/binary/signature-DEV2.jpg" border=0&gt;&lt;/a&gt;
&lt;br&gt;
&lt;img src="http://farm3.static.flickr.com/2415/2397468456_449560b4d6.jpg"&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.chrisballance.com/aggbug.ashx?id=4fec798a-4f16-48ce-9adc-58ab7d4e7e37" /&gt;</description>
      <comments>http://blog.chrisballance.com/CommentView,guid,4fec798a-4f16-48ce-9adc-58ab7d4e7e37.aspx</comments>
      <category>General</category>
      <category>Programming</category>
    </item>
  </channel>
</rss>