<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>I Write</title>
	<atom:link href="http://dharampal.name/feed/" rel="self" type="application/rss+xml" />
	<link>http://dharampal.name</link>
	<description>A blog about nothing in particular</description>
	<lastBuildDate>Sun, 31 May 2009 21:12:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>muffled thoughts..</title>
		<link>http://dharampal.name/2009/06/01/muffled-thoughts/</link>
		<comments>http://dharampal.name/2009/06/01/muffled-thoughts/#comments</comments>
		<pubDate>Sun, 31 May 2009 21:12:30 +0000</pubDate>
		<dc:creator>CodeMangler</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://blog.dharampal.name/?p=69</guid>
		<description><![CDATA[strange that the only girl I could ever say &#8220;I love you&#8221; to with conviction, couldn&#8217;t care less about it.. and rightly so, considering we know so little about each other and I&#8217;ve spoiled every chance I probably had to fix that sometimes I think I should just accept it and move on.. but then, [...]]]></description>
			<content:encoded><![CDATA[<p>strange that the only girl I could ever say <em>&#8220;I love you&#8221;</em> to with conviction, couldn&#8217;t care less about it.. and rightly so, considering we know so little about each other and I&#8217;ve spoiled every chance I probably had to fix that <img src='http://dharampal.name/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>sometimes I think I should just accept it and move on..</p>
<p>but then, I wish for just <em>one</em> more chance to fix it.. knowing all the time that I never will get one..</p>
<p>wish I could forget it all and pretend it was all a dream.. but then there&#8217;re these random incidents that always bring back the memories..</p>
<p>wonder why there&#8217;s nothing to erase these memories.. are memories always this persistent?</p>
]]></content:encoded>
			<wfw:commentRss>http://dharampal.name/2009/06/01/muffled-thoughts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>First triangle number to have over five hundred divisors</title>
		<link>http://dharampal.name/2009/01/28/first-triangle-number-to-have-over-five-hundred-divisors/</link>
		<comments>http://dharampal.name/2009/01/28/first-triangle-number-to-have-over-five-hundred-divisors/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 17:19:32 +0000</pubDate>
		<dc:creator>CodeMangler</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[project euler]]></category>

		<guid isPermaLink="false">http://blog.dharampal.name/?p=56</guid>
		<description><![CDATA[This was another interesting problem at Project Euler (Problem 12). Interesting because the naïve solution to this was all too trivial but slow, which forced me to seek out a better approach and I finally ended up learning something new   The nth triangle number is defined as the sum of all natural numbers till [...]]]></description>
			<content:encoded><![CDATA[<p>This was another interesting problem at <a href="http://projecteuler.net/" target="_blank">Project Euler</a> (<a href="http://projecteuler.net/index.php?section=problems&amp;id=12" target="_blank">Problem 12</a>). Interesting because the naïve solution to this was all too trivial but slow, which forced me to seek out a better approach and I finally ended up learning something new <img src='http://dharampal.name/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p>The <em>nth</em> triangle number is defined as the sum of all natural numbers till <em>n</em>. Well, that&#8217;s definitely trivial to calculate. It&#8217;s basically the sum of first n natural numbers and can be calculated using the well known formula:<span>  <a href="http://dharampal.info/wp-content/uploads/2009/01/sum-of-first-n-natural-numbers.gif"><img class="alignnone size-medium wp-image-57" title="sum-of-first-n-natural-numbers" src="http://dharampal.info/wp-content/uploads/2009/01/sum-of-first-n-natural-numbers.gif" alt="" width="58" height="36" /></a> </span></p>
<p>So, all that remains is to calculate the divisors and we all know how to do that right? Just count the numbers from 2 to half (or square root, if you prefer) the triangle number that divide the triangle number. So, here&#8217;s the code I started with: </p>

<div class="wp_syntax"><div class="code"><pre class="ocaml" style="font-family:monospace;"><span style="color: #a52a2a;">//</span> Sum <span style="color: #06c; font-weight: bold;">of</span> first n natural numbers
<span style="color: #06c; font-weight: bold;">let</span> triangle_number <span style="color: #6c6;">&#40;</span>n<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
    <span style="color: #6c6;">&#40;</span>n <span style="color: #a52a2a;">*</span> <span style="color: #6c6;">&#40;</span>n <span style="color: #a52a2a;">+</span> 1I<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">/</span> 2I <span style="color: #a52a2a;">;;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> divisors <span style="color: #6c6;">&#40;</span>n<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
    <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">rec</span> divisor_loop <span style="color: #6c6;">&#40;</span>i<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#40;</span>a_list<span style="color: #a52a2a;">:</span>bigint list<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
        <span style="color: #06c; font-weight: bold;">if</span> <span style="color: #6c6;">&#40;</span>i <span style="color: #a52a2a;">=</span> 1I<span style="color: #6c6;">&#41;</span> <span style="color: #06c; font-weight: bold;">then</span>
            <span style="color: #6c6;">&#40;</span>i <span style="color: #a52a2a;">::</span> a_list<span style="color: #6c6;">&#41;</span>
        <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">if</span> <span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#40;</span>n <span style="color: #a52a2a;">%</span> i<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span> 0I<span style="color: #6c6;">&#41;</span> <span style="color: #06c; font-weight: bold;">then</span>
            <span style="color: #6c6;">&#40;</span>divisor_loop <span style="color: #6c6;">&#40;</span>i <span style="color: #a52a2a;">-</span> 1I<span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#40;</span>i <span style="color: #a52a2a;">::</span> a_list<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span>
        <span style="color: #06c; font-weight: bold;">else</span>
            <span style="color: #6c6;">&#40;</span>divisor_loop <span style="color: #6c6;">&#40;</span>i <span style="color: #a52a2a;">-</span> 1I<span style="color: #6c6;">&#41;</span> a_list<span style="color: #6c6;">&#41;</span>
&nbsp;
    <span style="color: #6c6;">&#40;</span>divisor_loop <span style="color: #6c6;">&#40;</span>n <span style="color: #a52a2a;">/</span> 2I<span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#91;</span>n<span style="color: #a52a2a;">;</span><span style="color: #6c6;">&#93;</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;;</span></pre></div></div>

<p>As it turned out, using this method, it takes a really looooong time to even find the divisors of a large number, let alone use it for searching the triangle number with over 500 divisors.</p>
<p>So, I started looking for alternate methods, and finally found one here: <a href="http://www.algebra-online.com/positive-integral-divisors-1.htm" target="_blank">http://www.algebra-online.com/positive-integral-divisors-1.htm</a> (you&#8217;ll have to scroll to the end of the page to get to the part where they explain finding the number of divisors for a number)</p>
<p>The idea is simple actually. Take <em>5050</em> for example (the <em>100</em>th triangle number). It&#8217;s prime factors are: <em>2, 5, 5</em> and <em>101</em>. Now reduce the list to a list of unique numbers with their repetition represented in their exponents. So, the list <em>2, 5, 5, 101</em> becomes: <em>2<sup>1</sup>, 5<sup>2</sup>,101<sup>1</sup></em>. Now, add <em>1</em> to every exponent and multiply the resulting numbers. So, that would give us: <em>(1+1) * (2 + 1) * (1 + 1) = 12</em>. That&#8217;s the number of divisors that <em>5050</em> has. And, of course, that can be verified using the divisors method:</p>
<pre>(divisors 5050I);; -&gt; [1I; 2I; 5I; 10I; 25I; 50I; 101I; 202I; 505I; 1010I; 2525I; 5050I]</pre>
<p>Since I&#8217;d already written a function to find the prime factors to solve <a href="http://projecteuler.net/index.php?section=problems&amp;id=3" target="_blank">Problem 3</a>, solving this one was just a matter of writing code to search through a list of triangle numbers to find the first one with more than 500 divisors. Here&#8217;s the final code I ended up with:</p>

<div class="wp_syntax"><div class="code"><pre class="ocaml" style="font-family:monospace;"><span style="color: #a52a2a;">//</span> Sum <span style="color: #06c; font-weight: bold;">of</span> first n natural numbers
<span style="color: #06c; font-weight: bold;">let</span> triangle_number <span style="color: #6c6;">&#40;</span>n<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
    <span style="color: #6c6;">&#40;</span>n <span style="color: #a52a2a;">*</span> <span style="color: #6c6;">&#40;</span>n <span style="color: #a52a2a;">+</span> 1I<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">/</span> 2I <span style="color: #a52a2a;">;;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> divides <span style="color: #6c6;">&#40;</span>n<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#40;</span>i<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
    n <span style="color: #a52a2a;">%</span> i <span style="color: #a52a2a;">=</span> 0I <span style="color: #a52a2a;">;;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> is_prime <span style="color: #6c6;">&#40;</span>n<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
    <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">rec</span> prime_check_loop <span style="color: #6c6;">&#40;</span>i<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
        <span style="color: #6c6;">&#40;</span> i <span style="color: #a52a2a;">&gt;</span> <span style="color: #6c6;">&#40;</span>n <span style="color: #a52a2a;">/</span> 2I<span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">||</span> <span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">not</span> <span style="color: #6c6;">&#40;</span>i <span style="color: #a52a2a;">|&gt;</span> divides n<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">&amp;&amp;</span> prime_check_loop <span style="color: #6c6;">&#40;</span>i <span style="color: #a52a2a;">+</span> 1I<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span>
&nbsp;
    prime_check_loop 2I <span style="color: #a52a2a;">;;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">rec</span> prime_factors <span style="color: #6c6;">&#40;</span>n<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#40;</span>factors<span style="color: #a52a2a;">:</span>bigint list<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
    <span style="color: #06c; font-weight: bold;">if</span> <span style="color: #6c6;">&#40;</span>is_prime n<span style="color: #6c6;">&#41;</span> <span style="color: #06c; font-weight: bold;">then</span>
        n <span style="color: #a52a2a;">::</span> factors
    <span style="color: #06c; font-weight: bold;">else</span>
        <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">mutable</span> i<span style="color: #a52a2a;">:</span>bigint <span style="color: #a52a2a;">=</span> 2I<span style="color: #a52a2a;">;</span>
        <span style="color: #06c; font-weight: bold;">while</span> <span style="color: #6c6;">&#40;</span>n <span style="color: #a52a2a;">%</span> i <span style="color: #a52a2a;">&lt;&gt;</span> 0I<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">&amp;&amp;</span> <span style="color: #6c6;">&#40;</span>i <span style="color: #a52a2a;">&lt;=</span> n<span style="color: #a52a2a;">/</span>2I<span style="color: #6c6;">&#41;</span> <span style="color: #06c; font-weight: bold;">do</span>
            i <span style="color: #a52a2a;">&lt;-</span> i <span style="color: #a52a2a;">+</span> 1I
        <span style="color: #06c; font-weight: bold;">done</span>
&nbsp;
        <span style="color: #06c; font-weight: bold;">if</span><span style="color: #6c6;">&#40;</span> i <span style="color: #a52a2a;">&lt;=</span> n<span style="color: #a52a2a;">/</span>2I<span style="color: #6c6;">&#41;</span> <span style="color: #06c; font-weight: bold;">then</span>
            factors @ <span style="color: #6c6;">&#40;</span>prime_factors i factors<span style="color: #6c6;">&#41;</span> @ <span style="color: #6c6;">&#40;</span>prime_factors <span style="color: #6c6;">&#40;</span>n <span style="color: #a52a2a;">/</span> i<span style="color: #6c6;">&#41;</span> factors<span style="color: #6c6;">&#41;</span>
        <span style="color: #06c; font-weight: bold;">else</span>
            <span style="color: #6c6;">&#91;</span><span style="color: #6c6;">&#93;</span> <span style="color: #a52a2a;">;;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">open</span> System<span style="color: #a52a2a;">.</span><span style="color: #060;">Collections</span><span style="color: #a52a2a;">.</span><span style="color: #060;">Generic</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> prime_factor_map <span style="color: #6c6;">&#40;</span>factors<span style="color: #a52a2a;">:</span>bigint list<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
    <span style="color: #06c; font-weight: bold;">let</span> factor_map <span style="color: #a52a2a;">=</span> Dictionary<span style="color: #a52a2a;">&lt;</span>bigint, bigint<span style="color: #a52a2a;">&gt;</span><span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span>
&nbsp;
    <span style="color: #06c; font-weight: bold;">for</span> factor <span style="color: #06c; font-weight: bold;">in</span> factors <span style="color: #06c; font-weight: bold;">do</span>
        <span style="color: #06c; font-weight: bold;">if</span> <span style="color: #6c6;">&#40;</span>factor_map<span style="color: #a52a2a;">.</span><span style="color: #060;">ContainsKey</span><span style="color: #6c6;">&#40;</span>factor<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span> <span style="color: #06c; font-weight: bold;">then</span>
            factor_map<span style="color: #a52a2a;">.</span><span style="color: #6c6;">&#91;</span>factor<span style="color: #6c6;">&#93;</span> <span style="color: #a52a2a;">&lt;-</span> <span style="color: #6c6;">&#40;</span>factor_map<span style="color: #a52a2a;">.</span><span style="color: #6c6;">&#91;</span>factor<span style="color: #6c6;">&#93;</span> <span style="color: #a52a2a;">+</span> 1I<span style="color: #6c6;">&#41;</span>
        <span style="color: #06c; font-weight: bold;">else</span>
            factor_map<span style="color: #a52a2a;">.</span><span style="color: #060;">Add</span><span style="color: #6c6;">&#40;</span>factor, 1I<span style="color: #6c6;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">done</span>
&nbsp;
    factor_map <span style="color: #a52a2a;">;;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> number_of_divisors <span style="color: #6c6;">&#40;</span>n<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
    <span style="color: #06c; font-weight: bold;">let</span> factor_map <span style="color: #a52a2a;">=</span> <span style="color: #6c6;">&#40;</span>prime_factors n <span style="color: #6c6;">&#91;</span><span style="color: #6c6;">&#93;</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">|&gt;</span> prime_factor_map
    <span style="color: #06c; font-weight: bold;">let</span> exponents <span style="color: #a52a2a;">=</span> factor_map<span style="color: #a52a2a;">.</span><span style="color: #060;">Values</span>
    <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">mutable</span> divisor_count <span style="color: #a52a2a;">=</span> 1I
&nbsp;
    <span style="color: #06c; font-weight: bold;">for</span> exponent <span style="color: #06c; font-weight: bold;">in</span> exponents <span style="color: #06c; font-weight: bold;">do</span>
        divisor_count <span style="color: #a52a2a;">&lt;-</span> <span style="color: #6c6;">&#40;</span>divisor_count <span style="color: #a52a2a;">*</span> <span style="color: #6c6;">&#40;</span>exponent <span style="color: #a52a2a;">+</span> 1I<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">done</span>
&nbsp;
    divisor_count <span style="color: #a52a2a;">;;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> triangle_number_search <span style="color: #6c6;">&#40;</span>minimum_divisor_count<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
    <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">mutable</span> keep_searching <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">true</span>
    <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">mutable</span> next <span style="color: #a52a2a;">=</span> 1I
    <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">mutable</span> n <span style="color: #a52a2a;">=</span> <span style="color: #6c6;">&#40;</span>triangle_number next<span style="color: #6c6;">&#41;</span>
&nbsp;
    <span style="color: #06c; font-weight: bold;">while</span> keep_searching <span style="color: #06c; font-weight: bold;">do</span>
        <span style="color: #06c; font-weight: bold;">let</span> divisor_count <span style="color: #a52a2a;">=</span> <span style="color: #6c6;">&#40;</span>number_of_divisors n<span style="color: #6c6;">&#41;</span>
        <span style="color: #06c; font-weight: bold;">if</span> <span style="color: #6c6;">&#40;</span>divisor_count <span style="color: #a52a2a;">&lt;</span> minimum_divisor_count<span style="color: #6c6;">&#41;</span> <span style="color: #06c; font-weight: bold;">then</span>
            next <span style="color: #a52a2a;">&lt;-</span> next <span style="color: #a52a2a;">+</span> 1I
            n <span style="color: #a52a2a;">&lt;-</span> <span style="color: #6c6;">&#40;</span>triangle_number next<span style="color: #6c6;">&#41;</span>
        <span style="color: #06c; font-weight: bold;">else</span>
            keep_searching <span style="color: #a52a2a;">&lt;-</span> <span style="color: #06c; font-weight: bold;">false</span>
    <span style="color: #06c; font-weight: bold;">done</span>
    n <span style="color: #a52a2a;">;;</span></pre></div></div>

<p>This took less than a minute to run and running it gives:</p>
<pre>(triangle_number_search 500I);; -&gt; 76576500I</pre>
<p>So, the first triangle number to have over 500 divisors is: <em>76576500</em><br />
(btw, it has 576 divisors)</p>
<p>(and as you can see, I&#8217;m still not very proficient with F# <img src='http://dharampal.name/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  )</p>
]]></content:encoded>
			<wfw:commentRss>http://dharampal.name/2009/01/28/first-triangle-number-to-have-over-five-hundred-divisors/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Identifying Auto Properties in Assemblies</title>
		<link>http://dharampal.name/2009/01/17/identifying-auto-properties-in-assemblies/</link>
		<comments>http://dharampal.name/2009/01/17/identifying-auto-properties-in-assemblies/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 21:43:00 +0000</pubDate>
		<dc:creator>CodeMangler</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://blog.dharampal.name/?p=47</guid>
		<description><![CDATA[My current project is a UML modeling tool, and I&#8217;m working on the C# 3.0 bits. One of the things it lets you do is to Reverse Engineer your code and obtain the model. And that includes reversing the assemblies too. C# 3.0 introduced Auto Properties (or Automatically Implemented Properties if you like the wordy [...]]]></description>
			<content:encoded><![CDATA[<p>My current project is a UML modeling tool, and I&#8217;m working on the C# 3.0 bits. One of the things it lets you do is to Reverse Engineer your code and obtain the model. And that includes reversing the assemblies too.</p>
<p>C# 3.0 introduced <a href="http://msdn.microsoft.com/en-us/library/bb384054.aspx" target="_blank">Auto Properties</a> (or <a href="http://msdn.microsoft.com/en-us/library/bb384054.aspx" target="_blank">Automatically Implemented Properties</a> if you like the wordy versions <img src='http://dharampal.name/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  ), and the tool lets you model them. To maintain the symmetry, reverse engineering should detect and mark the Auto Properties appropriately. This&#8217;s easy in case of a source file since the rule for identifying an Auto Property is pretty simple. <em>It&#8217;s a property contained in a concrete type (non-abstract class/struct) which has both it&#8217;s accessors without their implementing bodies</em>. Simple, eh?</p>
<p>But it gets a wee bit more complicated to do that once you compile it. Because, the compiler <em>generates</em> a body for the Auto Property accessors. So, the last bit about the accessors not having an implementing body fails. Essentially, it seems like there&#8217;s no way to distingush an Auto Property from a regular one once it&#8217;s been compiled. And in fact, you shouldn&#8217;t have to because that&#8217;s the whole idea! Auto Properties help reduce some clutter in code and possibly save you a few keystrokes and let the compiler do the gruntwork. So, if you&#8217;re trying to distinguish an Auto Property, think again. You probably don&#8217;t have to.</p>
<p>Anyways, I still wanted to see if there&#8217;s a way to do it and the first thing I did was to Google for it. Since that didn&#8217;t turn up anything useful, I decided to figure it out myself and fired up Reflector. Long story (relative to a blog post, that is) short, I figured it out <em>and</em> decided to write this post to fill up a gaping hole in the public knowledge base <img src='http://dharampal.name/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>The C# compiler decorates all the stuff it generates with the <a href="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.compilergeneratedattribute.aspx" target="_blank">CompilerGeneratedAttribute</a>. Even vbc.exe &amp; vjc.exe should do the same, but I haven&#8217;t checked. Since the accessors of an Auto Property are generated, they&#8217;re decorated too <img src='http://dharampal.name/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Therefore, the rule for identifying an Auto Property after it&#8217;s been compiled is: <em>It&#8217;s a property which has both the accessors, both of which have been decorated with the CompilerGeneratedAttribute</em>. Simple isn&#8217;t it?</p>
<p>Here&#8217;s what my C# code looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Reflection</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Runtime.CompilerServices</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> PropertyWrapper
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">private</span> PropertyInfo _property<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> PropertyWrapper<span style="color: #000000;">&#40;</span>PropertyInfo property<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		_property <span style="color: #008000;">=</span> property<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> IsAutoProperty
	<span style="color: #000000;">&#123;</span>
            get
            <span style="color: #000000;">&#123;</span>
            	<span style="color: #0600FF;">return</span> isGenerated<span style="color: #000000;">&#40;</span>_property.<span style="color: #0000FF;">GetGetMethod</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #008000;">&amp;&amp;</span> isGenerated<span style="color: #000000;">&#40;</span>_property.<span style="color: #0000FF;">GetSetMethod</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">bool</span> isGenerated<span style="color: #000000;">&#40;</span>MethodInfo method<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">return</span> method <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span>
            <span style="color: #008000;">&amp;&amp;</span> method.<span style="color: #0000FF;">GetCustomAttributes</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>CompilerGeneratedAttribute<span style="color: #000000;">&#41;</span>, <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Ironically, <em>after</em> doing all these, I realized there&#8217;s not much sense in distinguishing them anyway. I mean, they are your regular properties for most of the purposes. Moreover, in my case, the the information derived from the assembly is used only to let the user extend the existing types. i.e. create generalizations and such.. So, even the existing implementation doesn&#8217;t bother showing the assembly types in much detail. They&#8217;re mostly limited to the high level details like classes, interfaces and such..</p>
<p>Ultimately, it wasn&#8217;t really useful, but was interesting nonetheless <img src='http://dharampal.name/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://dharampal.name/2009/01/17/identifying-auto-properties-in-assemblies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Subtext</title>
		<link>http://dharampal.name/2008/12/27/subtext/</link>
		<comments>http://dharampal.name/2008/12/27/subtext/#comments</comments>
		<pubDate>Sat, 27 Dec 2008 21:51:10 +0000</pubDate>
		<dc:creator>CodeMangler</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[subtext]]></category>

		<guid isPermaLink="false">http://blog.dharampal.name/?p=36</guid>
		<description><![CDATA[Subtext is a visual programming language where you express the application logic in a tabular fashion. I&#8217;m not gonna try to explain Subtext in this post. You can find out more from its homepage: http://subtextual.org/. I learned about Subtext nearly 2 months back. It sounded interesting, but all I could find on the site were [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://subtextual.org/" target="_blank">Subtext</a> is a visual programming language where you express the application logic in a tabular fashion. I&#8217;m not gonna try to explain Subtext in this post. You can find out more from its homepage: <a href="http://subtextual.org/" target="_blank">http://subtextual.org/</a>.</p>
<p>I learned about <a href="http://subtextual.org/" target="_blank">Subtext</a> nearly 2 months back. It sounded interesting, but all I could find on the site were 2 screencasts and a bunch of papers. Apparently, it&#8217;s still a research project and the prototype used in the <a href="http://subtextual.org/subtext2.html" target="_blank">screencast</a> isn&#8217;t publicly available yet. I was a little disappointed, and almost forgot about it until today.</p>
<p>Today, someone posted <a href="http://4.flowsnake.org/archives/327" target="_blank">this link</a> on <a href="http://www.reddit.com/r/programming/" target="_blank">programming reddit</a> where <a href="http://blog.darevay.com/" target="_blank">someone</a> had posted a <a href="http://alarmingdevelopment.org/?p=160" target="_blank">link</a> to the the page where <a href="http://subtextual.org/AboutMe.htm" target="_blank">Jonathan Edwards</a> (Subtext creator) has posted a <a href="http://subtextual.org/subtext2.zip" target="_blank">link</a> to the prototype used in the demo! (hmm.. that was just 3 indirections <img src='http://dharampal.name/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />   but still, here&#8217;s a direct link to the download if all that confused you: <a href="http://subtextual.org/subtext2.zip" target="_blank">http://subtextual.org/subtext2.zip</a> ) Yay! Finally, something for me to dabble with <img src='http://dharampal.name/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   And guess what, it&#8217;s even got the sources! <img src='http://dharampal.name/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I&#8217;m not expecting much from the prototype (not yet). Good if it&#8217;s mature enough for me to go beyond the hello worldish programs. Even otherwise, I&#8217;m happy just to play around <img src='http://dharampal.name/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://dharampal.name/2008/12/27/subtext/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sum of all the primes below two million</title>
		<link>http://dharampal.name/2008/12/25/sum-of-all-the-primes-below-two-million/</link>
		<comments>http://dharampal.name/2008/12/25/sum-of-all-the-primes-below-two-million/#comments</comments>
		<pubDate>Thu, 25 Dec 2008 12:48:38 +0000</pubDate>
		<dc:creator>CodeMangler</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[project euler]]></category>

		<guid isPermaLink="false">http://blog.dharampal.name/?p=23</guid>
		<description><![CDATA[I&#8217;ve written about Project Euler in my previous post (which I guess was the day before yesterday). I was going pretty well with solving the problems until I reached this one &#8211; to calculate the sum of all primes below 2 million. That&#8217;s the 10th problem in Project Euler and the one I&#8217;ve had to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written about <a href="http://projecteuler.net/" target="_blank">Project Euler</a> in my <a href="http://blog.dharampal.name/2008/12/23/project-euler/" target="_blank">previous post</a> (which I guess was the day before yesterday). I was going pretty well with solving the problems until I reached <a href="http://projecteuler.net/index.php?section=problems&amp;id=10" target="_blank">this one</a> &#8211; to calculate the sum of all primes below 2 million. That&#8217;s the 10th problem in <a href="http://projecteuler.net/" target="_blank">Project Euler</a> and the one I&#8217;ve had to spend the most time on till now. It&#8217;s a fairly trivial problem, if you exclude the scale that is. If you&#8217;re planning to calculate 2 million primes with your regular algorithm which checks each number for primality, then you better run it on a supercomputer <img src='http://dharampal.name/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>I&#8217;m solving these problems in <a href="http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/default.aspx" target="_blank">F#</a>, and this&#8217;s what I started with:</p>

<div class="wp_syntax"><div class="code"><pre class="ocaml" style="font-family:monospace;">&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> divides <span style="color: #6c6;">&#40;</span>n<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#40;</span>x<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
    n <span style="color: #a52a2a;">%</span> x <span style="color: #a52a2a;">=</span> 0I<span style="color: #a52a2a;">;;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> is_prime <span style="color: #6c6;">&#40;</span>n<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
    <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">rec</span> prime_check_loop <span style="color: #6c6;">&#40;</span>i<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
        <span style="color: #6c6;">&#40;</span> i <span style="color: #a52a2a;">&gt;</span> <span style="color: #6c6;">&#40;</span>n <span style="color: #a52a2a;">/</span> 2I<span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">||</span> <span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">not</span> <span style="color: #6c6;">&#40;</span>i <span style="color: #a52a2a;">|&gt;</span> divides n<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">&amp;&amp;</span> prime_check_loop <span style="color: #6c6;">&#40;</span>i <span style="color: #a52a2a;">+</span> 1I<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span>
&nbsp;
    prime_check_loop 2I<span style="color: #a52a2a;">;;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">rec</span> next_prime <span style="color: #6c6;">&#40;</span>from<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
    <span style="color: #06c; font-weight: bold;">if</span> from <span style="color: #a52a2a;">&lt;</span> 2I <span style="color: #06c; font-weight: bold;">then</span> 2I
    <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">if</span> is_prime <span style="color: #6c6;">&#40;</span>from <span style="color: #a52a2a;">+</span> 1I<span style="color: #6c6;">&#41;</span> <span style="color: #06c; font-weight: bold;">then</span> <span style="color: #6c6;">&#40;</span>from <span style="color: #a52a2a;">+</span> 1I<span style="color: #6c6;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">else</span> next_prime <span style="color: #6c6;">&#40;</span>from <span style="color: #a52a2a;">+</span> 1I<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;;</span></pre></div></div>

<p>As a quick test, I tried calculating the next prime after 2 million and got the result fairly immediately. Happy with that, I started writing the summation code.</p>

<div class="wp_syntax"><div class="code"><pre class="ocaml" style="font-family:monospace;">&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> sum_of_primes_below <span style="color: #6c6;">&#40;</span>limit<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
    <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">rec</span> add_prime <span style="color: #6c6;">&#40;</span>n<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#40;</span>acc<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
        <span style="color: #06c; font-weight: bold;">let</span> next <span style="color: #a52a2a;">=</span> next_prime n
        <span style="color: #06c; font-weight: bold;">if</span> next <span style="color: #a52a2a;">&lt;</span> limit <span style="color: #06c; font-weight: bold;">then</span>
            add_prime next <span style="color: #6c6;">&#40;</span>acc <span style="color: #a52a2a;">+</span> next<span style="color: #6c6;">&#41;</span>
         <span style="color: #06c; font-weight: bold;">else</span>
            acc
&nbsp;
    add_prime 0I 0I<span style="color: #a52a2a;">;;</span></pre></div></div>

<p>Did a quick check for the sum of primes below 10, 20, 200, 2000 and 20000. The last one took a bit of time, but that didn&#8217;t really concern me much. After all, it&#8217;s my computer doing the job right? <img src='http://dharampal.name/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>So, ask it to calculate the sum of all primes below 2 million and left it for a minute. I switch back to the F# interactive window and see that it&#8217;s still happily calculating. I check the <em>fsi.exe</em> process, and it&#8217;s maxing out one of the cores completely and taking around 50M. So, I leave it for a little longer. Now, I start getting worried about the range of BigInt and whether the result would overflow. So, I quickly google around and see that BigInt is for arbitrarily large integers. Then found that the SQL Sever BigInt is actually a 64 bit int, so guess even the .net type is the same, and that maxes out at 2<sup>64</sup> &#8211; 1 = 9,223,372,036,854,775,807. hmm.. Is the sum larger than that? It&#8217;s already been around 4 minutes and I&#8217;m impatient. So I google around for the solution and found a <a href="http://answers.yahoo.com/question/index?qid=20081112202726AARdL1X" target="_blank">Yahoo! Answers</a> page which says that the sum of all primes below 2 million is 142,913,828,922. That&#8217;s good. coz, now at least I&#8217;m confident that it won&#8217;t overflow and keep looping forever.</p>
<p>I knew that the <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes" target="_blank">Sieve of Eratosthenes</a> can be used to calculate primes, but always took it lightly. I mean, how often do you go about calculating an entire series of primes? Turns out, this is one of those times <img src='http://dharampal.name/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>I realized that <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes" target="_blank">Sieve of Eratosthenes</a> is probably the best solution for this problem, but since my code has already been running for over 10 min, I was hoping to get an answer anytime soon, so didn&#8217;t bother implementing the sieve. When I didn&#8217;t get the answer for another 20 mnutes, I had given up all hopes on my solution and I knew it was time I implemented the sieve. But just for curiosity, I tried estimating how long it&#8217;d take to get to the solution with my current method.</p>
<p>Assuming 1 sec per primality check, that&#8217;s about <a href="http://www.google.co.in/search?rlz=1C1GGLS_enIN300IN303&amp;sourceid=chrome&amp;ie=UTF-8&amp;q=2million+seconds+in+days" target="_blank">2 million seconds = 23.1481481 days</a>. Not good. Not good at all <img src='http://dharampal.name/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />   I thought that must be ridiculously wrong, since 2 million still didn&#8217;t seem like that large a number to handle. So, I tried running my code for 2000 (two thousand) and that took about a second. Then I ran it for 20000 (twenty thousand) and that took about 30 seconds. hmm.. That&#8217;s about a 30 times increase for a 10 times increase in the input size. So, for 200000 (two hundred thousand), it should take approximately 900 sec which&#8217;s 15 minutes. But well, I must&#8217;ve been estimating it completely wrong since even after 30 minutes, it was still calculating! <img src='http://dharampal.name/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />   But, even considering just 15 minutes for the two hundred thousand and extrapolating it, it&#8217;d have taken at least 7.5 hours! (which I did test and that estimate&#8217;s wrong too <img src='http://dharampal.name/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />   I left it overnight and woke up to see it still calculating.. )</p>
<p>So, finally I decided to generate primes with the sieve method and sum them up for the result. So, I ended up with this:</p>

<div class="wp_syntax"><div class="code"><pre class="ocaml" style="font-family:monospace;">&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> prime_series_sieve <span style="color: #6c6;">&#40;</span>limit<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
    <span style="color: #06c; font-weight: bold;">let</span> series <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">List</span><span style="color: #a52a2a;">.</span><span style="color: #060;">to_array</span> <span style="color: #6c6;">&#91;</span>0I<span style="color: #a52a2a;">..</span><span style="color: #060;">limit</span><span style="color: #6c6;">&#93;</span>
    series<span style="color: #a52a2a;">.</span><span style="color: #060;">SetValue</span><span style="color: #6c6;">&#40;</span>0I, <span style="color: #c6c;">1</span><span style="color: #6c6;">&#41;</span>
&nbsp;
    <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">rec</span> eliminate_multiples <span style="color: #6c6;">&#40;</span>n<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#40;</span>i<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
        <span style="color: #06c; font-weight: bold;">let</span> index <span style="color: #a52a2a;">=</span> <span style="color: #6c6;">&#40;</span>i <span style="color: #a52a2a;">*</span> n<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">//</span> Just <span style="color: #06c; font-weight: bold;">to</span> reduce <span style="color: #06c; font-weight: bold;">as</span> many calculations <span style="color: #06c; font-weight: bold;">as</span> possible
        <span style="color: #06c; font-weight: bold;">if</span> index <span style="color: #a52a2a;">&lt;</span> bigint<span style="color: #a52a2a;">.</span><span style="color: #060;">Parse</span><span style="color: #6c6;">&#40;</span>series<span style="color: #a52a2a;">.</span><span style="color: #060;">Length</span><span style="color: #a52a2a;">.</span><span style="color: #060;">ToString</span><span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span> <span style="color: #06c; font-weight: bold;">then</span>
            series<span style="color: #a52a2a;">.</span><span style="color: #060;">SetValue</span><span style="color: #6c6;">&#40;</span>0I, <span style="color: #6c6;">&#40;</span>bigint<span style="color: #a52a2a;">.</span><span style="color: #060;">ToInt64</span><span style="color: #6c6;">&#40;</span>index<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span>
            eliminate_multiples n <span style="color: #6c6;">&#40;</span>i <span style="color: #a52a2a;">+</span> 1I<span style="color: #6c6;">&#41;</span>
&nbsp;
    <span style="color: #06c; font-weight: bold;">for</span> n <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #6c6;">&#91;</span>2I<span style="color: #a52a2a;">..</span><span style="color: #6c6;">&#40;</span>limit<span style="color: #a52a2a;">/</span>2I<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#93;</span> <span style="color: #06c; font-weight: bold;">do</span>
        eliminate_multiples n 2I
&nbsp;
    series<span style="color: #a52a2a;">;;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> sum_of_primes_under <span style="color: #6c6;">&#40;</span>limit<span style="color: #a52a2a;">:</span>bigint<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
    <span style="color: #06c; font-weight: bold;">Array</span><span style="color: #a52a2a;">.</span><span style="color: #060;">sum</span> <span style="color: #6c6;">&#40;</span>prime_series_sieve limit<span style="color: #6c6;">&#41;</span><span style="color: #a52a2a;">;;</span></pre></div></div>

<p>After a few quick tests for the some smaller numbers, I let it calculate the for 2 million and hurray! It gave me the right answer! It took about 2.5 minutes and had a memory footprint of around 250 M, but I was happy just to get the answer <img src='http://dharampal.name/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Of course it can still be improved. The wikipedia page suggests a few optimizations like <a href="http://en.wikipedia.org/wiki/Wheel_factorization" target="_blank">Wheel Factorization</a>. But I&#8217;m not gonna worry about that for now. I&#8217;ve got <a href="http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/default.aspx" target="_blank">F#</a> to learn and a whole lotta problems to solve <img src='http://dharampal.name/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://dharampal.name/2008/12/25/sum-of-all-the-primes-below-two-million/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Project Euler</title>
		<link>http://dharampal.name/2008/12/23/project-euler/</link>
		<comments>http://dharampal.name/2008/12/23/project-euler/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 11:18:24 +0000</pubDate>
		<dc:creator>CodeMangler</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[project euler]]></category>

		<guid isPermaLink="false">http://blog.dharampal.name/?p=20</guid>
		<description><![CDATA[You’ve probably heard of Project Euler (http://projecteuler.net/). If you haven’t, I suggest you check it out. It’s an amazing collection of interesting mathematical and programming problems. Nowhere else have I seen such a quality collection of problems. I had known of Project Euler for a long time, but never found a good reason to actually [...]]]></description>
			<content:encoded><![CDATA[<p>You’ve probably heard of <a href="http://projecteuler.net/" target="_blank">Project Euler</a> (<a href="http://projecteuler.net/">http://projecteuler.net/</a>). If you haven’t, I suggest you check it out. It’s an amazing collection of interesting mathematical and programming problems. Nowhere else have I seen such a quality collection of problems.</p>
<p>I had known of <a href="http://projecteuler.net/" target="_blank">Project Euler</a> for a long time, but never found a good reason to actually try it out. Recently (3 days back) I thought of getting comfortable with F#. I believe that the best way to learn a language is to use it to solve some real problems. That’s when I remembered Project Euler.</p>
<p>Some of the problems over there can be answered with just pen and paper. But most of them require you to write some code in order to get to the solution. That’s not to say you can ignore the math behind it (hmm.. of course you can, but I wouldn’t suggest it <img class="wp-smiley" src="../wp-includes/images/smilies/icon_biggrin.gif" alt=":D" /> )  Understanding the underlying math concepts for a problem helps you devise better solutions (instead of going the brute-force way).</p>
<p>I’ve been sorta doing it the other way around. I look at a problem, chart out a quick solution. Google if needed to understand some background, but try to arrive at the solution by some means. Once I have the answer, I go thru solution thread which generally has some good insights into the problem.</p>
<p>I was almost scared when I spent 2 evenings to solve the just the first two problems. But that was mostly getting to know the language than getting to the solution itself. Now that I know F# a little better, I’m going much faster. Today I solved 4 of them ( <img class="wp-smiley" src="../wp-includes/images/smilies/icon_smile.gif" alt=":)" /> ) and I definitely feel good about it (and that’s why this post <img class="wp-smiley" src="../wp-includes/images/smilies/icon_biggrin.gif" alt=":D" /> )</p>
<p>One interesting thing is that there arent a lot of members in Project Euler who’re using F#. The count (as of today) is just around 160. And from India, I am the only member using F# <img class="wp-smiley" src="../wp-includes/images/smilies/icon_biggrin.gif" alt=":D" /></p>
<p>Btw, my handle on <a href="http://projecteuler.net/" target="_blank">Project Euler</a> is <a href="http://projecteuler.net/index.php?section=profile&amp;profile=CodeMangler" target="_blank">CodeMangler</a> (my standard online handle, except in games)</p>
<p>Some of the later problems sound pretty interesting. Can’t wait to get to them. Nope, they arent locked or anything. I’m just forcing myself to solve them in order <img src='http://dharampal.name/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />   Anyways, I just hope to solve the remaining 220ish problems asap and get to the top of the list soon <img class="wp-smiley" src="../wp-includes/images/smilies/icon_smile.gif" alt=":)" /> (overambitious.. I know)</p>
]]></content:encoded>
			<wfw:commentRss>http://dharampal.name/2008/12/23/project-euler/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>It&#8217;s my Birthday!</title>
		<link>http://dharampal.name/2008/12/23/its-my-birthday/</link>
		<comments>http://dharampal.name/2008/12/23/its-my-birthday/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 04:00:50 +0000</pubDate>
		<dc:creator>CodeMangler</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[birthday]]></category>

		<guid isPermaLink="false">http://blog.dharampal.name/?p=5</guid>
		<description><![CDATA[Today&#8217;s my birthday, and I turn 24. But I suspect it&#8217;s going to be my most boring birthday ever.. Since two days, I&#8217;m down with cold and cough, and intermittently feeling feverish.. Not a good way to start the day at all.. On top of that, most likely I&#8217;d be working at the office today.. [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s my birthday, and I turn 24. But I suspect it&#8217;s going to be my most boring birthday ever.. <img src='http://dharampal.name/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Since two days, I&#8217;m down with cold and cough, and intermittently feeling feverish.. Not a good way to start the day at all.. On top of that, most likely I&#8217;d be working at the office today.. Now that&#8217;s definitely a downer, don&#8217;t u think?</p>
<p>On the bright side, I was planning to start this blog on my birthday.. So, at least that happened <img src='http://dharampal.name/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Haven&#8217;t thought of any resolutions yet.. It&#8217;s not like I&#8217;m big on holding onto my birthday/new year resolutions, but still, it&#8217;s nice to have some <img src='http://dharampal.name/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />   And that reminds me.. Have you ever met anyone who has kept up his/her birthday/new year resolutions? Strangely, I can&#8217;t remember anyone <img src='http://dharampal.name/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://dharampal.name/2008/12/23/its-my-birthday/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
