<?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: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/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Coding Day</title>
	
	<link>http://www.codingday.com</link>
	<description>Adventures in Computing, Can Erten's blog</description>
	<lastBuildDate>Tue, 13 Jul 2010 12:52:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/CanErten" /><feedburner:info uri="canerten" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by-sa/2.0/</creativeCommons:license><image><link>http://www.canerten.com</link><url>http://www.canerten.com/gravatar.jpg</url><title>Can Erten</title></image><feedburner:emailServiceId>CanErten</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Random number Generation with  RNG</title>
		<link>http://feedproxy.google.com/~r/CanErten/~3/AIy-JXTZeiA/</link>
		<comments>http://www.codingday.com/random-number-generation-with-rng/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 10:38:56 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[F#]]></category>

		<guid isPermaLink="false">http://www.codingday.com/?p=474</guid>
		<description>I would like to mention a question that posed on stackoverflow a year back, with a slight change. Given a function which produces a random integer in the range 0 to 4, write a function which produces a random integer in the range 0 to 6. Simply, we have let ran5() = new Random().Next(5), we [...]</description>
				<content:encoded><![CDATA[<p>I would like to mention a question that <a target="_blank" href="http://stackoverflow.com/questions/137783/given-a-function-which-produces-a-random-integer-in-the-range-1-to-5-write-a-fun">posed on stackoverflow</a> a year back, with a slight change. </p>
<blockquote><p>Given a function which produces a random integer in the range 0 to 4, write a function which produces a random integer in the range 0 to 6.
</p></blockquote>
<p>Simply, we have let ran5() = new Random().Next(5), we would like to write ran7 using ran5, and without any other random number generator<br />
The answers are rather interesting for this question,  as it is important to have a uniformly distributed random number generator.<br />
The first attempt, is a naive way to generate the random number by defining the sample set small.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #5d478b; font-style: italic;">//random number generator with 6 numbers</span>
<span style="color: #06c; font-weight: bold;">let</span> ran <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">new</span> Random<span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span>
<span style="color: #06c; font-weight: bold;">let</span> random5<span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span> ran.<span style="color: #060;">Next</span><span style="color: #6c6;">&#40;</span><span style="color: #c6c;">5</span><span style="color: #6c6;">&#41;</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">//naive</span>
<span style="color: #06c; font-weight: bold;">let</span> rantbl <span style="color: #a52a2a;">=</span> <span style="color: #6c6;">&#91;</span>| <span style="color: #c6c;">0</span> .. <span style="color: #c6c;">6</span> |<span style="color: #6c6;">&#93;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">rec</span> random7<span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">let</span> i,j <span style="color: #a52a2a;">=</span> random5<span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span>, random5<span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span>                   
                    <span style="color: #06c; font-weight: bold;">let</span> sum <span style="color: #a52a2a;">=</span> i <span style="color: #a52a2a;">+</span> j
                    <span style="color: #06c; font-weight: bold;">if</span>  sum <span style="color: #a52a2a;">&lt;</span> rantbl.<span style="color: #060;">Length</span> <span style="color: #06c; font-weight: bold;">then</span> rantbl.<span style="color: #6c6;">&#91;</span>sum<span style="color: #6c6;">&#93;</span>
                    <span style="color: #06c; font-weight: bold;">else</span> random7<span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span></pre></td></tr></table></div>

<p>
Now, if you run the sample, it will generate the random numbers to 7 just fine, but it won&#8217;t be uniformly distributed, and will converge to a number as we run infinite times.<br />
However, if we define our initial set uniformly to match out number generator, in this case we can generate 5 numbers, so a set of 25, we can hit each element by the multiplication of those two  generators
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #5d478b; font-style: italic;">//based on</span>
<span style="color: #06c; font-weight: bold;">let</span> randomTable <span style="color: #a52a2a;">=</span> <span style="color: #6c6;">&#91;</span>|for i <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #c6c;">0</span> .. <span style="color: #c6c;">24</span> <span style="color: #06c; font-weight: bold;">do</span> <span style="color: #06c; font-weight: bold;">if</span> i <span style="color: #a52a2a;">/</span> <span style="color: #c6c;">7</span><span style="color: #a52a2a;">&lt;</span><span style="color: #c6c;">3</span> <span style="color: #06c; font-weight: bold;">then</span> <span style="color: #06c; font-weight: bold;">yield</span> i <span style="color: #a52a2a;">%</span> <span style="color: #c6c;">7</span>
                                        <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">yield</span> <span style="color: #a52a2a;">-</span><span style="color: #c6c;">1</span> |<span style="color: #6c6;">&#93;</span> 
<span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">rec</span> random7_2<span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">let</span> i,j <span style="color: #a52a2a;">=</span> random5<span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span>, random5<span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span>
                      <span style="color: #06c; font-weight: bold;">let</span> index <span style="color: #a52a2a;">=</span> i  <span style="color: #a52a2a;">*</span> <span style="color: #c6c;">5</span> <span style="color: #a52a2a;">+</span> j
                      <span style="color: #06c; font-weight: bold;">if</span>  randomTable.<span style="color: #6c6;">&#91;</span>index<span style="color: #6c6;">&#93;</span> <span style="color: #a52a2a;">&lt;&gt;</span> <span style="color: #a52a2a;">-</span><span style="color: #c6c;">1</span> <span style="color: #06c; font-weight: bold;">then</span> randomTable.<span style="color: #6c6;">&#91;</span>index<span style="color: #6c6;">&#93;</span>
                      <span style="color: #06c; font-weight: bold;">else</span> random7_2<span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> sampler sample <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">seq</span> <span style="color: #6c6;">&#123;</span> <span style="color: #06c; font-weight: bold;">for</span> i <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #c6c;">0</span> .. <span style="color: #c6c;">100000</span> <span style="color: #06c; font-weight: bold;">do</span> <span style="color: #06c; font-weight: bold;">yield</span> sample<span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#125;</span></pre></td></tr></table></div>

<div class="dos">val ran : Random<br />
val random5 : unit -> int<br />
val rantbl : int array<br />
val it : int array = [|0; 1; 2; 3; 4; 5; 6|]<br />
val randomTable : int array<br />
val it : int array = [|0; 1; 2; 3; 4; 5; 6; 0; 1; 2; 3; 4; 5; 6; 0; 1; 2; 3; 4; 5; 6; -1; -1; -1;<br />
-1|]<br />
val random7 : unit -> int<br />
val random7_2 : unit -> int<br />
val sampler : (unit -> &#8216;a) -> seq<'a></div>
<p>
We can estimate of the value of a random variable and predict the error, which is proportional to the iterations.  Since we have 2 sets, we can analyse and compare their statistical properties.
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> variance sample N <span style="color: #a52a2a;">=</span>  <span style="color: #06c; font-weight: bold;">let</span> mean <span style="color: #a52a2a;">=</span> sample <span style="color: #a52a2a;">|&gt;</span> <span style="color: #06c; font-weight: bold;">Seq</span>.<span style="color: #060;">average_by</span> <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">fun</span> i<span style="color: #a52a2a;">-&gt;</span> <span style="color: #06c; font-weight: bold;">float</span> i<span style="color: #6c6;">&#41;</span>
                         <span style="color: #6c6;">&#40;</span>sample <span style="color: #a52a2a;">|&gt;</span> <span style="color: #06c; font-weight: bold;">Seq</span>.<span style="color: #060;">sum_by</span> <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">fun</span> i<span style="color: #a52a2a;">-&gt;</span><span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">float</span> i <span style="color: #a52a2a;">-</span> mean<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">*</span> <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">float</span> i <span style="color: #a52a2a;">-</span> mean<span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span>
                                                     <span style="color: #a52a2a;">/</span> N
<span style="color: #06c; font-weight: bold;">let</span> standardDeviation varian<span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">sqrt</span> <span style="color: #6c6;">&#40;</span>varian<span style="color: #6c6;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> standardError sample <span style="color: #a52a2a;">=</span>  <span style="color: #06c; font-weight: bold;">let</span> N <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">float</span> <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">Seq</span>.<span style="color: #060;">length</span> sample<span style="color: #6c6;">&#41;</span>
                            <span style="color: #06c; font-weight: bold;">let</span> vari <span style="color: #a52a2a;">=</span> variance sample N
                            <span style="color: #06c; font-weight: bold;">let</span> stDev <span style="color: #a52a2a;">=</span> standardDeviation vari
                            stDev <span style="color: #a52a2a;">/</span> <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">sqrt</span> N<span style="color: #6c6;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> sample <span style="color: #a52a2a;">=</span> sampler random7
standardError<span style="color: #6c6;">&#40;</span>sampler random7 <span style="color: #6c6;">&#41;</span>
standardError <span style="color: #6c6;">&#40;</span>sampler random7_2<span style="color: #6c6;">&#41;</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">// uniform distribution</span>
<span style="color: #06c; font-weight: bold;">let</span> errorSet mySet <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">let</span> N <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">Seq</span>.<span style="color: #060;">length</span> mySet <span style="color: #a52a2a;">|&gt;</span> <span style="color: #06c; font-weight: bold;">float</span>
                     mySet <span style="color: #a52a2a;">|&gt;</span> <span style="color: #06c; font-weight: bold;">Seq</span>.<span style="color: #060;">count_by</span> <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">fun</span> e<span style="color: #a52a2a;">-&gt;</span> e<span style="color: #6c6;">&#41;</span>  <span style="color: #a52a2a;">|&gt;</span> <span style="color: #06c; font-weight: bold;">Seq</span>.<span style="color: #060;">map</span> <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">fun</span> <span style="color: #6c6;">&#40;</span>i,j<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">-&gt;</span> i, <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">float</span> j<span style="color: #6c6;">&#41;</span><span style="color: #a52a2a;">/</span>N <span style="color: #a52a2a;">*</span> <span style="color: #c6c;">100.0</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">|&gt;</span> <span style="color: #06c; font-weight: bold;">Map</span>.<span style="color: #060;">of_seq</span>
&nbsp;
errorSet <span style="color: #6c6;">&#40;</span>sampler random7<span style="color: #6c6;">&#41;</span>
errorSet <span style="color: #6c6;">&#40;</span>sampler random7_2<span style="color: #6c6;">&#41;</span></pre></td></tr></table></div>

<div class="dos">val variance : seq -> float -> float<br />
val standardDeviation : float -> float<br />
val standardError : seq -> float<br />
val sample : seq<br />
val errorSet : seq<'a> -> Map<'a,float></div>
<p><div class='download-link'>
							<a href='http://www.codingday.com/download.php?file=http://www.codingday.com/downloads/random.fs'><img alt='Download' class='leftalign' src='http://www.codingday.com/wp-content/plugins/dBeautifier/icons/downloads.png' /></a>
							<h4>
								<a href='http://www.codingday.com/download.php?file=http://www.codingday.com/downloads/random.fs'>Random Number Generation</a>
							</h4><p>Downloads: 459  File Name: random.fs</p>
						</div>. </p>
<img src="http://feeds.feedburner.com/~r/CanErten/~4/AIy-JXTZeiA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/random-number-generation-with-rng/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.codingday.com/random-number-generation-with-rng/</feedburner:origLink></item>
		<item>
		<title>Happy Pi Day and Monte Carlo Method</title>
		<link>http://feedproxy.google.com/~r/CanErten/~3/h49h-NsFKvg/</link>
		<comments>http://www.codingday.com/happy-pi-day-and-monte-carlo-method/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 22:11:17 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[monte carlo]]></category>
		<category><![CDATA[pi]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://www.codingday.com/?p=450</guid>
		<description>Pi Calculation Today is the day, 03/14 2010. Happy day to all! The Monte Carlo method generates multiple trials to determine the expected value of a random variable. Calculating Pi is generally the hello world of Monte Carlo Method in Stochastic Calculus. So for today, I will try to give a sample calculation of pi [...]</description>
				<content:encoded><![CDATA[<h3>Pi Calculation</h3>
<p>Today is the <img src="http://www.codingday.com/wp-content/plugins/easy-latex/cache/tex_0639f72af5c20093aca42231bd1e23de.png" title="\pi" style="vertical-align:-20%;" class="tex" alt="\pi" /> day, 03/14 2010. Happy <img src="http://www.codingday.com/wp-content/plugins/easy-latex/cache/tex_0639f72af5c20093aca42231bd1e23de.png" title="\pi" style="vertical-align:-20%;" class="tex" alt="\pi" />day to all!</p>
<blockquote><p>The Monte Carlo method generates multiple trials to determine the expected value of a  random variable.</p></blockquote>
<p>Calculating Pi is generally the hello world of Monte Carlo Method in Stochastic Calculus. So for today, I will try to give a sample calculation of pi as monte carlo in F#. There are very good articles on the <a href="http://en.wikipedia.org/wiki/Monte_Carlo_method" target="_blank">Monte carlo</a> and  how the <a href="http://www.chem.unl.edu/zeng/joy/mclab/mcintro.html" target="_blank">pi calculation</a> is formulated.</p>
<p>Generally these are the steps to follow, before running the simulation</p>
<ol>
<li>Define the input set</li>
<li>Generate randomly the input set</li>
<li>Filter the random set using some computations</li>
<li>Fold the result to the final result</li>
</ol>
<p>Pi calculation formula :<br />
<img src="http://www.codingday.com/wp-content/plugins/easy-latex/cache/tex_ee6406d66996d6b9daff084d4281c6d8.png" title="\frac{Hitting inside the circle} {Hitting Outside the circle} = \frac { 1/4  \pi r^2} { r^2} = \frac {1}{4}\pi" style="vertical-align:-20%;" class="tex" alt="\frac{Hitting inside the circle} {Hitting Outside the circle} = \frac { 1/4  \pi r^2} { r^2} = \frac {1}{4}\pi" /></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">open</span> System
<span style="color: #06c; font-weight: bold;">let</span> calcPi<span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
    <span style="color: #06c; font-weight: bold;">let</span> ran <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">new</span> Random<span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">let</span> distances <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">seq</span> <span style="color: #6c6;">&#123;</span> <span style="color: #06c; font-weight: bold;">for</span> i <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #c6c;">0</span> .. <span style="color: #c6c;">100000</span> <span style="color: #06c; font-weight: bold;">do</span>
                            <span style="color: #06c; font-weight: bold;">let</span> x,y  <span style="color: #a52a2a;">=</span> ran.<span style="color: #060;">NextDouble</span><span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span>, ran.<span style="color: #060;">NextDouble</span><span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span>
                            <span style="color: #06c; font-weight: bold;">yield</span> <span style="color: #06c; font-weight: bold;">sqrt</span> <span style="color: #6c6;">&#40;</span>x <span style="color: #a52a2a;">*</span> x <span style="color: #a52a2a;">+</span> y <span style="color: #a52a2a;">*</span> y<span style="color: #6c6;">&#41;</span>
         <span style="color: #6c6;">&#125;</span>
&nbsp;
    <span style="color: #06c; font-weight: bold;">let</span> count <span style="color: #a52a2a;">=</span> distances <span style="color: #a52a2a;">|&gt;</span> <span style="color: #06c; font-weight: bold;">Seq</span>.<span style="color: #060;">filter</span> <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">fun</span> distance <span style="color: #a52a2a;">-&gt;</span> distance <span style="color: #a52a2a;">&lt;=</span> <span style="color: #c6c;">1.0</span><span style="color: #6c6;">&#41;</span> 
                              <span style="color: #a52a2a;">|&gt;</span> <span style="color: #06c; font-weight: bold;">Seq</span>.<span style="color: #060;">length</span>     
  <span style="color: #c6c;">4.0</span> <span style="color: #a52a2a;">*</span> <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">float</span> count<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">/</span> <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">float</span> <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">Seq</span>.<span style="color: #060;">length</span> distances<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> errorRate<span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span> <span style="color: #6c6;">&#40;</span><span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">-</span> <span style="color: #6c6;">&#40;</span>calcPi<span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">/</span> Math.<span style="color: #060;">PI</span><span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">*</span> <span style="color: #c6c;">100.0</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> print5 value <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">for</span> i <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #c6c;">0</span> .. <span style="color: #c6c;">5</span> <span style="color: #06c; font-weight: bold;">do</span> printf <span style="color: #3cb371;">&quot;%f<span style="">\n</span>&quot;</span> <span style="color: #6c6;">&#40;</span>value<span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span>
print5 <span style="color: #6c6;">&#40;</span>errorRate<span style="color: #6c6;">&#41;</span></pre></td></tr></table></div>

<div class="dos">val calcPi : unit -> float<br />
val errorRate : unit -> float<br />
val print5 : (unit -> float) -> unit<br />
Error rates:<br />
-0.024698<br />
-0.093453<br />
-0.013239<br />
-0.094726<br />
-0.373563<br />
0.308887<br />
></p>
</div>
<p><div class='download-link'>
							<a href='http://www.codingday.com/download.php?file=http://www.codingday.com/downloads/pi.fs'><img alt='Download' class='leftalign' src='http://www.codingday.com/wp-content/plugins/dBeautifier/icons/downloads.png' /></a>
							<h4>
								<a href='http://www.codingday.com/download.php?file=http://www.codingday.com/downloads/pi.fs'>Pi Calculation</a>
							</h4><p>Downloads: 505  File Name: pi.fs</p>
						</div>. </p>
<img src="http://feeds.feedburner.com/~r/CanErten/~4/h49h-NsFKvg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/happy-pi-day-and-monte-carlo-method/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.codingday.com/happy-pi-day-and-monte-carlo-method/</feedburner:origLink></item>
		<item>
		<title>Book Review – Real World Functional Programming</title>
		<link>http://feedproxy.google.com/~r/CanErten/~3/mQ_chNvdEbA/</link>
		<comments>http://www.codingday.com/book-review-real-world-functional-programming/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 00:21:41 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[Book]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://www.codingday.com/?p=421</guid>
		<description>Real-World functional programming has been written by Tomas Petricek and Jon Skeet. Tomasz’s and Jon&amp;#8217;s book is built around how to think functionally when programming and how to make best use of functional paradigm for real world scenerios. The book is written  mainly for the C# programmers who would like to switch/learn more of the [...]</description>
				<content:encoded><![CDATA[<p><a href="http://www.functional-programming.net/" target="_blank"><img class="alignleft size-medium wp-image-423" title="Real World Functional Programming" src="http://www.codingday.com/wp-content/uploads/2010/01/51JSoWuTsqL._SS500_-300x300.jpg" alt="Real World Functional Programming" width="300" height="300" /></a></p>
<p>Real-World functional programming has been written by <a href="http://tomasp.net/" target="_blank">Tomas Petricek</a> and <a href="http://msmvps.com/blogs/jon_skeet/" target="_blank">Jon Skeet</a>.<br />
Tomasz’s and Jon&#8217;s book is built around how to think functionally when programming and how to make best use of functional paradigm for real world scenerios. The book is written  mainly for the C# programmers who would like to switch/learn more of the functional world. It also features snippets with some technical background of the ideas involved.<br />
As the title suggests the book is not focussed on one language, instead a mix of C# and F#, and it does a great job in bringing these worlds together,which is to me best of both worlds. Although, samples are all in functional style, when the problem needs the functional beauty to express, F# takes place. This gives any .NET developer to see when to use the necessary language for a particular problem.</p>
<p>The book starts slowly with the functional structures, and goes to monads, and to reactive libraries.  I found the language of the book clear to understand, and easy to follow. The samples in the beginning of a chapter starts with some really simple constructs, but at the end of a chapter they become more complicated, and a nice programs to reflect the idea of the chapter.</p>
<p>Applied functional programming is probably the most sophisticated part of the book. Some ideas mainly inspired from research papers (cited at the end) blended with modern languages and libraries and applied somewhat differently. Especially composable functional libraries and reactive functional programs were insightful and open the mind with new possibilities.</p>
<p>Finally, I would recommend this book whoever wants to switch to functional programming and also learn new techniques in general. Each sample is crafted well, and represent real value with its tutorial writing style.</p>
<img src="http://feeds.feedburner.com/~r/CanErten/~4/mQ_chNvdEbA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/book-review-real-world-functional-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.codingday.com/book-review-real-world-functional-programming/</feedburner:origLink></item>
		<item>
		<title>Pex, Unit Test but Better, Parameterized Unit Testing</title>
		<link>http://feedproxy.google.com/~r/CanErten/~3/npOwVi7W-ek/</link>
		<comments>http://www.codingday.com/pex-unit-test-but-better-parameterized-unit-testing/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 23:39:24 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[parameterized]]></category>
		<category><![CDATA[pex]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[unit test]]></category>

		<guid isPermaLink="false">http://www.codingday.com/?p=431</guid>
		<description>Finally I had a chance to play with the Pex (Program EXploration) , I heard it on lang.net for the very first time and I was quite impressed, but it took a while to explore it. I downloaded the latest commercial evaluation package 0.22.50128.1 from Pex web site. It is about 12 MB, it comes [...]</description>
				<content:encoded><![CDATA[<p><img class="alignleft size-thumbnail wp-image-436" title="Pex" src="http://www.codingday.com/wp-content/uploads/2010/02/pexweb-150x121.png" alt="" width="150" height="121" /></p>
<p>Finally I had a chance to play with the Pex (Program EXploration) , I heard it on <a href="http://langnetsymposium.com/2008/talks/2-08%20-%20Pex%20-%20Peli%20de%20Halleux.html" target="_blank">lang.net</a> for the very first time and I was quite impressed, but it took a while to explore it.</p>
<p>I downloaded the latest commercial evaluation package 0.22.50128.1 from <a href="http://research.microsoft.com/en-us/projects/Pex/" target="_blank">Pex web site</a>.</p>
<p>It is about 12 MB, it comes with different installation options with the support of VS 2008 and 2010. It installed without any problems on my VS2010 beta 2.</p>
<p>Here is what you get from the installation :</p>
<ul>
<li>Pex command line (Visual Studio not required)</li>
<li>Pex Visual Studio Add-in, for Visual Studio 2008 and Visual Studio 2010 Beta2</li>
<li>Moles (which includes Stubs), lightweight test stubs and detours for .NET</li>
<li>API reference, tutorials and documentation</li>
<li>Samples</li>
</ul>
<p>The documentation is really detailed, and the samples are worth investigating. I quite liked the <a href="http://research.microsoft.com/en-us/projects/pex/pextutorial.pdf">Pex Tutorial</a> document, which explains in detail what Pex is all about.</p>
<p>The good thing is it supports many different testing frameworks, including .NET&#8217;s own, nunit, xunit etc. By the way, I have to say VS2010 is awesome!</p>
<p>Pex is pretty much like a unit test but better in many ways. I&#8217;m quite surprised by the dynamic coverage window of a test method that you execute. This way, it is clear to see if the code is fully covered by the Pex test.</p>
<p>Pex is more like test method that takes inputs. In general, unit tests are not taking any inputs, they are isolated from each other and from external access, other than calling them parameterless.</p>
<p>Input generation in Pex based on the static analysis of the methods. It generates inputs such that, the code will be covered in full, however for some special types, the inputs might need to be explicitely told to test framework.  The tools it brings to Visual Studio is extremely simple and easy to use. It does a very good job on incorporating those results.</p>
<p>Here is a very simple function that I generated my first Pex tests from</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;"> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> Compare<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i, <span style="color: #6666cc; font-weight: bold;">string</span> s<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>i <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">500</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                i <span style="color: #008000;">*=</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">else</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> Compare2<span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> i <span style="color: #008000;">*</span> i<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p><a href="http://www.codingday.com/wp-content/uploads/2010/02/Screen-shot-2010-02-07-at-23.22.53.png"><img title="Run Pex Window" src="http://www.codingday.com/wp-content/uploads/2010/02/Screen-shot-2010-02-07-at-23.22.53.png" alt="" width="581" height="176" /></a></p>
<p>When you run Pex, it generates potential inputs to cover all the code. According to the documentation, it uses static analysis to figure the potential values. So it is not a random number generated test, or a brute force test, which is quite interesting. Pex can cover some obscure side of the code, which fully supports many Unicode string inputs or regular expressions.</p>
<p>However, when I converted this very simple code, from System.Int32 to System.Numeric.<em>BigInteger</em> (a new type in .NET 4), the test only generated for a null value. Unless I&#8217;m missing something, it doesn&#8217;t support all the types as yet, but it looks like a promising and valuable product to be added to your toolset</p>
<img src="http://feeds.feedburner.com/~r/CanErten/~4/npOwVi7W-ek" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/pex-unit-test-but-better-parameterized-unit-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.codingday.com/pex-unit-test-but-better-parameterized-unit-testing/</feedburner:origLink></item>
		<item>
		<title>TouchJSON conflicts with AdMob and Cocos2d</title>
		<link>http://feedproxy.google.com/~r/CanErten/~3/O-pZvyXMKl4/</link>
		<comments>http://www.codingday.com/touchjson-conflicts-with-admob-and-cocos2d/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 23:49:16 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[admob]]></category>
		<category><![CDATA[cocos2d]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[touchjson]]></category>

		<guid isPermaLink="false">http://www.codingday.com/?p=405</guid>
		<description>If you happen to use Admob and cocos2d in the same project, the compilation will fail with some linking errors. Although it is not mentioned on Admod SDK documentation, apparently Admob borrows TouchJSON from touch code, so does Cocos2d. ld: duplicate symbol .objc_category_name_NSCharacterSet_NSCharacterSet_Extensions in /AdMob/libAdMobSimulator.a(NSCharacterSet_Extensions.o) and Debug-iphonesimulator/ptap.build/Objects-normal/i386/NSCharacterSet_Extensions.o The duplicated links could be resolved by removing [...]</description>
				<content:encoded><![CDATA[<p>If you happen to use <a href="http://www.admob.com">Admob</a> and <a href="http://www.cocos2d-iphone.org/">cocos2d</a> in the same project, the compilation will fail with some linking errors. Although it is not mentioned on Admod SDK documentation, apparently Admob borrows TouchJSON from <a href="http://code.google.com/p/touchcode/wiki/TouchJSON">touch code</a>, so does Cocos2d.</p>
<div class="dos">
ld: duplicate symbol .objc_category_name_NSCharacterSet_NSCharacterSet_Extensions in /AdMob/libAdMobSimulator.a(NSCharacterSet_Extensions.o) and Debug-iphonesimulator/ptap.build/Objects-normal/i386/NSCharacterSet_Extensions.o
</div>
<p>
The duplicated links could be resolved by removing it from one of the sources. Since we don’t have Admob source code, the workaround is actually to remove the TouchJSON directories from your project which are located in the cocos2d source code.
</p>
<p>
Directory and Files to be Removed as they are statically linked through admob<br />
+TouchJSON<br />
-CDataScanner.h<br />
-CDataScanner.m<br />
+Extensions<br />
-CDataScanner_Extensions.h<br />
-CDataScanner_Extensions.m<br />
-NSCharacterSet_Extensions.h<br />
-NSCharacterSet_Extensions.m<br />
-NSDictionary_JSONExtensions.h<br />
-NSDictionary_JSONExtensions.m<br />
-NSScanner_Extensions.h<br />
-NSScanner_Extensions.m<br />
+JSON<br />
-CJSONDeserializer.h<br />
-CJSONDeserializer.m<br />
-CJSONScanner.h<br />
-CJSONScanner.m<br />
-CJSONSerializer.h<br />
-CJSONSerializer.m</p>
<img src="http://feeds.feedburner.com/~r/CanErten/~4/O-pZvyXMKl4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/touchjson-conflicts-with-admob-and-cocos2d/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.codingday.com/touchjson-conflicts-with-admob-and-cocos2d/</feedburner:origLink></item>
		<item>
		<title>Poker : Programming Problem</title>
		<link>http://feedproxy.google.com/~r/CanErten/~3/Gn3r6L7UTlw/</link>
		<comments>http://www.codingday.com/poker-programming-problem/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 01:19:36 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[54]]></category>
		<category><![CDATA[euler]]></category>
		<category><![CDATA[fsharp]]></category>
		<category><![CDATA[poker]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[projecteuler]]></category>

		<guid isPermaLink="false">http://www.canerten.com/?p=333</guid>
		<description>Although it has been a while since Brian posted the poker problem in his blog, I haven&amp;#8217;t got the chance to look at it until I came across in ProjectEuler Problem 54. It is not the elegant or best solution at all, but just wanted to join the crew and can confirm it works with [...]</description>
				<content:encoded><![CDATA[<p>Although it has been a while since Brian posted the <a title="A programming problem," href="http://lorgonblog.spaces.live.com/Blog/cns!701679AD17B6D310!546.entry" target="_blank">poker problem</a> in his blog, I haven&#8217;t got the chance to look at it until I came across in ProjectEuler <a href="http://projecteuler.net/index.php?section=problems&amp;id=54" target="_blank">Problem 54</a>. It is not the elegant or best solution at all, but just wanted to join the crew and can confirm it works with the problem&#8217;s 1000 games&#8217; dataset.</p>
<p>Hope this helps.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #5d478b; font-style: italic;">#light</span>
<span style="color: #5d478b; font-style: italic;">(* Problem 54 *)</span>
<span style="color: #06c; font-weight: bold;">type</span> suit <span style="color: #a52a2a;">=</span> |Spades |Hearts |Clubs |Diamonds 
<span style="color: #06c; font-weight: bold;">type</span> card<span style="color: #a52a2a;">=</span>  |Ace <span style="color: #a52a2a;">=</span> <span style="color: #c6c;">14</span> |Two <span style="color: #a52a2a;">=</span> <span style="color: #c6c;">2</span>  |Three <span style="color: #a52a2a;">=</span><span style="color: #c6c;">3</span>  |Four <span style="color: #a52a2a;">=</span> <span style="color: #c6c;">4</span> |Five <span style="color: #a52a2a;">=</span> <span style="color: #c6c;">5</span> |Six <span style="color: #a52a2a;">=</span> <span style="color: #c6c;">6</span> 
            |Seven <span style="color: #a52a2a;">=</span><span style="color: #c6c;">7</span>  |Eight <span style="color: #a52a2a;">=</span> <span style="color: #c6c;">8</span> |Nine <span style="color: #a52a2a;">=</span> <span style="color: #c6c;">9</span> |Ten <span style="color: #a52a2a;">=</span> <span style="color: #c6c;">10</span> |Jack <span style="color: #a52a2a;">=</span> <span style="color: #c6c;">11</span> |Queen <span style="color: #a52a2a;">=</span><span style="color: #c6c;">12</span> |King  <span style="color: #a52a2a;">=</span><span style="color: #c6c;">13</span>
<span style="color: #06c; font-weight: bold;">type</span> acard <span style="color: #a52a2a;">=</span> <span style="color: #6c6;">&#40;</span>card <span style="color: #a52a2a;">*</span> suit<span style="color: #6c6;">&#41;</span>  
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> carder x:card<span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">enum</span> x
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> card_value <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">function</span>
    | <span style="color: #3cb371;">'A'</span> <span style="color: #a52a2a;">-&gt;</span> card.<span style="color: #060;">Ace</span>
    | <span style="color: #3cb371;">'K'</span> <span style="color: #a52a2a;">-&gt;</span> card.<span style="color: #060;">King</span>
    | <span style="color: #3cb371;">'Q'</span> <span style="color: #a52a2a;">-&gt;</span> card.<span style="color: #060;">Queen</span>
    | <span style="color: #3cb371;">'J'</span> <span style="color: #a52a2a;">-&gt;</span> card.<span style="color: #060;">Jack</span>  
    | <span style="color: #3cb371;">'T'</span> <span style="color: #a52a2a;">-&gt;</span> card.<span style="color: #060;">Ten</span>
    | c <span style="color: #a52a2a;">-&gt;</span>  carder<span style="color: #6c6;">&#40;</span>System.<span style="color: #060;">Int32</span>.<span style="color: #060;">Parse</span><span style="color: #6c6;">&#40;</span>c.<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: #6c6;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> suit_value <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">function</span>
    | <span style="color: #3cb371;">'S'</span> <span style="color: #a52a2a;">-&gt;</span> Spades
    | <span style="color: #3cb371;">'H'</span> <span style="color: #a52a2a;">-&gt;</span> Hearts    
    | <span style="color: #3cb371;">'C'</span> <span style="color: #a52a2a;">-&gt;</span> Clubs
    | <span style="color: #3cb371;">'D'</span> <span style="color: #a52a2a;">-&gt;</span> Diamonds    
    | a <span style="color: #a52a2a;">-&gt;</span> invalid_arg <span style="color: #6c6;">&#40;</span>a.<span style="color: #060;">ToString</span><span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> Create <span style="color: #6c6;">&#40;</span>str: <span style="color: #06c; font-weight: bold;">string</span><span style="color: #6c6;">&#41;</span> :acard <span style="color: #a52a2a;">=</span> <span style="color: #6c6;">&#40;</span>card_value str.<span style="color: #6c6;">&#91;</span><span style="color: #c6c;">0</span><span style="color: #6c6;">&#93;</span>,suit_value str.<span style="color: #6c6;">&#91;</span><span style="color: #c6c;">1</span><span style="color: #6c6;">&#93;</span><span style="color: #6c6;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> isstraigh <span style="color: #6c6;">&#40;</span>mycards:acard list<span style="color: #6c6;">&#41;</span>  <span style="color: #a52a2a;">=</span> 
    <span style="color: #06c; font-weight: bold;">let</span> mycards <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">List</span>.<span style="color: #060;">sort_by</span> <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">fun</span> <span style="color: #6c6;">&#40;</span>a,b<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">-&gt;</span> a,b<span style="color: #6c6;">&#41;</span> mycards
    <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">rec</span> isstr previouscard mycards   <span style="color: #6c6;">&#40;</span>straightlist : acard list<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
        <span style="color: #06c; font-weight: bold;">if</span> straightlist.<span style="color: #060;">Length</span> <span style="color: #a52a2a;">&gt;=</span> <span style="color: #c6c;">5</span> <span style="color: #06c; font-weight: bold;">then</span> straightlist
        <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">match</span> mycards <span style="color: #06c; font-weight: bold;">with</span>  
                | cur :: rest <span style="color: #a52a2a;">-&gt;</span> <span style="color: #06c; font-weight: bold;">if</span> <span style="color: #06c; font-weight: bold;">int</span> <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">fst</span> cur<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">int</span> <span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">fst</span> previouscard<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">+</span> <span style="color: #c6c;">1</span> <span style="color: #06c; font-weight: bold;">then</span> isstr cur rest  <span style="color: #6c6;">&#40;</span>cur::straightlist<span style="color: #6c6;">&#41;</span>
                                 <span style="color: #06c; font-weight: bold;">else</span> isstr cur rest  <span style="color: #6c6;">&#91;</span><span style="color: #6c6;">&#93;</span>                           
                | _ <span style="color: #a52a2a;">-&gt;</span> <span style="color: #6c6;">&#91;</span><span style="color: #6c6;">&#93;</span>
    <span style="color: #06c; font-weight: bold;">let</span> head <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">List</span>.<span style="color: #060;">hd</span> mycards
    isstr head <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">List</span>.<span style="color: #060;">tl</span> mycards<span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#91;</span>head<span style="color: #6c6;">&#93;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> pairl <span style="color: #6c6;">&#40;</span>mycards : acard list<span style="color: #6c6;">&#41;</span> groupfunction minelementCount <span style="color: #a52a2a;">=</span>
                 mycards <span style="color: #a52a2a;">|&gt;</span> <span style="color: #06c; font-weight: bold;">Seq</span>.<span style="color: #060;">group_by</span> groupfunction
                         <span style="color: #a52a2a;">|&gt;</span> <span style="color: #06c; font-weight: bold;">Seq</span>.<span style="color: #060;">filter</span> <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">fun</span> a <span style="color: #a52a2a;">-&gt;</span> <span style="color: #06c; font-weight: bold;">Seq</span>.<span style="color: #060;">length</span> <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">snd</span> a<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">&gt;=</span> minelementCount<span style="color: #6c6;">&#41;</span>
                         <span style="color: #a52a2a;">|&gt;</span> <span style="color: #06c; font-weight: bold;">Seq</span>.<span style="color: #060;">to_list</span>
                         <span style="color: #a52a2a;">|&gt;</span> <span style="color: #06c; font-weight: bold;">List</span>.<span style="color: #060;">unzip</span>
&nbsp;
&nbsp;
<span style="color: #06c; font-weight: bold;">type</span> Ranks <span style="color: #a52a2a;">=</span>
    | Highest <span style="color: #06c; font-weight: bold;">of</span> card
    | Pair <span style="color: #06c; font-weight: bold;">of</span>  card
    | TwoPair <span style="color: #06c; font-weight: bold;">of</span> card<span style="color: #a52a2a;">*</span>card
    | Three <span style="color: #06c; font-weight: bold;">of</span> card
    | Straight <span style="color: #06c; font-weight: bold;">of</span> card
    | Flush <span style="color: #06c; font-weight: bold;">of</span> card 
    | FullHouse <span style="color: #06c; font-weight: bold;">of</span>  card<span style="color: #a52a2a;">*</span>card
    | Four <span style="color: #06c; font-weight: bold;">of</span>  card
    | StraightFlush <span style="color: #06c; font-weight: bold;">of</span> card
&nbsp;
<span style="color: #06c; font-weight: bold;">type</span> Player <span style="color: #a52a2a;">=</span> |One |Two  |Noone
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> rank <span style="color: #6c6;">&#40;</span>mycards :  acard list<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>     
    <span style="color: #06c; font-weight: bold;">let</span> traverseL  <span style="color: #6c6;">&#40;</span>l :<span style="color: #3cb371;">'a list)  = if not l.IsEmpty then l  |&gt; List.hd |&gt; Seq.to_list
                                   else []                            
    let isflush mycards = snd (pairl mycards snd 5)  |&gt; traverseL
&nbsp;
    let FofF l = traverseL l |&gt; List.hd |&gt; fst
&nbsp;
    let flush = isflush mycards
    let straight = isstraigh mycards
&nbsp;
    let ispair count= pairl mycards fst count                                                             
&nbsp;
    let four,fours = let f,s = ispair 4 
                     f,s|&gt; traverseL
    let three,threes = ispair 3 
    let two,twos = ispair 2
&nbsp;
    let maxcard c = fst (List.max c)
&nbsp;
    if not flush.IsEmpty &amp;&amp; not straight.IsEmpty then StraightFlush(maxcard flush),flush
    elif  not fours.IsEmpty then Four(four.Head),fours
    elif not threes.IsEmpty &amp;&amp; not twos.IsEmpty &amp;&amp; FofF twos &lt;&gt; FofF threes then FullHouse(two.Head, three.Head), List.append (threes |&gt; traverseL) (traverseL twos)
    elif not flush.IsEmpty then Flush(maxcard flush),flush
    elif not straight.IsEmpty then Straight(maxcard straight),straight
    elif not three.IsEmpty then Three( three.Head), threes |&gt; traverseL
    elif List.length two = 2 then TwoPair(two.Head,two.Tail.Head),Seq.append (twos.Head) (twos.Tail.Head) |&gt; Seq.to_list
    elif not (twos |&gt; traverseL).IsEmpty then Pair(two.Head), twos |&gt; traverseL
    else Highest(maxcard mycards), [List.max mycards]
&nbsp;
let play input =
    let convert (line: string) = let l = line.Split([|'</span> <span style="color: #3cb371;">'|])                                  
                                 [|[for j in 0 .. 4 do yield Create( l.[j])]; [for j in 5 .. 9 do yield Create( l.[j])]|]                                                                  
    let playercrds = convert input              
    let rec iswinner pcards=               
                let ranks,rankcards = pcards |&gt; Array.map (rank)  |&gt; Array.unzip
&nbsp;
                let removecards (mainlist) (toberemoved)  =                         
                        mainlist |&gt; Array.map2 (fun rem main-&gt; main |&gt; List.filter (fun c-&gt;
                                List.fold_left(fun ac x-&gt; if x = c then ac &amp;&amp; false else ac &amp;&amp; true) true rem)) toberemoved
&nbsp;
                if ranks.[0]&gt;ranks.[1] then One
                elif ranks.[0]&lt;ranks.[1] then Two
                else iswinner  (removecards  pcards rankcards) 
&nbsp;
    iswinner playercrds
&nbsp;
&nbsp;
play  &quot;5H 5C 6S 7S KD 2C 3S 8S 8D TD&quot; 
play  &quot;5D 8C 9S JS AC 2C 5C 7D 8S QH&quot;
play  &quot;2D 9C AS AH AC 3D 6D 7D TD QD&quot;
play  &quot;4D 6S 9H QH QC 3D 6D 7H QD QS&quot;  // prob pair queens look at the highes
play  &quot;2H 2D 4C 4D 4S 3C 3D 3S 9S 9D&quot; 
&nbsp;
play  &quot;2H 2D 4C 4D 4S 2H 2D 4C 4D 4S&quot; 
&nbsp;
play  &quot;TH 8D 6C 4D 3S TH 8D 6C 4D 4S&quot; 
&nbsp;
&nbsp;
&nbsp;
let rdinput =   use file = System.IO.File.OpenText(&quot;poker.txt&quot;)
                let p1count = ref 0  
&nbsp;
                while not file.EndOfStream do
                 if play (file.ReadLine()) = One then p1count := !p1count+1
&nbsp;
                file.Close()
                !p1count</span></pre></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/CanErten/~4/Gn3r6L7UTlw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/poker-programming-problem/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.codingday.com/poker-programming-problem/</feedburner:origLink></item>
		<item>
		<title>Multiple Inheritance in C# using Dynamic Features</title>
		<link>http://feedproxy.google.com/~r/CanErten/~3/nyO-YBL3mw4/</link>
		<comments>http://www.codingday.com/multiple-inheritance-in-c-using-dynamic-features/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 16:03:30 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[multiple inheritance]]></category>

		<guid isPermaLink="false">http://www.canerten.com/?p=346</guid>
		<description>Multiple Inheritance is a feature that a class that can inherit more than one class. Although CLR does not really care about it, it is not possible in the mainstream .NET languages to have multiple inheritance. It is arguable that why we would ever need multiple inheritance. I think it is the same paradox as [...]</description>
				<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Multiple_inheritance">Multiple Inheritance</a> is a feature that a class  that can inherit more than one class. Although CLR does not really care about it, it is not possible in the mainstream .NET languages to have multiple inheritance. </p>
<p>It is arguable that why we would ever need multiple inheritance. I think it is the same paradox as having dynamic types in a statically typed language. I am not going into that debate as it is already decided for almost a decade. This is an attempt on how to achieve the same effect using dynamic types easily.</p>
<p>In C++, multiple inheritance can simply be expressed like this :</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> Auto <span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
  <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> Go<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> a<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
  <span style="color: #0000ff;">virtual</span> ~Auto<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">class</span> Animal <span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
  <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> Go<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
  <span style="color: #0000ff;">virtual</span> ~Animal<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">class</span> SampleClass <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> Auto, <span style="color: #0000ff;">public</span> Animal<span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>	
	SampleClass <span style="color: #000040;">*</span>a <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> SampleClass<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> 
	<span style="color: #666666;">//a-&gt;Go(5); // Compiler error for ambigouity</span>
	<span style="color: #666666;">//a-&gt;Go(&quot;going&quot;); // Compiler error for missing method</span>
	Animal<span style="color: #000040;">*</span> an <span style="color: #000080;">=</span> <span style="color: #0000ff;">dynamic_cast</span><span style="color: #000080;">&lt;</span>Animal<span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>a<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	an<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Go<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> 
&nbsp;
	Auto<span style="color: #000040;">*</span> at <span style="color: #000080;">=</span> <span style="color: #0000ff;">dynamic_cast</span><span style="color: #000080;">&lt;</span>Auto<span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>a<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	at<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Go<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">7</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>When C# introduced dynamic type system and shared type system with C# 4, I thought it should be possible to express multiple inheritance using the new syntax. More like a forced Javascript prototypal inheritance instead of classical inheritance. However it turned out that it was even easier than that. It is relying on the runtime to operate on the types underlying with dynamic conversions, simply reflection.</p>
<p>Obviously it is not forced by the compiler, and you wouldn&#8217;t get intellisense but it will behave like a multiple inherited object. To achieve that the dynamic features of C# 4 has been used. </p>
<p>The same implementation in C# using Minherit object that has been created for reflected multiple inheritance.<br />
So in C#, it would look like this :</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> Auto
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Go<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> a<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>            
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> Animal
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Go<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>        
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> SampleClass <span style="color: #008000;">:</span> Minherit<span style="color: #008000;">&lt;</span>Auto, Animal<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&#123;</span>                        
        <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">dynamic</span> sample <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SampleClass<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>            
            a<span style="color: #008000;">.</span><span style="color: #0000FF;">Go</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">4</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// this will succeed at runtime and call the first Go(int)            </span>
            a<span style="color: #008000;">.</span><span style="color: #0000FF;">Go</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;going&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// runtime error for missing method</span>
            Animal an <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>Animal<span style="color: #008000;">&#41;</span>sample<span style="color: #008000;">;</span>
            Auto x <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>Auto<span style="color: #008000;">&#41;</span>sample<span style="color: #008000;">;</span>
&nbsp;
            an<span style="color: #008000;">.</span><span style="color: #0000FF;">Go</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            x<span style="color: #008000;">.</span><span style="color: #0000FF;">Go</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">7</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>            
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>It uses dynamic sample that has come with .NET Framework 4 CTP. I actually think that sample will go to mscorlib with the final release in the System namespace</p>
<p>As the code got a bit long, I post it as project zip file if you are interested.<br />
<div class='download-link'>
							<a href='http://www.codingday.com/download.php?file=http://www.codingday.com/downloads/cs4trials.zip'><img alt='Download' class='leftalign' src='http://www.codingday.com/wp-content/plugins/dBeautifier/icons/tar.png' /></a>
							<h4>
								<a href='http://www.codingday.com/download.php?file=http://www.codingday.com/downloads/cs4trials.zip'> C# 4 Dynamic Multiple Inheritance</a>
							</h4><p>Downloads: 854  File Name: cs4trials.zip</p>
						</div></p>
<p>It is possible to create multiple inheritance abstraction as shown below. Here are the selected four methods to display how the GetMember and SetMember is implemented.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;">  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">object</span> Call<span style="color: #008000;">&#40;</span>CallAction action, <span style="color: #0600FF; font-weight: bold;">params</span> <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">var</span> objMethod <span style="color: #008000;">=</span> GetMember<span style="color: #008000;">&lt;</span>MethodInfo<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, action<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Concat</span><span style="color: #008000;">&#40;</span>
                               GetMember<span style="color: #008000;">&lt;</span>MethodInfo<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>base1, action<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Concat</span><span style="color: #008000;">&#40;</span>
                                   GetMember<span style="color: #008000;">&lt;</span>MethodInfo<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>base2, action<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>                                                     
&nbsp;
            <span style="color: #6666cc; font-weight: bold;">object</span> result <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">bool</span> executionSuccess <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">var</span> item <span style="color: #0600FF; font-weight: bold;">in</span> objMethod<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">try</span>
                <span style="color: #008000;">&#123;</span>                     
                    result <span style="color: #008000;">=</span> item<span style="color: #008000;">.</span><span style="color: #0000FF;">Second</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Invoke</span><span style="color: #008000;">&#40;</span>item<span style="color: #008000;">.</span><span style="color: #0000FF;">First</span>, args<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    executionSuccess <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
                <span style="color: #0600FF; font-weight: bold;">catch</span> 
                <span style="color: #008000;">&#123;</span>                    
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>executionSuccess<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> result<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">else</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> MissingMethodException<span style="color: #008000;">&#40;</span>action<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>                    
        <span style="color: #008000;">&#125;</span>
 <span style="color: #0600FF; font-weight: bold;">private</span> IEnumerable<span style="color: #008000;">&lt;</span>Pair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">object</span>, T<span style="color: #008000;">&gt;&gt;</span> GetMember<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> obj, <span style="color: #6666cc; font-weight: bold;">string</span> name<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">from</span> member <span style="color: #0600FF; font-weight: bold;">in</span> obj<span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetMember</span><span style="color: #008000;">&#40;</span>name<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OfType</span><span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
                   <span style="color: #0600FF; font-weight: bold;">select</span> <span style="color: #008000;">new</span> Pair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">object</span>, T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>obj, member<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">object</span> GetMember<span style="color: #008000;">&#40;</span>GetMemberAction action<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">var</span> property <span style="color: #008000;">=</span> GetMember<span style="color: #008000;">&lt;</span>PropertyInfo<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, action<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Concat</span><span style="color: #008000;">&#40;</span>
                                     GetMember<span style="color: #008000;">&lt;</span>PropertyInfo<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>base1, action<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Concat</span><span style="color: #008000;">&#40;</span>
                                         GetMember<span style="color: #008000;">&lt;</span>PropertyInfo<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>base2, action<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FirstOrDefault</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">var</span> field <span style="color: #008000;">=</span> GetMember<span style="color: #008000;">&lt;</span>FieldInfo<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, action<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Concat</span><span style="color: #008000;">&#40;</span>
                            GetMember<span style="color: #008000;">&lt;</span>FieldInfo<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>base1, action<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Concat</span><span style="color: #008000;">&#40;</span>
                                GetMember<span style="color: #008000;">&lt;</span>FieldInfo<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>base2, action<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FirstOrDefault</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>property <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> property<span style="color: #008000;">.</span><span style="color: #0000FF;">Second</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span>property<span style="color: #008000;">.</span><span style="color: #0000FF;">First</span>, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>field <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> field<span style="color: #008000;">.</span><span style="color: #0000FF;">Second</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span>field<span style="color: #008000;">.</span><span style="color: #0000FF;">First</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">else</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> MissingMemberException<span style="color: #008000;">&#40;</span>action<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> SetMember<span style="color: #008000;">&#40;</span>SetMemberAction action, <span style="color: #6666cc; font-weight: bold;">object</span> <span style="color: #0600FF; font-weight: bold;">value</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">var</span> properties <span style="color: #008000;">=</span> GetMember<span style="color: #008000;">&lt;</span>PropertyInfo<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, action<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Concat</span><span style="color: #008000;">&#40;</span>
                                    GetMember<span style="color: #008000;">&lt;</span>PropertyInfo<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>base1, action<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Concat</span><span style="color: #008000;">&#40;</span>
                                        GetMember<span style="color: #008000;">&lt;</span>PropertyInfo<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>base2, action<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">var</span> fields <span style="color: #008000;">=</span> GetMember<span style="color: #008000;">&lt;</span>FieldInfo<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, action<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Concat</span><span style="color: #008000;">&#40;</span>
                            GetMember<span style="color: #008000;">&lt;</span>FieldInfo<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>base1, action<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Concat</span><span style="color: #008000;">&#40;</span>
                                GetMember<span style="color: #008000;">&lt;</span>FieldInfo<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>base2, action<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #6666cc; font-weight: bold;">bool</span> issucceess <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">var</span> property <span style="color: #0600FF; font-weight: bold;">in</span> properties<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">try</span>
                <span style="color: #008000;">&#123;</span>
                    property<span style="color: #008000;">.</span><span style="color: #0000FF;">Second</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SetValue</span><span style="color: #008000;">&#40;</span>property<span style="color: #008000;">.</span><span style="color: #0000FF;">First</span>, <span style="color: #0600FF; font-weight: bold;">value</span>, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    issucceess <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
                <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span>             
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>issucceess<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">var</span> field <span style="color: #0600FF; font-weight: bold;">in</span> fields<span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">try</span>
                    <span style="color: #008000;">&#123;</span>
                        field<span style="color: #008000;">.</span><span style="color: #0000FF;">Second</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SetValue</span><span style="color: #008000;">&#40;</span>field<span style="color: #008000;">.</span><span style="color: #0000FF;">First</span>, <span style="color: #0600FF; font-weight: bold;">value</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        issucceess <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                    <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>issucceess<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> MissingMemberException<span style="color: #008000;">&#40;</span>action<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/CanErten/~4/nyO-YBL3mw4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/multiple-inheritance-in-c-using-dynamic-features/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://www.codingday.com/multiple-inheritance-in-c-using-dynamic-features/</feedburner:origLink></item>
		<item>
		<title>Eclipse Reference Project Management with Maven</title>
		<link>http://feedproxy.google.com/~r/CanErten/~3/hby0x8UZvew/</link>
		<comments>http://www.codingday.com/eclipse-reference-project-management-with-maven/#comments</comments>
		<pubDate>Sun, 20 Jul 2008 00:50:33 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://www.canerten.com/eclipse-reference-project-management-with-maven/</guid>
		<description>I was using Eclipse for one for the previous projects as a development environment. It has some powerful features. But I have to say not as powerful as Visual Studio. Anyway since it is possibly the best IDE for Java development it was my choice on the day of implementation. The project that I was [...]</description>
				<content:encoded><![CDATA[<p><img style="margin: 0px 5px 5px 0px" height="75" src="http://assets.devx.com/articleicons/6601.gif" width="75" align="left" border="0" />I was using <a href="http://www.eclipse.org/" target="_blank">Eclipse</a> for one for the previous projects as a development environment. It has some powerful features. But I have to say not as powerful as Visual Studio. Anyway since it is possibly the best IDE for Java development it was my choice on the day of implementation. </p>
<p>The project that I was working was done using Borland’s <a href="http://www.codegear.com/products/jbuilder" target="_blank">Jbuilder</a>. Unfortunately that IDE doesn’t exist anymore as it is discontinued by a new company. Thanks to Eclipse import project wizard, the project migration wasn&#8217;t difficult at all. </p>
<p>I just opened the project XML and the project was ready to be working. However, when using with different big open source libraries, Eclipse has a problem in managing them. Actually I have a problem in managing them, because I need to find the required version of each dependency and so on. It is the difficulty of package and build management of eclipse. </p>
<p>It is often difficult to reference a library and get all the dependencies on Eclipse. Somehow it doesn&#8217;t warn at compile time as well and you get exception at runtime which is not nice enough. </p>
<p>Than I found a project called <a href="http://maven.apache.org/" target="_blank">Maven</a> for doing proper build systems. What it does is has an online repository that have all the dependencies filed and it downloads the required assemblies for your project. So you don&#8217;t have download each package separately and link to project. All the best it is very well integrated with eclipse with its marvelous plug-in. </p>
<p>You load the plug-in and tell maven to add a reference to your project. I know Java programmers call this as something else but since I&#8217;m mainly a .NET programmer I hope somebody will find it useful. </p>
<p>Anyway, it stores the configuration in XML file that you can tweak it later if needed. All the updates to the references can happen automatically as well which is quite nice. </p>
<img src="http://feeds.feedburner.com/~r/CanErten/~4/hby0x8UZvew" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/eclipse-reference-project-management-with-maven/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.codingday.com/eclipse-reference-project-management-with-maven/</feedburner:origLink></item>
		<item>
		<title>Next Generation Cryptography (CNG) for .NET</title>
		<link>http://feedproxy.google.com/~r/CanErten/~3/QCBV9Y_vz0M/</link>
		<comments>http://www.codingday.com/next-generation-cryptography-cng-for-net/#comments</comments>
		<pubDate>Sun, 20 Jul 2008 00:23:33 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.canerten.com/next-generation-cryptography-cng-for-net/</guid>
		<description>Last year, Windows Kernel team released a new cryptography libraries called Next Generation Cryptography (CNG). Although it is only available on Windows Vista and Windows Server 2008 kernels so far, I think it is going to replace the CAPICOM with its powerful new implementations. I quite liked the new CNG libraries as it gets over [...]</description>
				<content:encoded><![CDATA[<p><img style="margin: 0px 5px 5px 0px" src="http://static.flickr.com/2308/2453544236_f1b1dac91d_t.jpg" border="0" alt="Droster Lock (Infinite Combination)" align="left" />Last year, Windows Kernel team released a new cryptography libraries called <a href="http://msdn.microsoft.com/en-us/library/aa376210(VS.85).aspx" target="_blank">Next Generation Cryptography (CNG).</a> Although it is only available on Windows Vista and Windows Server 2008 kernels so far, I think it is going to replace the <a href="http://msdn.microsoft.com/en-us/library/ms995332.aspx" target="_blank">CAPICOM</a> with its powerful new implementations.</p>
<p>I quite liked the new CNG libraries as it gets over some limitations of the previous library.</p>
<p>CLR security team released a new project on codeplex called <a href="http://www.codeplex.com/clrsecurity" target="_blank">CLR Security</a> for that new cryptography library on .NET. So it is possible to benefit from those libraries in managed worlds as well. For a detailed description be sure to check <a href="http://blogs.msdn.com/shawnfa/archive/2008/07/10/clr-security-team-codeplex-site.aspx" target="_blank">security blog</a>.</p>
<p>Also, the team is very quick to respond and provide fixes if necessary.</p>
<img src="http://feeds.feedburner.com/~r/CanErten/~4/QCBV9Y_vz0M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/next-generation-cryptography-cng-for-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.codingday.com/next-generation-cryptography-cng-for-net/</feedburner:origLink></item>
		<item>
		<title>Recent Titles – Common Lisp ebook for free</title>
		<link>http://feedproxy.google.com/~r/CanErten/~3/KBRBdQm0EgQ/</link>
		<comments>http://www.codingday.com/recent-titles-common-lisp-ebook-for-free/#comments</comments>
		<pubDate>Sat, 19 Jul 2008 23:43:46 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[Book]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[ebook]]></category>
		<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://www.canerten.com/recent-titles-common-lisp-ebook-for-free/</guid>
		<description>I was thinking of reading a Lisp book. I checked the titles and decided to buy, luckily, it&amp;#8217;s freely provided in the Apress’ Practical Common Lisp page. I doubt that it is done by mistake, because the e-book price is also indicated but anyway there is a free link to download it.</description>
				<content:encoded><![CDATA[<p><img title="lisp" style="border-right: 0px; border-top: 0px; margin: 0px 5px; border-left: 0px; border-bottom: 0px" height="297" alt="lisp" src="http://www.codingday.com/wp-content/uploads/2008/07/lisp3.jpg" width="204" align="left" border="0" /></p>
<p>I was thinking of reading a Lisp book. I checked the titles and decided to buy,   <br />luckily, it&#8217;s freely provided in the <a href="http://www.apress.com/book/view/9781590592397" target="_blank">Apress’ Practical Common Lisp page</a>.</p>
<p>I doubt that it is done by mistake, because the e-book price is also indicated but anyway there is a free link to download it.</p>
<img src="http://feeds.feedburner.com/~r/CanErten/~4/KBRBdQm0EgQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/recent-titles-common-lisp-ebook-for-free/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.codingday.com/recent-titles-common-lisp-ebook-for-free/</feedburner:origLink></item>
	</channel>
</rss>
