<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><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/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>Chris Ballance's Blog</title>
    <link>http://www.chrisballance.com/Blog/</link>
    <description>I've got the 200 you need.</description>
    <language>en-us</language>
    <copyright>Christopher Ballance</copyright>
    <lastBuildDate>Sat, 21 Mar 2009 19:53:31 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>ballance@gmail.com</managingEditor>
    <webMaster>ballance@gmail.com</webMaster>
    <geo:lat>36.156707</geo:lat><geo:long>-79.806445</geo:long><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/Ballance" type="application/rss+xml" /><item>
      <trackback:ping>http://www.chrisballance.com/Blog/Trackback.aspx?guid=910fa09a-0416-4c09-93e3-e5cc25018317</trackback:ping>
      <pingback:server>http://www.chrisballance.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisballance.com/Blog/PermaLink,guid,910fa09a-0416-4c09-93e3-e5cc25018317.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://www.chrisballance.com/Blog/CommentView,guid,910fa09a-0416-4c09-93e3-e5cc25018317.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisballance.com/Blog/SyndicationService.asmx/GetEntryCommentsRss?guid=910fa09a-0416-4c09-93e3-e5cc25018317</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <title>The Official CWP Team Train</title>
      <guid isPermaLink="false">http://www.chrisballance.com/Blog/PermaLink,guid,910fa09a-0416-4c09-93e3-e5cc25018317.aspx</guid>
      <link>http://feedproxy.google.com/~r/Ballance/~3/hpjNQZHH3ko/TheOfficialCWPTeamTrain.aspx</link>
      <pubDate>Sat, 21 Mar 2009 19:53:31 GMT</pubDate>
      <description>&lt;div style="float: right; margin-left: 10px; margin-bottom: 10px"&gt;
&lt;object width="640" height="505"&gt;
&lt;param name="movie" value="http://www.youtube.com/v/r1Bk_2gSzUo&amp;hl=en&amp;fs=1&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999"&gt;&gt;
&lt;param name="allowFullScreen" value="true"&gt;&gt;
&lt;param name="allowscriptaccess" value="always"&gt;&gt;&lt;embed src="http://www.youtube.com/v/r1Bk_2gSzUo&amp;hl=en&amp;fs=1&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"&gt;&lt;/embed&gt;
&lt;/object&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;When &lt;a href="http://twitter.com/travismurray"&gt;Travis&lt;/a&gt; mentioned to the group
that his Barbershop Quartet would be competing in a Barbershop Quartet competition
right around the corner in Winston-Salem, NC, a few of us decided to attend to cheer
him on. One day we were discussing it in the Common Area and some crazy ideas were
thrown out, namely a few of us dressing up as a Train, befitting their group name, &lt;a href="http://www.grandcentralquartet.com/"&gt;Grand
Central&lt;/a&gt;. It turned into quite a crazy evening, as the video evidence to the right
shows. Thanks to &lt;a href="http://twitter.com/bridgetlas"&gt;Bridget&lt;/a&gt;, &lt;a href="http://twitter.com/rexm"&gt;Rex&lt;/a&gt;, &lt;a href="http://twitter.com/lucasdargis"&gt;Lucas&lt;/a&gt;, &lt;a href="http://twitter.com/bspotter"&gt;Brandon&lt;/a&gt;, &lt;a href="http://twitter.com/harperj"&gt;Jason&lt;/a&gt; for
your participation in the aforementioned silliness. I would also like to thank &lt;a href="http://twitter.com/realestatedeals"&gt;Tony&lt;/a&gt; and &lt;a href="http://twitter.com/davidbates"&gt;David&lt;/a&gt; for
responding to our tweets and suppling the cardboard and UPS respectively. You may
view the rest of the photos &lt;a href="http://www.flickr.com/photos/ballance/sets/72157615728473156/"&gt;here
on Flickr&lt;/a&gt;. 
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.chrisballance.com/Blog/aggbug.ashx?id=910fa09a-0416-4c09-93e3-e5cc25018317" /&gt;</description>
      <comments>http://www.chrisballance.com/Blog/CommentView,guid,910fa09a-0416-4c09-93e3-e5cc25018317.aspx</comments>
      <category>Personal</category>
    <feedburner:origLink>http://www.chrisballance.com/Blog/2009/03/21/TheOfficialCWPTeamTrain.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://www.chrisballance.com/Blog/Trackback.aspx?guid=14a3c590-05e8-46b5-9b47-db5338492928</trackback:ping>
      <pingback:server>http://www.chrisballance.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisballance.com/Blog/PermaLink,guid,14a3c590-05e8-46b5-9b47-db5338492928.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://www.chrisballance.com/Blog/CommentView,guid,14a3c590-05e8-46b5-9b47-db5338492928.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisballance.com/Blog/SyndicationService.asmx/GetEntryCommentsRss?guid=14a3c590-05e8-46b5-9b47-db5338492928</wfw:commentRss>
      <title>Building the CWP Train</title>
      <guid isPermaLink="false">http://www.chrisballance.com/Blog/PermaLink,guid,14a3c590-05e8-46b5-9b47-db5338492928.aspx</guid>
      <link>http://feedproxy.google.com/~r/Ballance/~3/cnLmx99GtK4/BuildingTheCWPTrain.aspx</link>
      <pubDate>Fri, 20 Mar 2009 04:14:28 GMT</pubDate>
      <description>&lt;div style="float: right; margin-left: 10px; margin-bottom: 10px;"&gt;
&lt;object type="application/x-shockwave-flash" width="585" height="440" data="http://www.flickr.com/apps/video/stewart.swf?v=68975" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"&gt;
&lt;param name="flashvars" value="intl_lang=en-us&amp;photo_secret=6447877896&amp;photo_id=3369794702&amp;show_info_box=true"&gt;
&gt;
&lt;param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=68975"&gt;
&gt;
&lt;param name="bgcolor" value="#000000"&gt;
&gt;
&lt;param name="allowFullScreen" value="true"&gt;
&gt;&lt;embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=68975" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&amp;photo_secret=6447877896&amp;photo_id=3369794702&amp;flickr_show_info_box=true" height="440" width="585"&gt;&lt;/embed&gt;
&lt;/object&gt;
&lt;br /&gt;
&lt;span style="font-size: 0.9em; margin-top: 0px;"&gt;&lt;a href="http://www.flickr.com/photos/ballance/3369794702/"&gt;MVI_4166&lt;/a&gt;
&lt;br /&gt;
Originally uploaded by &lt;a href="http://www.flickr.com/people/ballance/"&gt;ballance5702&lt;/a&gt;&lt;/span&gt;
&lt;/div&gt;
Testing the smokestack system for the official Grand Central train.&lt;br clear="all" /&gt;
&lt;img width="0" height="0" src="http://www.chrisballance.com/Blog/aggbug.ashx?id=14a3c590-05e8-46b5-9b47-db5338492928" /&gt;</description>
      <comments>http://www.chrisballance.com/Blog/CommentView,guid,14a3c590-05e8-46b5-9b47-db5338492928.aspx</comments>
    <feedburner:origLink>http://www.chrisballance.com/Blog/2009/03/20/BuildingTheCWPTrain.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://www.chrisballance.com/Blog/Trackback.aspx?guid=6004d5cb-03a2-4413-be2a-b1b9918f4eac</trackback:ping>
      <pingback:server>http://www.chrisballance.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisballance.com/Blog/PermaLink,guid,6004d5cb-03a2-4413-be2a-b1b9918f4eac.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://www.chrisballance.com/Blog/CommentView,guid,6004d5cb-03a2-4413-be2a-b1b9918f4eac.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisballance.com/Blog/SyndicationService.asmx/GetEntryCommentsRss?guid=6004d5cb-03a2-4413-be2a-b1b9918f4eac</wfw:commentRss>
      <title>Google Charts API and States I've travelled to</title>
      <guid isPermaLink="false">http://www.chrisballance.com/Blog/PermaLink,guid,6004d5cb-03a2-4413-be2a-b1b9918f4eac.aspx</guid>
      <link>http://feedproxy.google.com/~r/Ballance/~3/bh761gDTgFg/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;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"&gt; 
&lt;/p&gt;
&lt;p&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;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"&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&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;cht=gom&amp;chd=t:40&amp;chl=Milk%20left%20in%20refrigerator"&gt;&lt;img width="0" height="0" src="http://www.chrisballance.com/Blog/aggbug.ashx?id=6004d5cb-03a2-4413-be2a-b1b9918f4eac" /&gt;</description>
      <comments>http://www.chrisballance.com/Blog/CommentView,guid,6004d5cb-03a2-4413-be2a-b1b9918f4eac.aspx</comments>
      <category>General</category>
      <category>Personal</category>
      <category>Programming</category>
      <category>Travel</category>
    <feedburner:origLink>http://www.chrisballance.com/Blog/2009/03/01/GoogleChartsAPIAndStatesIveTravelledTo.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://www.chrisballance.com/Blog/Trackback.aspx?guid=3d2afa34-b66d-4b43-9f82-bb4a496c4367</trackback:ping>
      <pingback:server>http://www.chrisballance.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisballance.com/Blog/PermaLink,guid,3d2afa34-b66d-4b43-9f82-bb4a496c4367.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://www.chrisballance.com/Blog/CommentView,guid,3d2afa34-b66d-4b43-9f82-bb4a496c4367.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisballance.com/Blog/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="http://www.chrisballance.com/Blog/content/binary/stackoverflowBadge.png" />
        </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://www.chrisballance.com/Blog/aggbug.ashx?id=3d2afa34-b66d-4b43-9f82-bb4a496c4367" />
      </body>
      <title>Show your Stackoverflow.com badge on your blog</title>
      <guid isPermaLink="false">http://www.chrisballance.com/Blog/PermaLink,guid,3d2afa34-b66d-4b43-9f82-bb4a496c4367.aspx</guid>
      <link>http://feedproxy.google.com/~r/Ballance/~3/ynAMOJWzdbI/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="http://www.chrisballance.com/Blog/content/binary/stackoverflowBadge.png"&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;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;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;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;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;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;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;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;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://www.chrisballance.com/Blog/aggbug.ashx?id=3d2afa34-b66d-4b43-9f82-bb4a496c4367" /&gt;</description>
      <comments>http://www.chrisballance.com/Blog/CommentView,guid,3d2afa34-b66d-4b43-9f82-bb4a496c4367.aspx</comments>
      <category>General</category>
      <category>Programming</category>
    <feedburner:origLink>http://www.chrisballance.com/Blog/2009/02/23/ShowYourStackoverflowcomBadgeOnYourBlog.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://www.chrisballance.com/Blog/Trackback.aspx?guid=e45b4313-cf50-46ca-a3c0-6a65c33c1bdc</trackback:ping>
      <pingback:server>http://www.chrisballance.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisballance.com/Blog/PermaLink,guid,e45b4313-cf50-46ca-a3c0-6a65c33c1bdc.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://www.chrisballance.com/Blog/CommentView,guid,e45b4313-cf50-46ca-a3c0-6a65c33c1bdc.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisballance.com/Blog/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://www.chrisballance.com/so/">Current StackOverflow.com Rankings</a>
        </p>
        <img border="0" src="http://www.chrisballance.com/Blog/content/binary/StackOverflowRankings.png" />
        <img width="0" height="0" src="http://www.chrisballance.com/Blog/aggbug.ashx?id=e45b4313-cf50-46ca-a3c0-6a65c33c1bdc" />
      </body>
      <title>Finding your rank on Stackoverflow.com</title>
      <guid isPermaLink="false">http://www.chrisballance.com/Blog/PermaLink,guid,e45b4313-cf50-46ca-a3c0-6a65c33c1bdc.aspx</guid>
      <link>http://feedproxy.google.com/~r/Ballance/~3/WlxE5FLYDCQ/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://www.chrisballance.com/so/"&gt;Current StackOverflow.com Rankings&lt;/a&gt;
&lt;/p&gt;
&lt;img border=0 src="http://www.chrisballance.com/Blog/content/binary/StackOverflowRankings.png"&gt;&lt;img width="0" height="0" src="http://www.chrisballance.com/Blog/aggbug.ashx?id=e45b4313-cf50-46ca-a3c0-6a65c33c1bdc" /&gt;</description>
      <comments>http://www.chrisballance.com/Blog/CommentView,guid,e45b4313-cf50-46ca-a3c0-6a65c33c1bdc.aspx</comments>
      <category>General</category>
      <category>Personal</category>
      <category>Programming</category>
    <feedburner:origLink>http://www.chrisballance.com/Blog/2009/02/17/FindingYourRankOnStackoverflowcom.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://www.chrisballance.com/Blog/Trackback.aspx?guid=704c3a47-0006-4f22-9155-18ff796a6ab2</trackback:ping>
      <pingback:server>http://www.chrisballance.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisballance.com/Blog/PermaLink,guid,704c3a47-0006-4f22-9155-18ff796a6ab2.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://www.chrisballance.com/Blog/CommentView,guid,704c3a47-0006-4f22-9155-18ff796a6ab2.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisballance.com/Blog/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://www.chrisballance.com/Blog/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://www.chrisballance.com/Blog/PermaLink,guid,704c3a47-0006-4f22-9155-18ff796a6ab2.aspx</guid>
      <link>http://feedproxy.google.com/~r/Ballance/~3/m7wTyZkBcrg/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://www.chrisballance.com/Blog/aggbug.ashx?id=704c3a47-0006-4f22-9155-18ff796a6ab2" /&gt;</description>
      <comments>http://www.chrisballance.com/Blog/CommentView,guid,704c3a47-0006-4f22-9155-18ff796a6ab2.aspx</comments>
      <category>Programming</category>
    <feedburner:origLink>http://www.chrisballance.com/Blog/2009/02/10/FindingPrimeNumbersFasterThanIThoughtPossibleWithThisLittleBitOfCodeEuler7.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://www.chrisballance.com/Blog/Trackback.aspx?guid=ad580c1a-2e52-4d0d-92de-7fb5e79327fe</trackback:ping>
      <pingback:server>http://www.chrisballance.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisballance.com/Blog/PermaLink,guid,ad580c1a-2e52-4d0d-92de-7fb5e79327fe.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://www.chrisballance.com/Blog/CommentView,guid,ad580c1a-2e52-4d0d-92de-7fb5e79327fe.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisballance.com/Blog/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 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.Diagnostics; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">namespace</span> Euler6
{ <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) { 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">long</span> result <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> SumDifference(1,
100); 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(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"Sum
difference is: "</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">+</span> result);
Console.ReadLine(); } <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">long</span> SumDifference(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> begin, <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> end)
{ <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span> SquareOfSums(begin,
end) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">-</span> SumOfSquares(begin,
end); } <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">long</span> SumOfSquares(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> begin, <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> end)
{ <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">long</span> returnValue <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">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> begin;
i &lt;= end; i++) { returnValue += Convert.ToInt64(Math.Pow(i,2)); } <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span> returnValue;
} <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">long</span> SquareOfSums(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> begin, <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> end)
{ <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">long</span> returnValue <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">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> begin;
i &lt;= end; i++) { returnValue += i; } <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span> Convert.ToInt64(Math.Pow(returnValue,
2)); } } }</span>
        </pre>
        <img width="0" height="0" src="http://www.chrisballance.com/Blog/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://www.chrisballance.com/Blog/PermaLink,guid,ad580c1a-2e52-4d0d-92de-7fb5e79327fe.aspx</guid>
      <link>http://feedproxy.google.com/~r/Ballance/~3/KWly6rX7z0Q/CMethodForFindingTheMathematicalDifferenceBetweenTheSumOfSquaresAndSquareOfSumsEuler6.aspx</link>
      <pubDate>Tue, 10 Feb 2009 04:01:49 GMT</pubDate>
      <description>&lt;p&gt;
Euler #6 is very straightforward.&amp;nbsp; I was concerned about needing to work with
numbers &amp;gt; 2^32, but this was not a factor.&amp;nbsp; 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).&amp;nbsp; Runtime is &amp;lt; 1 ms, only ~2400 ticks.
&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.Diagnostics; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;namespace&lt;/span&gt; Euler6
{ &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) { 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;long&lt;/span&gt; result &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; SumDifference(1,
100); 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(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"Sum
difference is: "&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;+&lt;/span&gt; result);
Console.ReadLine(); } &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;long&lt;/span&gt; SumDifference(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; begin, &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; end)
{ &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; SquareOfSums(begin,
end) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;-&lt;/span&gt; SumOfSquares(begin,
end); } &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;long&lt;/span&gt; SumOfSquares(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; begin, &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; end)
{ &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;long&lt;/span&gt; returnValue &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;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; begin;
i &amp;lt;= end; i++) { returnValue += Convert.ToInt64(Math.Pow(i,2)); } &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; returnValue;
} &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;long&lt;/span&gt; SquareOfSums(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; begin, &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; end)
{ &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;long&lt;/span&gt; returnValue &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;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; begin;
i &amp;lt;= end; i++) { returnValue += i; } &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&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://www.chrisballance.com/Blog/aggbug.ashx?id=ad580c1a-2e52-4d0d-92de-7fb5e79327fe" /&gt;</description>
      <comments>http://www.chrisballance.com/Blog/CommentView,guid,ad580c1a-2e52-4d0d-92de-7fb5e79327fe.aspx</comments>
      <category>Programming</category>
    <feedburner:origLink>http://www.chrisballance.com/Blog/2009/02/10/CMethodForFindingTheMathematicalDifferenceBetweenTheSumOfSquaresAndSquareOfSumsEuler6.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://www.chrisballance.com/Blog/Trackback.aspx?guid=359bedca-fccc-4e79-aff9-f87037cde20f</trackback:ping>
      <pingback:server>http://www.chrisballance.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisballance.com/Blog/PermaLink,guid,359bedca-fccc-4e79-aff9-f87037cde20f.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://www.chrisballance.com/Blog/CommentView,guid,359bedca-fccc-4e79-aff9-f87037cde20f.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisballance.com/Blog/SyndicationService.asmx/GetEntryCommentsRss?guid=359bedca-fccc-4e79-aff9-f87037cde20f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <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">
              <p>
                <font color="#006400" size="3" face="Verdana">This one was elusively easy since I
went with a simple brute-force approach.  Execution averages 1 second.</font>
              </p>
            </span>
          </span>
        </pre>
        <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.Diagnostics; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">namespace</span> Euler5
{ <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) { 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">int</span> lcm <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> FindLeastCommonMultiple();
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(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"LCM
is "</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">+</span> lcm);
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">int</span> FindLeastCommonMultiple()
{ <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> 2520;
i &lt; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span>.MaxValue;
i += 20) { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">if</span> (IsDivisibleByRange(i,
1, 20)) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span> i;
} <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span> -1;
} <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">long</span> SmallestNumber()
{ <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span> factorial(20);
} <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">long</span> factorial(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">long</span> n)
{ <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">long</span> returnValue <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> 1; <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> 1;
i &lt; n; i++) { returnValue *= i; } <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span> returnValue;
} <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> IsDivisibleByRange(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> num, <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> begin, <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> end)
{ <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> begin;
i &lt;= end; i++) { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">if</span> ((num <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">%</span> i)
!<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">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">return</span><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://www.chrisballance.com/Blog/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://www.chrisballance.com/Blog/PermaLink,guid,359bedca-fccc-4e79-aff9-f87037cde20f.aspx</guid>
      <link>http://feedproxy.google.com/~r/Ballance/~3/Xxwuy6pN9HM/ProgramaticallyFindingTheLeastCommonMultipleOfTheNumbers1To20Euler5.aspx</link>
      <pubDate>Tue, 10 Feb 2009 03:44:54 GMT</pubDate>
      <description>&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;
&lt;p&gt;
&lt;font color=#006400 size=3 face=Verdana&gt;This one was elusively easy since I went with
a simple brute-force approach.&amp;nbsp; Execution averages 1 second.&lt;/font&gt;
&lt;/span&gt;&lt;/span&gt;&gt;
&lt;/pre&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.Diagnostics; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;namespace&lt;/span&gt; Euler5
{ &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) { 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;int&lt;/span&gt; lcm &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; FindLeastCommonMultiple();
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(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"LCM
is "&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;+&lt;/span&gt; lcm);
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;int&lt;/span&gt; FindLeastCommonMultiple()
{ &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; 2520;
i &amp;lt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt;.MaxValue;
i += 20) { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;if&lt;/span&gt; (IsDivisibleByRange(i,
1, 20)) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; i;
} &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; -1;
} &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;long&lt;/span&gt; SmallestNumber()
{ &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; factorial(20);
} &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;long&lt;/span&gt; factorial(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;long&lt;/span&gt; n)
{ &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;long&lt;/span&gt; returnValue &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; 1; &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; 1;
i &amp;lt; n; i++) { returnValue *= i; } &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; returnValue;
} &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; IsDivisibleByRange(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; num, &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; begin, &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; end)
{ &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; begin;
i &amp;lt;= end; i++) { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;if&lt;/span&gt; ((num &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;%&lt;/span&gt; i)
!&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;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;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&gt;&lt;/pre&gt;
&lt;img width="0" height="0" src="http://www.chrisballance.com/Blog/aggbug.ashx?id=359bedca-fccc-4e79-aff9-f87037cde20f" /&gt;</description>
      <comments>http://www.chrisballance.com/Blog/CommentView,guid,359bedca-fccc-4e79-aff9-f87037cde20f.aspx</comments>
      <category>Programming</category>
    <feedburner:origLink>http://www.chrisballance.com/Blog/2009/02/10/ProgramaticallyFindingTheLeastCommonMultipleOfTheNumbers1To20Euler5.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://www.chrisballance.com/Blog/Trackback.aspx?guid=f573980f-67cd-4060-9b39-5bd827935884</trackback:ping>
      <pingback:server>http://www.chrisballance.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisballance.com/Blog/PermaLink,guid,f573980f-67cd-4060-9b39-5bd827935884.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://www.chrisballance.com/Blog/CommentView,guid,f573980f-67cd-4060-9b39-5bd827935884.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisballance.com/Blog/SyndicationService.asmx/GetEntryCommentsRss?guid=f573980f-67cd-4060-9b39-5bd827935884</wfw:commentRss>
      <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://www.chrisballance.com/Blog/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://www.chrisballance.com/Blog/PermaLink,guid,f573980f-67cd-4060-9b39-5bd827935884.aspx</guid>
      <link>http://feedproxy.google.com/~r/Ballance/~3/0eCBMBmWteE/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://www.chrisballance.com/Blog/aggbug.ashx?id=f573980f-67cd-4060-9b39-5bd827935884" /&gt;</description>
      <comments>http://www.chrisballance.com/Blog/CommentView,guid,f573980f-67cd-4060-9b39-5bd827935884.aspx</comments>
      <category>Programming</category>
    <feedburner:origLink>http://www.chrisballance.com/Blog/2009/02/10/FindingTheLargestPallindromeProductOfTwoThreeDigitIntegers.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://www.chrisballance.com/Blog/Trackback.aspx?guid=f65a9a24-eb6a-4373-ab93-90fa17ad563d</trackback:ping>
      <pingback:server>http://www.chrisballance.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisballance.com/Blog/PermaLink,guid,f65a9a24-eb6a-4373-ab93-90fa17ad563d.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://www.chrisballance.com/Blog/CommentView,guid,f65a9a24-eb6a-4373-ab93-90fa17ad563d.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisballance.com/Blog/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="http://www.chrisballance.com/Blog/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://www.chrisballance.com/Blog/aggbug.ashx?id=f65a9a24-eb6a-4373-ab93-90fa17ad563d" />
      </body>
      <title>Fun with Prime Factorization</title>
      <guid isPermaLink="false">http://www.chrisballance.com/Blog/PermaLink,guid,f65a9a24-eb6a-4373-ab93-90fa17ad563d.aspx</guid>
      <link>http://feedproxy.google.com/~r/Ballance/~3/nrBiRrYIgss/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="http://www.chrisballance.com/Blog/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://www.chrisballance.com/Blog/aggbug.ashx?id=f65a9a24-eb6a-4373-ab93-90fa17ad563d" /&gt;</description>
      <comments>http://www.chrisballance.com/Blog/CommentView,guid,f65a9a24-eb6a-4373-ab93-90fa17ad563d.aspx</comments>
      <category>Programming</category>
    <feedburner:origLink>http://www.chrisballance.com/Blog/2009/01/22/FunWithPrimeFactorization.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://www.chrisballance.com/Blog/Trackback.aspx?guid=1150dda4-a7f0-4af4-9734-0e16d7a863d9</trackback:ping>
      <pingback:server>http://www.chrisballance.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisballance.com/Blog/PermaLink,guid,1150dda4-a7f0-4af4-9734-0e16d7a863d9.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://www.chrisballance.com/Blog/CommentView,guid,1150dda4-a7f0-4af4-9734-0e16d7a863d9.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisballance.com/Blog/SyndicationService.asmx/GetEntryCommentsRss?guid=1150dda4-a7f0-4af4-9734-0e16d7a863d9</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
On my commute into the office this morning I heard of the most recent government bail-out
of a private bank, CitiGroup.  This is the second second installment, at CitiGroup
alone, of taxpayer dollars being used to try and fix problems the average taxpayer
did not create.
</p>
        <p>
While it makes some sense to put measures into place to ensure that major financial
companies do not fail and collapse industries beyond the financial sectors, are we
fundamentally doing the right thing by the American taxpayer?
</p>
        <p>
Of course not!
</p>
        <p>
          <img src="http://www.chrisballance.com/Blog/content/binary/citiactYourShoeSize.jpg" border="0" />
          <br />
          <span class="Apple-style-span" style="WORD-SPACING: 0px; FONT: 11px Arial; TEXT-TRANSFORM: none; COLOR: rgb(102,102,102); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; orphans: 2; widows: 2; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0">photo
courtesy of <a title="Link to dalydose's photostream" style="COLOR: rgb(0,99,220); TEXT-DECORATION: underline" href="http://www.flickr.com/photos/dalydose/"><b>dalydose</b></a></span>
        </p>
        <p>
Have we reached the point that our government is borrowing money to cover for haphazard
and irresponsible behavior by investors and BANKS?  Why yes, yes we have. 
But who started this mess?
</p>
        <p>
The way I see it, here is how the snowball began rolling downhill:
</p>
        <ul>
          <li>
For the past 10 years or more since the tightening of regulation following the savings
and loan crisis, government regulation of the U.S. financial markets has loosened
significantly.<br /></li>
          <li>
Banks saw this combined with low interest rates as opportunities to increase their
revenues significantly by tapping into the elusive "subprime loan" market.<br /></li>
          <li>
A increasingly credit hungry society took advantage of achieving the previously out
of reach so-called "American dream" of home ownership, regardless of whether or not
this made good financial sense for them at the time.  (The former "dream" is
now more of a nightmare.)<br /></li>
          <li>
Banks decided they could crank up profits by closing a bunch of loans quickly and
immediately selling the loans to someone else so they didn't have to keep these risky
investments in-house, on their own balance sheets.<br /></li>
          <li>
Banks, unsure of exactly what was the current risk with these subprime mortgages started
selling "mortgage backed securities" like hotcakes.  Investors and other banks
bought them by the truckload.<br /></li>
          <li>
Ratings agencies tasked with rating the risk of these strange new investment vehicles
did a rotten job rating the actual risk and kept slapping AAA ratings on everything
in sight<br /></li>
          <li>
Mortgages within these investment backed securities start failing exponentially, and
banks start cleverly hiding them off their balance sheets.<br /></li>
          <li>
Banks start to fail, starting with smaller players, then major banks and financial
powerhouses start to fail when they can no longer hide their failing mostly-imaginary-now
investments.<br /></li>
          <li>
And then....the story comes full circle....and here comes Uncle Sam to save the banks
by throwing BORROWED money at the problem to buy up these toxic financial investments.</li>
        </ul>
        <p>
Who screwed up?  Most everyone involved screwed up in one way or another. 
But who enabled this to happen?  As we have seen, given enough rope, investors
and banks will hang themselves.  
</p>
        <p>
Perhaps we should stop providing the rope and repeal the <a href="http://banking.senate.gov/conf/">Gramm-Leach-Biley
Act</a> that allowed the creation of Citigroup and others?  
</p>
        <p>
Hindsight aside, why did we let Lehman fail and others who made the exact same bad
decisions survive?
</p>
        <p>
It's time for a large helping of what everyone should have had more of all along,
Fiscal Responsibility.
</p>
        <a href="http://www.chrisballance.com/Blog/content/binary/Gramm-Leach-Bliley_Vote_1999.png">Gramm-Leach-Bliley_Vote_1999.png
(138.89 KB)</a>
        <img width="0" height="0" src="http://www.chrisballance.com/Blog/aggbug.ashx?id=1150dda4-a7f0-4af4-9734-0e16d7a863d9" />
      </body>
      <title>The Vicious cycle of irresponsiblity and really bad ideas gone worse</title>
      <guid isPermaLink="false">http://www.chrisballance.com/Blog/PermaLink,guid,1150dda4-a7f0-4af4-9734-0e16d7a863d9.aspx</guid>
      <link>http://feedproxy.google.com/~r/Ballance/~3/-zsvbCzcWp8/TheViciousCycleOfIrresponsiblityAndReallyBadIdeasGoneWorse.aspx</link>
      <pubDate>Tue, 25 Nov 2008 02:04:39 GMT</pubDate>
      <description>&lt;p&gt;
On my commute into the office this morning I heard of the most recent government bail-out
of a private bank, CitiGroup.&amp;nbsp; This is the second second installment, at CitiGroup
alone, of taxpayer dollars being used to try and fix problems the average taxpayer
did not create.
&lt;/p&gt;
&lt;p&gt;
While it makes some sense to put measures into place to ensure that major financial
companies do not fail and collapse industries beyond the financial sectors, are we
fundamentally doing the right thing by the American taxpayer?
&lt;/p&gt;
&lt;p&gt;
Of course not!
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.chrisballance.com/Blog/content/binary/citiactYourShoeSize.jpg" border=0&gt;
&lt;br&gt;
&lt;span class=Apple-style-span style="WORD-SPACING: 0px; FONT: 11px Arial; TEXT-TRANSFORM: none; COLOR: rgb(102,102,102); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; orphans: 2; widows: 2; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0"&gt;photo
courtesy of &lt;a title="Link to dalydose's photostream" style="COLOR: rgb(0,99,220); TEXT-DECORATION: underline" href="http://www.flickr.com/photos/dalydose/"&gt;&lt;b&gt;dalydose&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
Have we reached the point that our government is borrowing money to cover for haphazard
and irresponsible behavior by investors and BANKS?&amp;nbsp; Why yes, yes we have.&amp;nbsp;
But who started this mess?
&lt;/p&gt;
&lt;p&gt;
The way I see it, here is how the snowball began rolling downhill:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
For the past 10 years or more since the tightening of regulation following the savings
and loan crisis, government regulation of the U.S. financial markets has loosened
significantly.&lt;br&gt;
&lt;li&gt;
Banks saw this combined with low interest rates as opportunities to increase their
revenues significantly by tapping into the elusive "subprime loan" market.&lt;br&gt;
&lt;li&gt;
A increasingly credit hungry society took advantage of achieving the previously out
of reach so-called "American dream" of home ownership, regardless of whether or not
this made good financial sense for them at the time.&amp;nbsp; (The former "dream" is
now more of a nightmare.)&lt;br&gt;
&lt;li&gt;
Banks decided they could crank up profits by closing a bunch of loans quickly and
immediately selling the loans to someone else so they didn't have to keep these risky
investments in-house, on their own balance sheets.&lt;br&gt;
&lt;li&gt;
Banks, unsure of exactly what was the current risk with these subprime mortgages started
selling "mortgage backed securities" like hotcakes.&amp;nbsp; Investors and other banks
bought them by the truckload.&lt;br&gt;
&lt;li&gt;
Ratings agencies tasked with rating the risk of these strange new investment vehicles
did a rotten job rating the actual risk and kept slapping AAA ratings on everything
in sight&lt;br&gt;
&lt;li&gt;
Mortgages within these investment backed securities start failing exponentially, and
banks start cleverly hiding them off their balance sheets.&lt;br&gt;
&lt;li&gt;
Banks start to fail, starting with smaller players, then major banks and financial
powerhouses start to fail when they can no longer hide their failing mostly-imaginary-now
investments.&lt;br&gt;
&lt;li&gt;
And then....the story comes full circle....and here comes Uncle Sam to save the banks
by throwing BORROWED money at the problem to buy up these toxic financial investments.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Who screwed up?&amp;nbsp; Most everyone involved screwed up in one way or another.&amp;nbsp;
But who enabled this to happen?&amp;nbsp; As we have seen, given enough rope, investors
and banks will hang themselves.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
Perhaps we should stop providing the rope and repeal the &lt;a href="http://banking.senate.gov/conf/"&gt;Gramm-Leach-Biley
Act&lt;/a&gt;&amp;nbsp;that allowed the creation of Citigroup and others?&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
Hindsight aside, why did we let Lehman fail and others who made the exact same bad
decisions survive?
&lt;/p&gt;
&lt;p&gt;
It's time for a large helping of what everyone should have had more of all along,
Fiscal Responsibility.
&lt;/p&gt;
&lt;a href="http://www.chrisballance.com/Blog/content/binary/Gramm-Leach-Bliley_Vote_1999.png"&gt;Gramm-Leach-Bliley_Vote_1999.png
(138.89 KB)&lt;/a&gt;&lt;img width="0" height="0" src="http://www.chrisballance.com/Blog/aggbug.ashx?id=1150dda4-a7f0-4af4-9734-0e16d7a863d9" /&gt;</description>
      <comments>http://www.chrisballance.com/Blog/CommentView,guid,1150dda4-a7f0-4af4-9734-0e16d7a863d9.aspx</comments>
      <category>economics</category>
      <category>General</category>
    <feedburner:origLink>http://www.chrisballance.com/Blog/2008/11/25/TheViciousCycleOfIrresponsiblityAndReallyBadIdeasGoneWorse.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://www.chrisballance.com/Blog/Trackback.aspx?guid=225a7c3b-c4ce-4de5-bde8-cfa124dd552c</trackback:ping>
      <pingback:server>http://www.chrisballance.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisballance.com/Blog/PermaLink,guid,225a7c3b-c4ce-4de5-bde8-cfa124dd552c.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://www.chrisballance.com/Blog/CommentView,guid,225a7c3b-c4ce-4de5-bde8-cfa124dd552c.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisballance.com/Blog/SyndicationService.asmx/GetEntryCommentsRss?guid=225a7c3b-c4ce-4de5-bde8-cfa124dd552c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Likely a fake, but a cool video nonetheless....<br /><br />
Plane loses a wing during an air show and then flawlessly lands the plane.
</p>
        <p>
          <img src="http://www.chrisballance.com/Blog/content/binary/planeloseswing.jpg" border="0" />
          <br />
          <font color="#000000">photo courtesy of </font>
          <a title="" href="http://www.flickr.com/photos/baggis/">
            <b>
              <font color="#000000">Travis
S.</font>
            </b>
          </a>
          <font color="#000000">
          </font>
        </p>
        <p>
          <font color="#000000">Video: </font>
          <a href="http://www.chrisballance.com/Blog/content/binary/planeLosesWing.wmv">planeLosesWing.wmv
(1.51 MB)</a>
        </p>
        <img width="0" height="0" src="http://www.chrisballance.com/Blog/aggbug.ashx?id=225a7c3b-c4ce-4de5-bde8-cfa124dd552c" />
      </body>
      <title>Landing a plane with one wing</title>
      <guid isPermaLink="false">http://www.chrisballance.com/Blog/PermaLink,guid,225a7c3b-c4ce-4de5-bde8-cfa124dd552c.aspx</guid>
      <link>http://feedproxy.google.com/~r/Ballance/~3/HvNAB9nAPrI/LandingAPlaneWithOneWing.aspx</link>
      <pubDate>Tue, 11 Nov 2008 20:42:09 GMT</pubDate>
      <description>&lt;p&gt;
Likely a fake, but a cool video nonetheless....&lt;br&gt;
&lt;br&gt;
Plane loses a wing during an air show and then flawlessly lands the plane.
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.chrisballance.com/Blog/content/binary/planeloseswing.jpg" border=0&gt;
&lt;br&gt;
&lt;font color=#000000&gt;photo courtesy of&amp;nbsp;&lt;/font&gt;&lt;a title="" href="http://www.flickr.com/photos/baggis/"&gt;&lt;b&gt;&lt;font color=#000000&gt;Travis
S.&lt;/font&gt;&lt;/b&gt;&lt;/a&gt;&lt;font color=#000000&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000&gt;Video: &lt;/font&gt;&lt;a href="http://www.chrisballance.com/Blog/content/binary/planeLosesWing.wmv"&gt;planeLosesWing.wmv
(1.51 MB)&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.chrisballance.com/Blog/aggbug.ashx?id=225a7c3b-c4ce-4de5-bde8-cfa124dd552c" /&gt;</description>
      <comments>http://www.chrisballance.com/Blog/CommentView,guid,225a7c3b-c4ce-4de5-bde8-cfa124dd552c.aspx</comments>
      <category>General</category>
    <feedburner:origLink>http://www.chrisballance.com/Blog/2008/11/11/LandingAPlaneWithOneWing.aspx</feedburner:origLink></item>
    <item>
      <trackback:ping>http://www.chrisballance.com/Blog/Trackback.aspx?guid=4ce1c949-c020-4df8-b0ee-8641275d0cee</trackback:ping>
      <pingback:server>http://www.chrisballance.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisballance.com/Blog/PermaLink,guid,4ce1c949-c020-4df8-b0ee-8641275d0cee.aspx</pingback:target>
      <dc:creator>Chris Ballance</dc:creator>
      <wfw:comment>http://www.chrisballance.com/Blog/CommentView,guid,4ce1c949-c020-4df8-b0ee-8641275d0cee.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisballance.com/Blog/SyndicationService.asmx/GetEntryCommentsRss?guid=4ce1c949-c020-4df8-b0ee-8641275d0cee</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font face="Tahoma">
          </font>
        </p>
        <p>
          <font size="3">The UAW and what's left of the ‘not-so-big-anymore’ Three.</font>
        </p>
        <p>
          <font size="1">
            <font color="#a9a9a9">
              <img src="http://www.chrisballance.com/Blog/content/binary/renaissanceCenter.jpg" border="0" />
              <br />
Photo of the Renaissance Center by <span class="Apple-style-span" style="WORD-SPACING: 0px; FONT: 11px Arial; TEXT-TRANSFORM: none; COLOR: rgb(102,102,102); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; TEXT-ALIGN: left; orphans: 2; widows: 2; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0"><a title="" style="COLOR: rgb(0,99,220); TEXT-DECORATION: underline" href="http://www.flickr.com/photos/chrisjman/"><b>Casino
Jones</b></a></span></font>
          </font>
        </p>
        <p>
The basic premise of any Trade Union is to work to achieve the common goals of its
members. These common goals can range from higher wages, better working conditions,
improved benefits, to any key factor affecting member workers. These organizations
rose out of 18th century industrialization in order for personnel to collectively
bargain for a better deal than they could negotiate on their own. With minimal labor
laws on the books and significantly dismal working conditions in industry, these groups
championed harsh and unfair conditions through various methods and put power into
the hands of rank and file employees who otherwise would have had no capacity to make
things any better on their own.
</p>
        <p>
While they bear stark similarities to Medieval Guilds in their member composition,
their basic premise diverges significantly. The key difference that makes many modern
ones self-defeating is that their interests do not lie in the preservation of the
Corporations their workers are employed by. In many cases their only role seems to
spite the companies of their members.
</p>
        <p>
Trade Unions exist in order to restore an order lost in the employer’s lack of vested
interest in the goals for which the unions are created. They work to restore an order
that would otherwise be lost without the collective bargaining power they provide.
During early industrialization, these entities were essential to workers.
</p>
        <p>
The case in point is the United Auto Workers Union (UAW). The “Big Three” in the U.S.
are often referred to as “Pension Funds that just happen to have car companies attached
to them.” Unfortunately, the realization of this just doesn’t become apparent to those
who could do something about the situation.
</p>
        <p>
General Motors, Ford, and Chrysler have become dinosaurs that simply cannot compete
in today’s market, end of story. Fueled by big oil in more ways than one, they have
consciously chosen to continue doing things the way they always worked, “build it
and someone will buy it.” With a lineup of models orders of magnitude more numerous
than leaner, more efficient competitors, they have lost sight of one of the most basic
principals of doing business successfully.<strong> “Do one thing, and do it well”</strong> Compare
the model offerings of Volkswagen or BMW and the problem becomes more apparent. American
car companies have become Jacks of All Trades, inherently doing none of them well.
Poor management, a disconnect with what consumers want and really need, and I would
venture to guess Chronic American Isolationism and inflexibility have all contributed
heavily to their serious loss of market share and profitability in the last decade.
</p>
        <p>
However, the most serious problem they currently face is that without major changes
in their fundamental ways of conducting business, they will all be gone and carved
up to the highest bidder within a year. While too late to save Chrysler, Ford and
GM could stand a chance if they would heed the following:
</p>
        <p>
          <b>Disband the UAW immediately and fire every worker that refuses to burn their union
card.</b>
        </p>
        <p>
Harsh as this sounds, and it is, the only way they can hope to have a possible path
to viability in the market again is to take this route, effective yesterday if possible.
The UAW, and many other Trade Unions, are vestiges of a bygone time and lack
relevance in today’s market. How does a group sworn to protect its members do so by
being the single largest factor in putting their members’ employers completely out
of business? Each and every worker has needs that should be met to the best of the
ability of their employer, but let’s be realistic folks. The UAW jumped the shark
years ago and this destructive path taken in the name of those it claims to protect
is a ruthless paradox.
</p>
        <p>
A recent strike organized by the UAW was one of the most laughable and pointless ventures
imaginable. Shutting down the assembly lines for which the end products have few or
no interested buyers? This just defies the most basic capitalist principals,<strong> Supply
and Demand</strong>. If the demand for what you supply is severely waning, bullying
those in charge of selling these outmoded and undesirable products has <em>no hope
of improving your situation</em>.
</p>
        <p>
The pension plans put into place by the Big Three during good economic times, and
dependent on the continuation of that prosperity are going to have to be re-evaluated
and modified such that they are sustainable. An overarching symbol that applies to
several parts of this equation is Sustainability. Sustainable promises to employees,
or none at all if nothing can truly be delivered, sustainable products that meet the
needs of the consumer, and sustainable long term plans which take into account diminishing
demands for the product the way it is currently made.
</p>
        <p>
Obviously there is no silver bullet, but the UAW and the policies it has bargained
for and put into place are killing auto-making in this country. This is not something
that can be fixed; it needs to go away as quickly as possible such the Big Three can
rapidly generate plans for a road to recovery. It’s only a starting point, but a crucial
one that cannot be ignored. The dichotomy between what the workers really want and
need and what the UAW is fighting for on their behalf should be abundantly obvious
by now, but somehow is not. There is no blood to be had from a turnip, no matter how
effectively you negotiate with said turnip. 
</p>
        <p>
The current efforts by the Obama camp, including House Speaker Nancy Pelosi and Senator
Harry Reid, are wholly misguided and if carried through will only prolong the inevitable,
and do so on our dime. If companies are poorly managed, make bad decisions, and can
no longer compete in the market due to the culminations of decisions they have made
and directions they have freely chosen to go, then they <strong>fully deserve their
fate</strong>. Loans and government subsidies seem like a quick fix to do what we
can to save these companies, but let’s face it they just aren’t worth saving. They
had their fair chance, and face-planted in the dirt time and time again. It’s simple
capitalism, and Darwin wouldn’t have it any other way. 
</p>
        <img width="0" height="0" src="http://www.chrisballance.com/Blog/aggbug.ashx?id=4ce1c949-c020-4df8-b0ee-8641275d0cee" />
      </body>
      <title>Biting the Hand That Feeds</title>
      <guid isPermaLink="false">http://www.chrisballance.com/Blog/PermaLink,guid,4ce1c949-c020-4df8-b0ee-8641275d0cee.aspx</guid>
      <link>http://feedproxy.google.com/~r/Ballance/~3/fUnF3CO_RDY/BitingTheHandThatFeeds.aspx</link>
      <pubDate>Mon, 10 Nov 2008 03:56:01 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font face=Tahoma&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=3&gt;The UAW and what's left&amp;nbsp;of the&amp;nbsp;‘not-so-big-anymore’ Three.&lt;/font&gt;&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=1&gt;&lt;font color=#a9a9a9&gt;&lt;img src="http://www.chrisballance.com/Blog/content/binary/renaissanceCenter.jpg" border=0&gt;
&lt;br&gt;
Photo of the Renaissance Center by &lt;span class=Apple-style-span style="WORD-SPACING: 0px; FONT: 11px Arial; TEXT-TRANSFORM: none; COLOR: rgb(102,102,102); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; TEXT-ALIGN: left; orphans: 2; widows: 2; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0"&gt;&lt;a title="" style="COLOR: rgb(0,99,220); TEXT-DECORATION: underline" href="http://www.flickr.com/photos/chrisjman/"&gt;&lt;b&gt;Casino
Jones&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
The basic premise of any Trade Union is to work to achieve the common goals of its
members. These common goals can range from higher wages, better working conditions,
improved benefits, to any key factor affecting member workers. These organizations
rose out of 18th century industrialization in order for personnel to collectively
bargain for a better deal than they could negotiate on their own. With minimal labor
laws on the books and significantly dismal working conditions in industry, these groups
championed harsh and unfair conditions through various methods and put power into
the hands of rank and file employees who otherwise would have had no capacity to make
things any better on their own.
&lt;/p&gt;
&lt;p&gt;
While they bear stark similarities to Medieval Guilds in their member composition,
their basic premise diverges significantly. The key difference that makes many modern
ones self-defeating is that their interests do not lie in the preservation of the
Corporations their workers are employed by. In many cases their only role seems to
spite the companies of their members.
&lt;/p&gt;
&lt;p&gt;
Trade Unions exist in order to restore an order lost in the employer’s lack of vested
interest in the goals for which the unions are created. They work to restore an order
that would otherwise be lost without the collective bargaining power they provide.
During early industrialization, these entities were essential to workers.
&lt;/p&gt;
&lt;p&gt;
The case in point is the United Auto Workers Union (UAW). The “Big Three” in the U.S.
are often referred to as “Pension Funds that just happen to have car companies attached
to them.” Unfortunately, the realization of this just doesn’t become apparent to those
who could do something about the situation.
&lt;/p&gt;
&lt;p&gt;
General Motors, Ford, and Chrysler have become dinosaurs that simply cannot compete
in today’s market, end of story. Fueled by big oil in more ways than one, they have
consciously chosen to continue doing things the way they always worked, “build it
and someone will buy it.” With a lineup of models orders of magnitude more numerous
than leaner, more efficient competitors, they have lost sight of one of the most basic
principals of doing business successfully.&lt;strong&gt; “Do one thing, and do it well”&lt;/strong&gt; Compare
the model offerings of Volkswagen or BMW and the problem becomes more apparent. American
car companies have become Jacks of All Trades, inherently doing none of them well.
Poor management, a disconnect with what consumers want and really need, and I would
venture to guess Chronic American Isolationism and inflexibility have all contributed
heavily to their serious loss of market share and profitability in the last decade.
&lt;/p&gt;
&lt;p&gt;
However, the most serious problem they currently face is that without major changes
in their fundamental ways of conducting business, they will all be gone and carved
up to the highest bidder within a year. While too late to save Chrysler, Ford and
GM could stand a chance if they would heed the following:
&lt;/p&gt;
&lt;p&gt;
&lt;b&gt;Disband the UAW immediately and fire every worker that refuses to burn their union
card.&lt;/b&gt;
&lt;/p&gt;
&lt;p&gt;
Harsh as this sounds, and it is, the only way they can hope to have a possible path
to viability in the market again is to take this route, effective yesterday if possible.
The UAW, and many other Trade Unions,&amp;nbsp;are vestiges of a bygone time and lack
relevance in today’s market. How does a group sworn to protect its members do so by
being the single largest factor in putting their members’ employers completely out
of business? Each and every worker has needs that should be met to the best of the
ability of their employer, but let’s be realistic folks. The UAW jumped the shark
years ago and this destructive path taken in the name of those it claims to protect
is a ruthless paradox.
&lt;/p&gt;
&lt;p&gt;
A recent strike organized by the UAW was one of the most laughable and pointless ventures
imaginable. Shutting down the assembly lines for which the end products have few or
no interested buyers? This just defies the most basic&amp;nbsp;capitalist principals,&lt;strong&gt; Supply
and Demand&lt;/strong&gt;. If the demand for what you supply is severely waning, bullying
those in charge of selling these outmoded and undesirable products has &lt;em&gt;no hope
of improving your situation&lt;/em&gt;.
&lt;/p&gt;
&lt;p&gt;
The pension plans put into place by the Big Three during good economic times, and
dependent on the continuation of that prosperity are going to have to be re-evaluated
and modified such that they are sustainable. An overarching symbol that applies to
several parts of this equation is Sustainability. Sustainable promises to employees,
or none at all if nothing can truly be delivered, sustainable products that meet the
needs of the consumer, and sustainable long term plans which take into account diminishing
demands for the product the way it is currently made.
&lt;/p&gt;
&lt;p&gt;
Obviously there is no silver bullet, but the UAW and the policies it has bargained
for and put into place are killing auto-making in this country. This is not something
that can be fixed; it needs to go away as quickly as possible such the Big Three can
rapidly generate plans for a road to recovery. It’s only a starting point, but a crucial
one that cannot be ignored. The dichotomy between what the workers really want and
need and what the UAW is fighting for on their behalf should be abundantly obvious
by now, but somehow is not. There is no blood to be had from a turnip, no matter how
effectively you negotiate with said turnip. 
&lt;/p&gt;
&lt;p&gt;
The current efforts by the Obama camp, including House Speaker Nancy Pelosi and Senator
Harry Reid, are wholly misguided and if carried through will only prolong the inevitable,
and do so on our dime. If companies are poorly managed, make bad decisions, and can
no longer compete in the market due to the culminations of decisions they have made
and directions they have freely chosen to go, then they &lt;strong&gt;fully deserve their
fate&lt;/strong&gt;. Loans and government subsidies seem like a quick fix to do what we
can to save these companies, but let’s face it they just aren’t worth saving. They
had their fair chance, and face-planted in the dirt time and time again. It’s simple
capitalism, and Darwin wouldn’t have it any other way. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.chrisballance.com/Blog/aggbug.ashx?id=4ce1c949-c020-4df8-b0ee-8641275d0cee" /&gt;</description>
      <comments>http://www.chrisballance.com/Blog/CommentView,guid,4ce1c949-c020-4df8-b0ee-8641275d0cee.aspx</comments>
      <category>economics</category>
      <category>General</category>
    <feedburner:origLink>http://www.chrisballance.com/Blog/2008/11/10/BitingTheHandThatFeeds.aspx</feedburner:origLink></item>
  </channel>
</rss>
