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

<channel>
	<title>Coranac</title>
	<atom:link href="http://www.coranac.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.coranac.com</link>
	<description>my own little world</description>
	<lastBuildDate>Wed, 02 May 2012 10:02:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>GCC 4.7 vs ARM assembly</title>
		<link>http://www.coranac.com/2012/05/gcc-4-7-vs-arm-assembly/</link>
		<comments>http://www.coranac.com/2012/05/gcc-4-7-vs-arm-assembly/#comments</comments>
		<pubDate>Tue, 01 May 2012 15:49:13 +0000</pubDate>
		<dc:creator>cearn</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tonc]]></category>

		<guid isPermaLink="false">http://www.coranac.com/?p=292</guid>
		<description><![CDATA[In a recent bout of &#8216;They Changed It, Now It Sucks&#8217;, GCC 4.7 won&#8217;t add interworking instructions to ARM assembly code unless you add a .type directive to the function boilerplate. Following some code from devkitARM 38 announcement: &#160; &#160; &#8230; <a href="http://www.coranac.com/2012/05/gcc-4-7-vs-arm-assembly/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
In a recent bout of &lsquo;<a href="http://tvtropes.org/pmwiki/pmwiki.php/Main/TheyChangedItNowItSucks">They Changed It, Now It Sucks</a>&rsquo;, GCC 4.7 won&#8217;t add interworking instructions to ARM assembly code unless you add a <code>.type</code> directive to the function boilerplate. Following some code from <a href="http://devkitpro.org/viewtopic.php?f=13&#038;t=3073">devkitARM 38 announcement</a>:
</p>
<div class="gccarm">
<div class="gccarm proglist" style=" ">&nbsp; &nbsp; <span class="co1">@ section directive goes here.</span><br />
&nbsp; &nbsp; <span class="co1">@ code dirctive goes here.</span><br />
&nbsp; &nbsp; <span class="kw4">.align</span>&nbsp; <span class="nu0">2</span><br />
&nbsp; &nbsp; <span class="kw4">.global</span> foo<br />
&nbsp; &nbsp; .<span class="kw4">type</span> &nbsp; foo STT_FUNC&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">@ Add this line right here</span><br />
foo:<br />
&nbsp; &nbsp; <span class="co1">@ etc</span></div>
</div>
<p>Though the change is simple, it does effectively mean that basically <b>all</b> older assembly code is now b0rked, including tonc and many of the ASM functions I&#8217;ve written about here. I hope I can assess the damage this weekend and fix everything.</p>
<p>
]]></content:encoded>
			<wfw:commentRss>http://www.coranac.com/2012/05/gcc-4-7-vs-arm-assembly/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Gaddammit, SpaceChem</title>
		<link>http://www.coranac.com/2012/04/gaddammit-spacechem/</link>
		<comments>http://www.coranac.com/2012/04/gaddammit-spacechem/#comments</comments>
		<pubDate>Sun, 08 Apr 2012 17:09:57 +0000</pubDate>
		<dc:creator>cearn</dc:creator>
				<category><![CDATA[spacechem]]></category>

		<guid isPermaLink="false">http://www.coranac.com/?p=270</guid>
		<description><![CDATA[&#160; So here I was, thinking I could have a nice and relaxing easter. But then the spacechem bug bit me again, so now I just have to write down some assignments to solve when AFK. But I can stop &#8230; <a href="http://www.coranac.com/2012/04/gaddammit-spacechem/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p></p>
<p><img class="centered" src="/img/spacechem/addiction/spacechem-nope.jpg" alt="nope"></p>
<p><div>&nbsp;</div></p>
<p>
So here I was, thinking I could have a nice and relaxing easter. But then the spacechem bug<br />
bit me again, so now I just <i>have</i> to write down some assignments to solve when AFK.
</p>
<p><div  class="cptc" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"></span>
</div>
</p>
<p>
But I can stop anytime I want! Really!
</p>
<p><div>&nbsp;</div><div>&nbsp;</div></p>
<p>
Oh, I also found this on a <a href="http://forums.penny-arcade.com/discussion/comment/21933211#Comment_21933211">penny-arcade thread</a>:
</p>
<blockquote><p>
this goddamned game. spend 20-40 minutes finishing a level and think &#8220;hey I&#8217;m pretty clever&#8221; only to load the next one and have the game kick you in the balls and whisper &#8220;nope, you&#8217;re actually dumb as shit&#8221; in your ear while you&#8217;re rolling on the ground
</p></blockquote>
<p>
Yeah. That&#8217;s pretty much sums it up.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coranac.com/2012/04/gaddammit-spacechem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SpaceChem tutorial : Fun With Water</title>
		<link>http://www.coranac.com/2012/04/spacechem-tutorial-fun-with-water/</link>
		<comments>http://www.coranac.com/2012/04/spacechem-tutorial-fun-with-water/#comments</comments>
		<pubDate>Sun, 01 Apr 2012 13:44:49 +0000</pubDate>
		<dc:creator>cearn</dc:creator>
				<category><![CDATA[spacechem]]></category>

		<guid isPermaLink="false">http://www.coranac.com/?p=251</guid>
		<description><![CDATA[1 Introduction 2 Varying solutions for water 3 Summary 1 Introduction One of the great things about SpaceChem is that you&#8217;re completely free in the approach to a solution, so you can let your creativity run wild. At the same &#8230; <a href="http://www.coranac.com/2012/04/spacechem-tutorial-fun-with-water/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p></p>
<p><ul>
  <li> <a href="#sec-intro">1
Introduction
</a> </li>
  <li> <a href="#sec-solutions">2
Varying solutions for water
</a> </li>
  <li> <a href="#sec-conc">3
Summary
</a> </li>
</ul>
</p>
<p><h2 id="sec-intro">1
Introduction
</h2>
</p>
<p>
One of the great things about SpaceChem is that you&#8217;re completely free in<br />
the approach to a solution, so you can let your creativity run wild. At the<br />
same time, one of the worst things about Spacechem is that you&#8217;re completely<br />
free in the approach to a solution, so you <i>have</i> to let your creativity<br />
run wild. This means that, at first, you might have <i>no</i> idea where to<br />
start. And even if you do, the solution you come up with might be, well, let&#8217;s<br />
be generous and say&lsquo;not exactly brilliant&rsquo;. For that reason, I&#8217;d like<br />
to show a few common patterns that can serve as starting points for efficient<br />
solutions.
</p>
<p><div>&nbsp;</div></p>
<p>
For this, I will use the assignment shown in SpaceChem&#8217;s introduction video,<br />
where you use hydrogen (&alpha;) and oxygen (&beta;) to create water (&omega;).<br />
This is ideal for two reasons. First, like any good introduction video, it shows<br />
the building process and what happens when a command is activated, so you should have<br />
some idea of how things work in this game. Second, it&#8217;s also actually a <i>terribly</i><br />
inefficient solution, so we can try to optimize it <kbd>:)</kbd>.
</p>
<p><span id="more-251"></span></p>
<div class="cptc" style="width:560px">
<iframe width="560" height="315" src="http://www.youtube.com/embed/Gk8JwvtVs38" frameborder="0" allowfullscreen></iframe><br />
Original introduction video with H<sub>2</sub>O example, by zachatronicsindustries. WATCH THIS FIRST!
</div>
<p><div class="note" >
<div  class="nh">Audience : beginner-intermediate</div>

</p>
<p>
I would classify this as an beginner-intermediate level tutorial. I expect you to understand<br />
at least the basics of the game: how waldos move, what the different instruction symbols mean,<br />
what bonders do, and that by activating the right symbols at the right time and space (I&#8217;m not<br />
talking about what that right sequence <i>is</i>, just the principle of the thing) you can solve a<br />
mission.
</p>
<p><div>&nbsp;</div></p>
<p>In other words, I expect you to understand the video linked to above.
</p>
<p>
</div>
</p>
<p><h2 id="sec-solutions">2
Varying solutions for water
</h2>
</p>
<p><h3 id="ssec-solutions-rules">2.1
Ground rules
</h3>
</p>
<p>
Before we go into the actual solutions, here are a few notes on nomenclature. Note that as far<br />
as I know, there is no standard nomenclature for elements and patterns. What I&#8217;m using here is<br />
mostly based on terms I&#8217;ve found on the web and my own terms. If you think you know of terms<br />
that better suit the situation or are more common, please say so.
</p>
<ul>
<li>
    A reactor is basically a 10&times;8 matrix with two 4&times;4 input zones<br />
    on the left called &alpha; and &beta;, and two 4&times;4 output zones on the<br />
    right called &psi; and &omega;.
  </li>
<li>
    I will refer to a specific cell on the grid using Excel&#8217;s cell-referencing.<br />
    That is, the top-left cell is (a1), and the bottom-right is (j8). Sometimes<br />
    it&#8217;s also useful to name a cell by its relation within an input or output zone.<br />
    For example, cell (a5) is also the top-left cell in &beta;, so it may also<br />
    be referred to as (&beta;:a1).
  </li>
<li>
    A reactor is essentially a dual-threaded computer. The red and blue paths<br />
    are essentially scripts of commands. The big red/blue circles running around<br />
    are the instruction pointers called <dfn>waldos</dfn>. The smaller red/blue<br />
    circles with text are <dfn>symbols</dfn>. If a waldo runs into a symbol,<br />
    the command belonging to that symbol is executed. The gray elements in the<br />
    background are reactor <dfn>features</dfn>. Interesting things happen when<br />
    atoms are over a feature at the same time as a waldo executes the right<br />
    command. A specific feature instance is also referred to as a <dfn>plate</dfn>.
  </li>
</ul>
<p><div>&nbsp;</div></p>
<p>
There are also a few ground rules and tips that you need to be aware of before even<br />
starting.
</p>
<ul>
<li>
    <b>All</b> elements in a reactor can be moved. Not only the symbols you&#8217;ve<br />
    placed yourself, but also the start symbols and the reactor feature plates.
  </li>
<li>
    <b>All</b> symbols have a right-click menu for more options. For instance, the<br />
    start-symbols can get a different starting direction. You can also switch<br />
    colors of each symbol (<b>including</b> inputs and outputs), or switch<br />
    between similar types of commands (again, like &alpha;&nbsp;&harr;&nbsp;&beta; or<br />
    &psi;&nbsp;&harr;&nbsp;&omega;). DO NOT FORGET THIS!!! Check the right-click menu<br />
    for each symbol to learn its variations.
  </li>
<li>
    Each command has a keyboard shortcut, and many of the standard mouse/keyboard UI commands<br />
    apply. Ctrl+Z/+Y undo and redo and Del deletes. You can<br />
    drag-select, a Shift+click does multi-select and Ctrl+drag copies symbols. Just toy around<br />
    a bit to see what else is possible.
  </li>
<li>
    There is no true simultaneous command execution. When red and blue perform<br />
	a command at the &#8216;same&#8217; time, red will execute first. We&#8217;ll see how<br />
	this can be used to our benefit. (There is also a certain order in<br />
	which the bonders are executed, but how it works exactly is currently unknown.)
  </li>
<li>
    The input molecules will appear exactly as shown on the input. Or, in case it<br />
	comes from another reactor&#8217;s output, exactly as it was outputted there.
  </li>
<li>
    The output molecules do not need to match the target molecule&#8217;s position or<br />
	orientation. As long as all the correct bonds are in place, it will be<br />
	accepted.
  </li>
<li>
    A feature activator-symbol does not have to be placed on top of the feature plate.<br />
	For example, you can activate the bonders when the waldo isn&#8217;t anywhere<br />
	near the plates. Also, you don&#8217;t have to drop an atom to bond or unbond it.
  </li>
</ul>
<p>
The thing about the items listed above is that they&#8217;re not all that obvious from<br />
playing the game (although some do appear in the trainings). A more extensive list can<br />
be found at <a<br />
href="http://www.reddit.com/r/spacechem/comments/h6nbd/tips_and_tricks_for_new_players/" target="_blank"><br />
reddit: tips_and_tricks_for_new_players</a>.
</p>
<p>
Also, don&#8217;t forget to visit <a href="http://spacechem.net">SolutionNet</a> where you can upload your own solution and view those of others to get some ideas on where to start if you&#8217;re stuck.<sup class="fnote"><a href="#ft-nr1" title="Please don&#8217;t copy solutions wholesale, though, that would be cheating &ndash; not just cheating others, but you&#8217;re also cheating yourself: if there&#8217;s one thing everybody agrees on it&#8217;s the intense pride one feels when you finally solve a mission, and you&#8217;d completely miss that. Seriously, looking up solutions to a puzzle game. What the hell?!?">(1)</a></sup>.
</p>
<p><div>&nbsp;</div></p>
<p><h4>
ResearchNet code
</h4>
</p>
<p>
Annnnnd &hellip; oh yeah! If you want to play along with these solutions, you&#8217;ll<br />
have to create it in researchNet, because there&#8217;s no actual assignment for it. Or<br />
you can also use the following code:
</p>
<div class="none">
<div class="none proglist" style=" ">H4sIACYioU8A/3WPMWvDMBCF/0q42QbJdAjSXrxlzBA6KPY5FiiSkU5Q17i/vSenlLily8F9vP<br />
fu3QLWT5nqj+AxgVpAlLExXi8L3IPDLjsEBe3cx3BDr1stpRQCKuhC9gRKNuvbWoH833t6n4vz<br />
xM7jHydbQ6ZdjS3qyX82hFG3n6IpEXxdNxwkddPsi4gSNppUOxNvWD9iQQ3GJazgGnyPsf4Wvz<br />
yUCX0K8UdT0JAT7kmanCX6BQkdTiE+Y5qnUjdiQhO7kZt5cy/kNfvD2dJ42D5hbjKN5Sx0rPQM<br />
ejsMlt+lGZRYvwBa3V5umQEAAA==</div>
</div>
<p>
Technically, ResearchNet only opens up once you solved mission 7-1, but for those<br />
who would benefit the most from this exercise, that&#8217;s probably a long way away.<br />
No matter, you can also just hack it. I don&#8217;t think there are any adverse consequences.<br />
You can find an &lsquo;Import&rsquo; button under &lsquo;Create or Import an<br />
 Assignment&rsquo;.
</p>
<p><h3 id="ssec-sol-overview">2.2
Overview
</h3>
</p>
<p>
Here is a list of the solutions we&#8217;ll be looking at. There&#8217;s the original, of course, and a<br />
version where the circuits are compressed as much as possible. There&#8217;s a single-loop version<br />
for least-symbols, and one where both waldos do that loop to optimize for speed. Finally, a<br />
solution where the paths are just single lines, which if available decreases the number of<br />
symbols and can be quick to boot.
</p>
<ul class="vlist">
<li><a href="#ssec-sol-base">2.3 Original: base solution</a></li>
<li><a href="#ssec-sol-tight">2.4 Cycle optimization: tight loop</a></li>
<li><a href="#ssec-sol-single">2.5<br />
    Symbol optimization: single loop / parked waldo waldo</a></li>
<li><a href="#ssec-sol-double">2.6<br />
    Cycle optimization: parallel execution / twin loop</a></li>
<li><a href="#ssec-sol-lines">2.7 Symbol optimization: bouncers</a></li>
</ul>
<p><h4>
Video
</h4>
</p>
<p>
I&#8217;ve also made an instructional video, so that you can view the following solutions in action.<br />
It&#8217;s much easier to see what a solution is doing if you can follow the waldos over time.
</p>
<div class="cptc" style="width:420px">
<iframe width="420" height="315" src="http://www.youtube.com/embed/wLkhC8qd-vM" frameborder="0" allowfullscreen></iframe><br />
Accompanying video showing all the solutions discussed below.
</div>
<p><h3 id="ssec-sol-base">2.3
Original : base solution
</h3>
</p>
<p>
With that out of the way, let&#8217;s begin. Fig&nbsp;<span class="oops">[[ref:img-water-base]]</span> is a picture<br />
of the solution in the intro video (click to get a blowout). This is our base<br />
solution. the first thing you should notice is that both red and blue paths are<br />
closed. This is important, because we need to make more than one H<sub>2</sub>O,<br />
so we need to loop back to the beginning of the routine again. Also note that<br />
for a single H<sub>2</sub>O, red brings two H&#8217;s to the<br />
table<sup class="fnote"><a href="#ft-nr2" title="onto the plates, AHAHAHA *cough*, ahem, sorry about that.">(2)</a></sup><br />
but blue only brings one O, and that red&#8217;s path is also considerably longer.<br />
This would result in timing problems, but the sync symbols at (d5) for red, and<br />
(b7) for blue mean that everything works out. By the time blue can continue on<br />
its path, red will have already placed two H&#8217;s on the plates for blue&#8217;s O to<br />
bind with. After that, blue will drop the finished H<sub>2</sub>O at the output<br />
zone at (&omega;:b2) and then actually output it via the &omega; symbol at (&omega;:a3).<br />
Note that the output molecule is actually rotated 180&deg; from the target, but<br />
is still accepted.
</p>
<p><div  class="cptc" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"></span>
</div>
</p>
<h4>Process</h4>
<p>
The whole process is as follows.
</p>
<ol>
<li>Red &alpha;-ins (c2) and grab H (b2). Blue &beta;-ins and wait (b7).</li>
<li>Red drops at (e4).</li>
<li>Red &alpha;-ins (c1) grabs H (b2).</li>
<li>Red syncs (d5), which releases blue. Blue grabs O (b6).</li>
<li>Red drops (f5).</li>
<li>Blue binds to O (e5) to two H&#8217;s (e4,f5).</li>
<li>Blue drops H<sub>2</sub>O at (&omega;:b2) and then &omega;-outs at<br />
    (&omega;:a3). Loop complete. </li>
</ol>
<h4>Results</h4>
<div class="cblock">
<table border="1">
<tr>
<th>cycles</th>
<td>323</td>
</tr>
<tr>
<th>reactors</th>
<td>1</td>
</tr>
<tr>
<th>symbols</th>
<td>24</td>
</tr>
</table>
</div>
<p>
The results for this solution are 323 cycles, 1 reactor, and 24<br />
symbols<sup class="fnote"><a href="#ft-nr3" title="start-symbols do not count to the final score, but arrows
do.">(3)</a></sup>. Which, is alright I suppose, but as we&#8217;ll see, we can do a lot better<br />
on both cycles and symbols.
</p>
<p><h3 id="ssec-sol-tight">2.4
Cycle optimization: tight loop
</h3>
</p>
<p>
First, let&#8217;s take a look at cycle optimisation. If you look at<br />
Fig&nbsp;<span class="oops">[[ref:img-water-base]]</span>, and/or run the solution, you&#8217;ll notice that the waldos<br />
spend a lot of time doing nothing but moving. the first order of business should<br />
be to shorten the path lengths as much as possible.
</p>
<p>
For example, the two<br />
right-most symbols of red&#8217;s path are the two grab-drops at (e4,f5), but the path<br />
continies to the right one more step before going up again. Tightening that up so<br />
that red goes up right at the grab-drops reduces the path length by 2&times;2=4,<br />
saving 40 cycles.
</p>
<p>
And that&#8217;s just one spot where we can tighten the loop. By moving the bonders a<br />
little, red&#8217;s path can be fitted entirely into the &alpha; zone, creating a<br />
really compact loop. At the same time, blue&#8217;s right side can be move left by<br />
one &ndash; only one, mind you, as blue still needs to be able to drop the<br />
water molecule into the output zone. The final design can be seen in Fig&nbsp;<span class="oops">[[ref:img-water-tight]]</span>.
</p>
<p><div  class="cptc" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"></span>
</div>
</p>
<h4>Process</h4>
<p>
The algorithm is actually exactly the same as before; only the positions have moved.
</p>
<ol>
<li>Red &alpha;-ins (c2) and grab H (b2). Blue &beta;-ins (c6), grabs O (b6) and waits (b5).</li>
<li>Red drops at (c3).</li>
<li>Red &alpha;-ins at (c2) again, then loops around and grabs H (b2).</li>
<li>Red syncs (c4), which releases blue.</li>
<li>Red drops (d4).</li>
<li>Blue binds to O (c4) to two H&#8217;s (c3,d4).</li>
<li>Blue drops H<sub>2</sub>O at (g6) and then &omega;-outs at<br />
    (f6). Loop complete. </li>
</ol>
<h4>Results</h4>
<div class="cblock">
<table border="1">
<tr>
<th>cycles</th>
<td>166</td>
</tr>
<tr>
<th>reactors</th>
<td>1</td>
</tr>
<tr>
<th>symbols</th>
<td>23</td>
</tr>
</table>
</div>
<p>
Wahey, 166 cycles! That&#8217;s half the time we used before, and all we&#8217;ve done is<br />
made the paths shorter. If you&#8217;re going for least cycles, keep your path lengths<br />
as low as possible.
</p>
<p>
By a happy accident, the symbol count is also one lower. Because the red path<br />
crosses itself at (c2), the &alpha;-in there is executed twice in one loop. You<br />
could have also done this in the base solution at (f2), for example, but you&#8217;d<br />
have to move the red start back as well.
</p>
<h5>Syncless</h5>
<p>
There is also the opportunity to get rid of both syncs. The reason for the sync<br />
is to keep the red and blue loop-times the same &ndash; that&#8217;s basically what<br />
syncing means. However, the red and blue loops are now 16 and 14 cycles long,<br />
and it&#8217;s rather trivial to make blue&#8217;s 2 cycles longer. You&#8217;ll also<br />
have to move the blue start back to ensure that blue&#8217;s O won&#8217;t collide with red&#8217;s<br />
second H at (c4). Fig&nbsp;1a,b show how that can be done<br />
efficiently.
</p>
<table id="img-water-tight-II">
<tr>
<td>
      <div  class="cptc" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"></span>
</div>

	</td>
<td>
      <div  class="cptc" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"></span>
</div>

	</td>
</table>
<h5>Failed variations</h5>
<p>
There are a few other things that you might try in Fig&nbsp;<span class="oops">[[ref:img-water-tight]]</span>,<br />
but which won&#8217;t work.
</p>
<ul>
<li>
    In an attempt to speed things up by one cycle, you could move the blue<br />
    sync up to (b5). However, this would block red&#8217;s path as the latter brings<br />
    the second hydrogen, so that won&#8217;t work.
  </li>
<li>
    Alternatively, you could move the red sync left to (b4). This won&#8217;t work<br />
    either, as blue&#8217;s O will bump into red&#8217;s H as they move into (b4) and (c4),<br />
    respectively.
  </li>
<li>
    Blue&#8217;s path seems a little long. While the lower line must be at row 6<br />
	(because that&#8217;s where the O spawns), you could move the upper line down by one.<br />
	However, you&#8217;d need to lengthen red&#8217;s path to compensate, and since red&#8217;s path<br />
	is already the longer of the two, this move would actually cost you time instead<br />
	of speeding things up. When optimizing, concentrate on the<br />
	
<a href="http://en.wikipedia.org/wiki/Rate-determining_step">rate-limiting factor</a> first.
  </li>
<li>
    You could also try moving blue&#8217;s drop up to (g5), but now H<sub>2</sub> doesn&#8217;t<br />
	entirely fall into &omega;, so yeah &hellip; no.
  </li>
</ul>
<p>
As you can see, there are always things you can try to squeeze just a little bit<br />
more out of a solution. Even if most of them don&#8217;t work, the experience of the<br />
attempt will teach you what to look out for, and what works and what doesn&#8217;t.
</p>
<p><h3 id="ssec-sol-single">2.5
Symbol optimization: single loop / parked waldo
</h3>
</p>
<p>
Now let&#8217;s take a look at symbol optimization. First, think of what you need<br />
for the reaction. In this case, that&#8217;s one &beta;, two &alpha;&#8217;s, one grab,<br />
two bonds, one drop and one &omega;-output. So that&#8217;s 8 symbols. As we&#8217;ve seen<br />
earlier, sometimes you can use a symbol multiple times, so you could potentially<br />
have a minimum of 6. Now look at the results for the previous examples: 23 symbols.<br />
Where the hell are all the other symbols coming from?!?
</p>
<p>
In short: arrows. Well, arrows, syncs and useless drops, but mostly arrows.<br />
Optimizing for symbols usually comes down to reducing the amount of arrows, and<br />
eliminating syncs.
</p>
<p>
In most cases, the best way to get rid of arrows is do do everything with a<br />
single waldo &ndash; which, obviously, gets rid of syncs at the same time. The<br />
only question is whether that&#8217;s possible for the task at hand. In this case,<br />
it happens to work out. Now, I could show you how to do it with just a single<br />
waldo, but instead I&#8217;m going to introduce something better: the parked waldo.
</p>
<h5>Parked Waldo</h5>
<p>
Take a look at Fig&nbsp;<span class="oops">[[ref:img-water-single]]</span>, which shows the single-waldo<br />
design in red. It&#8217;s just a simple loop with 4 arrows, and 2 &alpha;&#8217;s, 1 &beta;,<br />
1 grab, drop, and &omega;. Note that the bond+ symbols are conspicuously absent<br />
on the red line, but there is one &ndash;and only one&ndash; on blue. What&#8217;s<br />
up with that?
</p>
<p>
The blue path is a pattern known as the <dfn>parked waldo</dfn>. When a path<br />
leads the waldo into the side of the reactor, it will just get stuck there. More<br />
precisely, it will get stuck there <i>and</i> continuously issue the<br />
command on that square, which in this case means a <code>bond+</code>.
</p>
<p>
In other words, every cycle, blue will activate the bonder plates, so when red<br />
issues an &alpha;-in, at (b3) and (c2), the H spawned at (b2) will immediately<br />
bond with the O. Please look closely at how this happens. Remember that red always<br />
comes before blue, meaning that the spawn occurs before the bond+. If the colors<br />
were reversed, it wouldn&#8217;t work. But in this arrangement, it will. The first<br />
&alpha; happens at (b3), which spawns an H at (b2). Normally,  the grabbed O<br />
would just run into the stationary H, but thanks to blue&#8217;s bond+, the<br />
atoms will bond together on the same cycle as the spawn, and everyone&#8217;s happy.
</p>
<p><div  class="cptc" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"></span>
</div>
</p>
<h4>Results</h4>
<div class="cblock">
<table border="1">
<tr>
<th>cycles</th>
<td>197</td>
</tr>
<tr>
<th>reactors</th>
<td>1</td>
</tr>
<tr>
<th>symbols</th>
<td>11</td>
</tr>
</table>
</div>
<p>
11 symbols. Again, about half that of the base solution, nice. Now I&#8217;ll be honest,<br />
I initially envisioned this to be a least-cycle trial, and it is pretty fast, but<br />
in the end it&#8217;s the symbol-count that&#8217;s the more impressive here.
</p>
<h5>Failed variations</h5>
<p>
As I mentioned before, it is also possible to do a pure one-waldo solution for<br />
this. However, in that case you can&#8217;t take advantage over the in/bond combo that<br />
the parked waldo provides. Also, you&#8217;d now need two bond symbols, so it&#8217;s<br />
actually less efficient anyway.
</p>
<p>
Another thing you might try is using a single &alpha;. For that, you&#8217;d need to<br />
make a little loop so that the &alpha; is activated twice. In doing so, however,<br />
you&#8217;d have to use two extra arrows to lose the one &alpha;, so that&#8217;s not worth it.
</p>
<p><div>&nbsp;</div></p>
<p>
So anyway: parked waldo FTW.
</p>
<p><h3 id="ssec-sol-double">2.6
Cycle optimization: parallel execution / twin loop
</h3>
</p>
<p>
In the previous section, I showed how you can how you can do the reaction using<br />
only a single waldo. Now, it stands to reason that if you used <i>two</i><br />
single-waldo paths, you&#8217;d be twice as fast. This is the <dfn>parallel<br />
execution</dfn> pattern. As usual, though, it won&#8217;t be <i>quite</i> that simple.
</p>
<p><div  class="cptc" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"></span>
</div>
</p>
<p>
Fig&nbsp;<span class="oops">[[ref:img-water-double-i]]</span> shows a solution where red and blue both create<br />
their own water. Both loops are essentially copies of Fig&nbsp;<span class="oops">[[ref:img-water-single]]</span>,<br />
with a few key differences.
</p>
<p><div>&nbsp;</div></p>
<p>
The main reason you can&#8217;t use an exact copy is because you can&#8217;t use a parked<br />
waldo anymore, so you&#8217;ll have to add a few <code>bond+</code> symbols here and<br />
there. As it happens, you need to be very specific about where these are placed.<br />
To create a tight loop, the second hydrogen <i>must</i> be bonded in the same cycle,<br />
or the HO will miss it. This means <code>bond+</code>s at (b3) and (c2).
</p>
<p>
And now we run into a second snare, namely that we also need an<br />
<code>&alpha;-in</code> at (c2). To make this work, you need to have one waldo<br />
do the input, and the other should then bond it immediately. Now, remember:<br />
<b>red goes before blue!</b> This means that red should do the<br />
<code>&alpha;-in</code>, and blue the <code>bond+</code>.
</p>
<p>
Getting the timings just right for this is a little tricky, because now the two<br />
waldos have to work together, while still doing their own rounds. For these<br />
situations, first concentrate on getting <i>a</i> <code>in/bond</code> pair<br />
working, and design the rest of the solution around it.
</p>
<p>
The red-first rule is used in two other ways as well. We can use it to create<br />
a <code>&beta;-in/grab</code> combo at the start, and a<br />
<code>drop/&omega;-out</code> at the end. This saves two cycles in the overall<br />
results.
</p>
<p>
The last little trick is to rotate the molecule so we can drop it in column G<br />
instead of H. The rotate costs an extra cycle, but the shorter path saves two,<br />
so overall it&#8217;s a 1 cycle/loop gain.
</p>
<table>
<tr>
<td>
      <div  class="cptc" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"></span>
</div>

	</td>
<td>
      <div  class="cptc" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"></span>
</div>

	</td>
</table>
<p>
The final result of all this is Fig&nbsp;<span class="oops">[[ref:img-water-double-i]]</span>. I focussed on<br />
making blue&#8217;s loop as quick as possible. This meant I had to have a<br />
<code>&beta;-in</code> on cycle 2, and <code>&alpha;-in</code>s at cycles 5 and 7.<br />
Taking the required grabs, drops and outputs into account, the earliest position<br />
I had for red&#8217;s start was (g4); I&#8217;d liked to have placed it further along, but<br />
then I&#8217;d run into a conflict with other symbols.
</p>
<p></p>
<p>
As you can see, running a twin-loop is <i>not</i> a beginner&#8217;s technique. It relies on a very<br />
careful interaction between two waldos and you have to carefully count out the cycles to make<br />
it work. But if you do get it to work, it is very powerful.
</p>
<h4>Process</h4>
<p>
Because we&#8217;re now interleaving two waldos, a single process iteration doesn&#8217;t<br />
stop until both waldos have done their paths. This produces two H<sub>2</sub>O<br />
instead of just one.
</p>
<ol>
<li>
    Cycle 2 : red <code>&beta;-in</code>s O (g6) and blue <code>grab</code>s it<br />
    immediately (b6).
  </li>
<li>
    Cycle 5 : red <code>&alpha;-in</code>s the first H (e6) and blue <code>bond+</code>s (b3).
  </li>
<li>
    Cycle 6 : red <code>&beta;-in</code>s its own O (d6).
  </li>
<li>
    Cycle 7 : red  <code>&alpha;-in</code>s the second H (c6), which blue bonds to<br />
    immediately (c2). Blue&#8217;s H<sub>2</sub>O is complete. Red then picks up its<br />
    oxygen.
  </li>
<li>
    Cycles 11 &amp; 13 : red <code>&alpha;-in</code>s its hydrogens (b3,c2), which<br />
    blue <code>bond+</code>s at (g2,g4).
  </li>
<li>
    Blue rotates, drops and <code>&omega;-out</code>s its cargo (g5,g6,f6).
  </li>
<li>
    Red rotates and drops its water (g3,g6), which blue immedately outputs (b5).<br />
	Right before this, however, the second iteration has already started as well<br />
	with a <code>&beta;-in/grab</code> combo.
  </li>
</ol>
<h4>Results</h4>
<div class="cblock">
<table border="1">
<tr>
<th>cycles</th>
<td>97</td>
</tr>
<tr>
<th>reactors</th>
<td>1</td>
</tr>
<tr>
<th>symbols</th>
<td>26</td>
</tr>
</table>
</div>
<p>
As expected, running both waldos on a single-waldo solution pretty much doubles the<br />
speed. It also doubles the symbols, though, but we were&#8217;t going for that here anyway.<br />
The tight-loop solution took 166 cycles, so we&#8217;re beating that by some 40%.
</p>
<p><h4>
A slightly faster alternative
</h4>
</p>
<p>
There is actually a way to tighten it up by a few extra cycles. The final time is decided by<br />
the tenth H<sub>2</sub>O, which is red&#8217;s responsibility. Notice that there is quite a gap<br />
between blue and red, so if red were to start closer you could gain a bit of time.
</p>
<p>
This isn&#8217;t quite a small a thing as it sounds, though. Moving red up means that a lot of other<br />
symbols have to move up with it, particularly the ones involved in combos. And you still have<br />
to make sure the new positions aren&#8217;t already taken. Look at the <code>&alpha;-in</code>s right<br />
before the O spawn-point for example. These <i>need</i> to be two apart to make the binding<br />
with H to work, but you can&#8217;t more them up by 1 or 3, because then they&#8217;d conflict with red&#8217;s<br />
grab. So, let&#8217;s try 2. The fact that now the <code>&beta;-in</code> conflicts with the<br />
<code>grab</code> doesn&#8217;t matter, as the input can occur at an earlier time as well. A bigger<br />
problem is that now red&#8217;s start will conflict with its <code>drop</code>. Fortunately, there&#8217;s<br />
a way around that to: put red&#8217;s start (and initial <code>&beta;-in</code>) in a separate<br />
branch.
</p>
<table id="img-water-double-ii">
<tr>
<td>
      <div  class="cptc" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"></span>
</div>

    </td>
<td>
      <div  class="cptc" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"></span>
</div>

	</td>
</table>
<h4>Results</h4>
<div class="cblock">
<table border="1">
<tr>
<th>cycles</th>
<td>95</td>
</tr>
<tr>
<th>reactors</th>
<td>1</td>
</tr>
<tr>
<th>symbols</th>
<td>28</td>
</tr>
</table>
</div>
<p>
The process is largely the same, so let&#8217;s go straight to the results. As expected, we&#8217;ve gained<br />
another two cycles overall, at the expense of two symbols because of the extra branch. One of<br />
these symbols is actually unnecessary in this case, because the additional <code>&beta;in</code><br />
could also be put on the main line at (f6), removing the need for the blue<br />
<code>&beta;-in</code>.
</p>
<p>
This is as close as red can get to blue &ndash; any faster and you&#8217;ll get a collision with blue<br />
at the curve back down or during the ro&hellip;ta&hellip;tion &hellip;
</p>
<div class="mini">
</p>
<p>No wait, that&#8217;s not true. Hang on &hellip;</p>
<p></p>
<p>
Eh, doesn&#8217;t matter; I can&#8217;t move red up more because of <code>&alpha;-in/grab</code> clash.<br />
Or &hellip; oh wow.
</p>
<p></p>
<p>
&hellip; I&#8217;ll &hellip; be right back. (<i>sounds of *SCIENCE* in the background</i>)
</p>
</div>
<p><h4>
And another alternative
</h4>
</p>
<p>
Right! So you <i>can</i> move red up one more space. While it&#8217;s true that there&#8217;s a potential<br />
for an <code>&alpha;-in/grab</code> clash, that particular <code>&alpha;-in</code> actually<br />
has quite a bit of freedom: as long as it&#8217;s before blue&#8217;s first <code>bond+</code> you&#8217;re good.
</p>
<p>
The final design can be found in Fig&nbsp;3. Moving<br />
<code>&alpha;-in</code>s about allows the gaps to be one cycle smaller, and I&#8217;ve also removed<br />
the superfluous <code>&beta;-in</code>.  The gap between H<sub>2</sub>O&#8217;s is now reduced to<br />
1, and after blue&#8217;s rotation it&#8217;s actually 0. you need to be very careful where you do these<br />
rotates, otherwise you&#8217;ll get collisions when the waldos move down again. Important to note<br />
is that blue&#8217;s H<sub>2</sub>O stays in the system for one cycle because it has to do its own<br />
output. Since there&#8217;s barely enough room for this now, it means that this is the theoretical<br />
limit. Usually it&#8217;s Andy or Sahishar that find that extra cycle, but this time I caught<br />
it in time <kbd>:)</kbd>.
</p>
<table id="img-water-double-iii">
<tr>
<td>
      <div  class="cptc" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"></span>
</div>

    </td>
<td>
      <div  class="cptc" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"></span>
</div>

	</td>
<td>
      <div  class="cptc" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"></span>
</div>

	</td>
</table>
<p><h4>
Results
</h4>
</p>
<p>
Nothing too exciting anymore, just the one extra cycle and symbol gain.
</p>
<div class="cblock">
<table border="1">
<tr>
<th>cycles</th>
<td>94</td>
</tr>
<tr>
<th>reactors</th>
<td>1</td>
</tr>
<tr>
<th>symbols</th>
<td>27</td>
</tr>
</table>
</div>
<p><h3 id="ssec-sol-lines">2.7
Symbol optimization: bouncers
</h3>
</p>
<p>
And finally, the <dfn>bouncer</dfn> pattern, but unfortunately I have to cheat<br />
a little here. It requires the output to be at &psi;, which technically falls<br />
outside of the parameters of the level, but the bouncer pattern is so good<br />
that I&#8217;ll allow it here.
</p>
<p>
The core principle of the bouncer is to have an arrow that reflects the waldo<br />
back in the direction it came from. This allows everything to be placed on a<br />
single line and uses two arrows less than if you used a loop. It is also the<br />
shortest path between two points.
</p>
<p>
The tricky thing about a bouncer line is that, aside from the corners, every<br />
square is passed twice. This usually means that inputs need to be at the ends to avoid<br />
collisions. The exception is to use parallel bouncers, but that way madness lies<br />
(of course, that&#8217;s where this game eventually leads to anyway, but there&#8217;s no need to<br />
rush).
</p>
<p><div  class="cptc" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"></span>
</div>
</p>
<p><h4>
Process
</h4>
</p>
<p>
In this particular case, there is one <code>&beta;-in</code> for the O and one<br />
<code>&alpha;-in</code> for both H&#8217;s. Red starts with creation of HO, and then blue picks that<br />
up, adds an extra hydrogen and drags it to &psi;. Both waldos follow single lines, the lines<br />
are of equal length so there&#8217;s no need for syncs.
</p>
<ol>
<li>Cycle 2,4: Red spawns an O and carries it upwards (b8,b6).</li>
<li>Cycle 6,7: Red spawns an H and bonds it itself (b4,b3).</li>
<li>Cycle 8: Red drops OH at (b2); blue is now at (c2).</li>
<li>Cycle 9: blue picks up the OH.</li>
<li>Cycle 10: blue is now at (c2) again, so that (b2) is free to hold the second H.<br />
    Red spawns that H (b4), and  blue bonds it in the same cycle.</li>
<li>Cycle 16,17: blue drops and outputs the H<sub>2</sub>O.</li>
</ol>
<p><h4>
Results
</h4>
</p>
<div class="cblock">
<table border="1">
<tr>
<th>cycles</th>
<td>124</td>
</tr>
<tr>
<th>reactors</th>
<td>1</td>
</tr>
<tr>
<th>symbols</th>
<td>13</td>
</tr>
</table>
</div>
<p>
124 cycles is actually pretty damn good, considering I wasn&#8217;t going for that. The reason for<br />
its speed is that red and blue&#8217;s jobs are interleaved: both paths are 12 cycles long,<br />
because of the distribution of labour, the work done with blue is essentially free. This is<br />
an example of a <dfn>relay</dfn> pattern, where the work is divided into smaller subtasks and<br />
both waldos work independently (and simultanously!) and the results of one waldo is passed onto<br />
the next. It&#8217;s similar to an assembly line or water-carrying relay.
</p>
<p>
On the face of it, 13 symbols is pretty good as well. Unfortunately, we already had a 11 symbol<br />
solution, so this one isn&#8217;t as good as I had hoped. Having said that, the bouncer pattern is<br />
a good one, and in many cases it will actually be the least-symbol solution.
</p>
<p><h2 id="sec-conc">3
Summary
</h2>
</p>
<p>
So, what have we learned here?
</p>
<ul>
<li>
    First and foremost: know the rules of the game!</p>
<ul>
<li>All symbols and plates can be moved.</li>
<li>All symbols have a context menu.</li>
<li>Red executes before blue.</li>
<li>To match the target, you only need to match atom-pairs and their bond number,<br />
          not the position or rotation.
      </ul>
<p>    There are more rules, but these are the most important ones.
  </li>
<li>
    Path length is the biggest factor for the cycle count. When optimizing for speed, make the<br />
    tracks as short as possible. That said, on occasion it&#8217;s also useful to use longer paths<br />
    for syncing, in order to remove <code>sync</code> symbols.
    </p.<br />
  </li>
<li>
    <b>Combo execution</b>. Since red&#8217;s instruction always preceded blue&#8217;s on the same cycle,<br />
    you can let the instructions work together to form, for example, <code>in/grab</code> or<br />
    <code>in/bond</code> combos. Using these at the right time can win you a few cycles<br />
    overall.
  </li>
<li>
    <b>Bouncer arrows</b> will create single-line paths instead of loops, and can be used to<br />
    minimize arrows and path-length. Combined with <code>flip-flop</code>s, you can create<br />
    some truly devious paths.
  </li>
<li>
    A <b>parked waldo</b> can be used to execute an instruction on every cycle, and can help<br />
    reduce the amount of symbols. Primary targets for these are <code>bond</code> or output<br />
    commands.
  </li>
<li>
    A parked waldo solution means that the other waldo does all the heavy lifting. In some<br />
    cases, you can duplicate that algorithm to achieve a <b>twin loop</b>, taking full<br />
    advantage of parallel execution. You can work at twice the speed, but it also costs twice<br />
    as much in symbols.
  </li>
<li>
    Another way to to achieve parallel execution is to have <b>relay waldos</b>. Part of<br />
    a waldo&#8217;s task is carrying molecules from the left input zones to the right output zones,<br />
    and this can be a significant part of the time. In the relay-waldo pattern, each<br />
    waldo carries the molecule halfway, and the first passes it on to the next. Because both<br />
    waldos now work independently, they can do their work simultaneously.<br />
    For comparison, consider a case where a single loop solution takes 20 cycles to complete.</p>
<ul>
<li>With a parked waldo, you use the single loop and have 20c/output.</li>
<li>With a twin-loop, you have two 20-cycle loops, and get 20/2 = 10c/output.</li>
<li>With a relay, each waldo takes takes 20/2 cycles, and because the work&#8217;s done<br />
        simultaneously, the final time is also 10c / output.</li>
</ul>
</li>
</ul>
<p><div>&nbsp;</div></p>
<p>
And here are some links that you should probably check out:
</p>
<p><div>&nbsp;</div></p>
<ul>
<li>
    <a href="http://spacechem.net">SolutionNet</a>. For saving and comparing solutions.
  </li>
<li>
    <a<br />
href="http://www.reddit.com/r/spacechem/comments/h6nbd/tips_and_tricks_for_new_players/" target="_blank">reddit: Tips and tricks for new players</a>. For tips and tricks.
  </li>
<li>
    <a href="http://www.reddit.com/r/gaming/comments/o7y6y/how_i_feel_playing_spacechem/">reddit: How I feel playing SpaceChem</a>. For the lulz and shared experience.
  </li>
<li>
    Steam forum: <a href="http://forums.steampowered.com/forums/showthread.php?t=2194268">Revolutionary revelations</a>, <a href="http://forums.steampowered.com/forums/showthread.php?t=2169594">Solutions you&#8217;re proud of</a> and <a href="http://forums.steampowered.com/forums/showthread.php?t=2007279">Terrible Solutions</a>.
  </li>
</ul>
<hr /><div class="footnotes">
<h5>Notes:</h5>
<ol>
<li id="ft-nr1"> 
  Please don&#8217;t copy solutions wholesale, though, that would be cheating &ndash; not just cheating others, but you&#8217;re also cheating yourself: if there&#8217;s one thing everybody agrees on it&#8217;s the intense pride one feels when you finally solve a mission, and you&#8217;d completely miss that. Seriously, looking up solutions to a <i>puzzle</i> game. What the hell?!?
</li>
<li id="ft-nr2"> 
  onto the plates, AHAHAHA *cough*, ahem, sorry about that.
</li>
<li id="ft-nr3"> 
  start-symbols do not count to the final score, but arrows<br />
do.
</li>
</ol>
</div>
<hr />
]]></content:encoded>
			<wfw:commentRss>http://www.coranac.com/2012/04/spacechem-tutorial-fun-with-water/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Wet paint (this is not an instruction)</title>
		<link>http://www.coranac.com/2012/04/wet-paint-this-is-not-an-instruction/</link>
		<comments>http://www.coranac.com/2012/04/wet-paint-this-is-not-an-instruction/#comments</comments>
		<pubDate>Sun, 01 Apr 2012 13:07:46 +0000</pubDate>
		<dc:creator>cearn</dc:creator>
				<category><![CDATA[blag]]></category>

		<guid isPermaLink="false">http://www.coranac.com/?p=247</guid>
		<description><![CDATA[hhhyeah, I guess it&#8217;s time to give this thing a new theme. Had the old style since, what, 2007 and drab gray is out, right? And now that IE6/7 are firmly on the way out, I can do nice CSS &#8230; <a href="http://www.coranac.com/2012/04/wet-paint-this-is-not-an-instruction/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
hhhyeah, I guess it&#8217;s time to give this thing a new theme. Had the old style since, what, 2007 and drab gray is out, right? And now that IE6/7 are firmly on the way out, I can do nice CSS 2/3 effects like rounded borders and shadows and the like. Yay. For better or worse I also added ShareThis buttons, but as they&#8217;re a little heavy on the javascript I might have to remove them from the frontpage later. I&#8217;ll see how it goes.
</p>
<p><div>&nbsp;</div></p>
<p>
I&#8217;m sure there will still be some CSS bugs here and there, but I think I&#8217;ve covered most of them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coranac.com/2012/04/wet-paint-this-is-not-an-instruction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tiny little tonc fix</title>
		<link>http://www.coranac.com/2011/11/tiny-little-tonc-fix/</link>
		<comments>http://www.coranac.com/2011/11/tiny-little-tonc-fix/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 18:37:18 +0000</pubDate>
		<dc:creator>cearn</dc:creator>
				<category><![CDATA[tonc]]></category>

		<guid isPermaLink="false">http://www.coranac.com/?p=227</guid>
		<description><![CDATA[I just noticed that the gfxmake files in tonc&#8217;s advanced examples used an absolute link to grit.exe, which of course won&#8217;t work unless you have my file system. They no use local links now. Should compile right out of the &#8230; <a href="http://www.coranac.com/2011/11/tiny-little-tonc-fix/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
I just noticed that the <code>gfxmake</code> files in tonc&#8217;s advanced examples used an absolute link to <tt>grit.exe</tt>, which of course won&#8217;t work unless you have my file system. They no use local links now. Should compile right out of the box again now.
</p>
<p><div>&nbsp;</div></p>
<p><a href="/files/tonc-code.zip">New tonc-code.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.coranac.com/2011/11/tiny-little-tonc-fix/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Today&#8217;s steam deal : SpaceChem</title>
		<link>http://www.coranac.com/2011/07/steam-deal-spacechem/</link>
		<comments>http://www.coranac.com/2011/07/steam-deal-spacechem/#comments</comments>
		<pubDate>Fri, 01 Jul 2011 18:23:59 +0000</pubDate>
		<dc:creator>cearn</dc:creator>
				<category><![CDATA[spacechem]]></category>

		<guid isPermaLink="false">http://www.coranac.com/?p=222</guid>
		<description><![CDATA[This is just a small head&#8217;s up (I intend to do a larger discussion later) about one of the most awesome and geeky indie-games available at the moment: SpaceChem by Zachatronics Industries. &#160; The basic premise behind SpaceChem is chemical &#8230; <a href="http://www.coranac.com/2011/07/steam-deal-spacechem/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
This is just a small head&#8217;s up (I intend to do a larger discussion later) about one of the most awesome and geeky indie-games available at the moment: <a href="http://store.steampowered.com/app/92800/">SpaceChem</a> by <a href="http://www.zachtronicsindustries.com/">Zachatronics Industries</a>.
</p>
<p><div>&nbsp;</div></p>
<p>
The basic premise behind SpaceChem is chemical engineering: in each assignment, you get some input molecules and you have to turn them into the requested output molecules via bonding and unbonding their atoms, and the occasional nuclear fusion. A simple (and decidedly sub-optimal) example:
</p>
<p><div>&nbsp;</div><iframe width="584" height="329" src="http://www.youtube.com/embed/Gk8JwvtVs38?fs=1&#038;feature=oembed" frameborder="0" allowfullscreen></iframe><div>&nbsp;</div></p>
<p>
The chemistry part is just a front, though. What the game <i>really</i> is, is a programming simulator. You have a tiny board (10&times;8) board with input and output zones and two &#8216;waldos&#8217; that trace a path on which you place and execute instructions: basically a tiny dual-threaded CPU with a select instruction set. I know it sounds simple, and that&#8217;s exactly right: it <i>sounds</i> simple. However, working out a workable design hard, VERY hard. Especially when you try to optimize a design for least time or components.
</p>
<p>
There are in-game leaderboards, showing you how much a design that you have toiled away at for hours actually sucks sweaty donkey balls, and a more detailed scoreboard at <a href="http://spacechem.net/">spacechem.net</a>. You can also upload your solutions to youtube. Here&#8217;s one of mine for &ldquo;Gas Works Park&rdquo;, where you turn some random carbon strings (C<sub>3</sub> / C<sub>4</sub>) and water (H<sub>2</sub>O) and turn them into methane (CH<sub>4</sub>) and carbondioxide (CO<sub>2</sub>). Solution details can be found in the video description.
</p>
<p><div>&nbsp;</div><iframe width="584" height="329" src="http://www.youtube.com/embed/dTVM_1sJq5o?fs=1&#038;feature=oembed" frameborder="0" allowfullscreen></iframe><div>&nbsp;</div></p>
<ul>
<li>
Publisher site (with other engineering games): <a href="http://www.zachtronicsindustries.com/">Zachatronics Industries</a>
  </li>
<li>
Game site: <a href="http://www.spacechemthegame.com/">http://www.spacechemthegame.com/</a>
  </li>
<li>
Review: <a href="http://www.rockpapershotgun.com/2011/01/10/wot-i-think-spacechem">http://www.rockpapershotgun.com/2011/01/10/wot-i-think-spacechem</a>
  </li>
</ul>
<p><div>&nbsp;</div></p>
<p>
If you like programming and games (which probably describes readers here pretty well), you need to give this a try.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coranac.com/2011/07/steam-deal-spacechem/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Netherlands &#8211; FUCK YEAH!</title>
		<link>http://www.coranac.com/2010/07/the-netherlands-fuck-yeah/</link>
		<comments>http://www.coranac.com/2010/07/the-netherlands-fuck-yeah/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 21:30:30 +0000</pubDate>
		<dc:creator>cearn</dc:creator>
				<category><![CDATA[tainment]]></category>

		<guid isPermaLink="false">http://www.coranac.com/?p=214</guid>
		<description><![CDATA[Normally, I don&#8217;t really do this kind of stuff, but &#8230; Finals!!! woooOOOOOOOOOOOOOOOOOOOooo!!! &#160; Holy crap, that was a tight game. First a beautiful goal by van Bronckhorst. Then the equalizer by Forl&#225;n just before the break. Then a hideous &#8230; <a href="http://www.coranac.com/2010/07/the-netherlands-fuck-yeah/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
Normally, I don&#8217;t really do this kind of stuff, but &hellip;
</p>
<p><center></p>
<p><span style="font-size:200%;"><br />
<b>Finals!!!</b><br />
<b>woooOOO<span style="font-size:150%;">OOO<span style="font-size:150%;">OOOOOOO</span>OOO</span>OOOooo!!!</b><br />
</span>
</p>
<p></center><div>&nbsp;</div></p>
<p><center><br />
<div  class="cptc" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"></span>
</div>
<br />
</center></p>
<p>
Holy crap, that was a tight game. First a beautiful goal by van Bronckhorst. Then the equalizer by Forl&aacute;n just before the break. Then a hideous goal by not-Sneijder, but he gets the point anyway, quickly followed by Robben&#8217;s header. And then <i>in overtime</i> they still almost manage to blow it when Pereira makes it 2&ndash;3 and then drama in the rest of the overtime! OMFGWTFBBQ!!111!!ELEVENTYONE!!!
</p>
<p><div>&nbsp;</div></p>
<p>
Netherlands &ndash; Germany finals incoming!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coranac.com/2010/07/the-netherlands-fuck-yeah/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Portal is free :D</title>
		<link>http://www.coranac.com/2010/05/portal-is-free/</link>
		<comments>http://www.coranac.com/2010/05/portal-is-free/#comments</comments>
		<pubDate>Thu, 13 May 2010 10:24:27 +0000</pubDate>
		<dc:creator>cearn</dc:creator>
				<category><![CDATA[tainment]]></category>

		<guid isPermaLink="false">http://www.coranac.com/?p=206</guid>
		<description><![CDATA[It seems that Valve is &#8216;selling&#8217; the absolutely awesome Portal for zero dollars until May 24th. If you don&#8217;t have it yet, this would be a good time to get it. &#160; Linky: http://store.steampowered.com/freeportal/]]></description>
			<content:encoded><![CDATA[<p>
It seems that Valve is &#8216;selling&#8217; the absolutely awesome Portal for zero dollars until May 24th. If you don&#8217;t have it yet, this would be a good time to get it.
</p>
<p><div>&nbsp;</div></p>
<p>Linky:
</p>
<p>
<a href="http://store.steampowered.com/freeportal/">http://store.steampowered.com/freeportal/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.coranac.com/2010/05/portal-is-free/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Probabilities in simple random samples</title>
		<link>http://www.coranac.com/2010/05/probabilities-in-simple-random-samples/</link>
		<comments>http://www.coranac.com/2010/05/probabilities-in-simple-random-samples/#comments</comments>
		<pubDate>Wed, 05 May 2010 17:41:51 +0000</pubDate>
		<dc:creator>cearn</dc:creator>
				<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://www.coranac.com/?p=200</guid>
		<description><![CDATA[1 Introduction 2 Probability and its rules 3 Combinatorics : counting evolved 4 Examples 5 Summary 1 Introduction When it comes to math, one of the things that people are phenomenally bad at &#8211; aside from the obvious everything &#8211; &#8230; <a href="http://www.coranac.com/2010/05/probabilities-in-simple-random-samples/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p></p>
<p><ul>
  <li> <a href="#sec-intro">1
Introduction
</a> </li>
  <li> <a href="#sec-prob">2
Probability and its rules
</a> </li>
  <li> <a href="#sec-cmb">3
Combinatorics : counting evolved
</a> </li>
  <li> <a href="#sec-eg">4
Examples
</a> </li>
  <li> <a href="#sec-summary">5
Summary
</a> </li>
</ul>
</p>
<p><h2 id="sec-intro">1
Introduction
</h2>
</p>
<p>
When it comes to math, one of the things that people are phenomenally<br />
bad at &ndash; aside from the obvious everything &ndash; is<br />
probabilities. Specifically, <i>calculating</i> probabilities.<br />
People are bad enough at<br />
estimating chances, but properly calculating then has its own<br />
hurdles.
</p>
<p>
In this particular case, I&#8217;d like to take a look at the probability of<br />
a 
<a href="http://en.wikipedia.org/wiki/Simple%20random%20sample">Simple random sample</a>: getting a particular distribution<br />
of results from a number of samples, like getting 3 sixes in a<br />
certain number of rolls. Specifically, I&#8217;ll look at the case<br />
<b>with replacement</b>. In this case, the sample pool remains the same<br />
after each individual sample. The case <b>without replacement</b><br />
(like picking colored marbles from a vase without putting them back)<br />
is a bit trickier so I won&#8217;t cover that now.
</p>
<p><span id="more-200"></span></p>
<h4 id="sssec-binom">The binomial distribution</h4>
<p>
One of the equations that is relevant here is the<br />

<a href="http://en.wikipedia.org/wiki/binomial%20distribution">binomial distribution</a><br />
(see Eq&nbsp;1), the scourge of math students<br />
everywhere. What I&#8217;d like to do is explain why it looks the way it does,<br />
what the terms mean and how you can generalize it to cover more than<br />
two outcomes (that&#8217;s what the &ldquo;bi-&rdquo; stands for: two).<br />
Basically, I&#8217;d like to show you how to &ldquo;read&rdquo; the equation<br />
and to interpret the terms in it, which will make it easier to deal<br />
with the subject.
</p>
<p><table class="eqtbl" id="eq-binom-std">
<tr>
<td class="eqnrcell">(1)</td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?P%28W%3Dk%29%20%3D%20%7Bn%5Cchoose%20k%7D%20p%5Ek%20%281-p%29%5E%7Bn-k%7D'<br />
	title="P(W=k) = {n\choose k} p^k (1-p)^{n-k}"<br />
	alt="P(W=k) = {n\choose k} p^k (1-p)^{n-k}" /><br />
</td>
</tr>
</table></p>
<p>
First, a few words about the Eq&nbsp;1 itself. Say you have<br />
a random event that can have two outcomes: coin-flip, true/false question,<br />
but also a die-roll if you just look at an X vs non-X result. Or, in<br />
the parlance of our times, whether you have a win (<b>W</b>) or a<br />
fail (<b>F</b>). What Eq&nbsp;1 gives you is the probability<br />
of getting exactly <i>k</i> wins in <i>n</i> trials.
</p>
<p><div>&nbsp;</div></p>
<p>
That&#8217;s all well and good, of course, but unless you actually understand<br />
how the equation is built up and what all the terms in it mean, it&#8217;ll<br />
just be yet another magic formula that someone dreamed up to torture you<br />
with. In practical terms, it also means that it&#8217;s harder to apply it<br />
correctly. So let&#8217;s look at what it means, starting with what each<br />
individual symbol means.
</p>
<div class=cblock>
<table id="tbl-binom" class="cblock"<br />
	border=1 cellpadding=2 cellspacing=0><br />
<caption>
  <b>Table&nbsp;1</b>: Explanation of symbols in<br />
  Eq&nbsp;1.<br />
</caption>
<tr>
<th>Symbol</th>
<th>Meaning</th>
</tr>
<tr>
<th>W</th>
<td>Win index, or number of wins.</td>
</tr>
<tr>
<th>F</th>
<td>Fail index, or number of fails.</td>
</tr>
<tr>
<th>n</th>
<td>Number of trials.</td>
</tr>
<tr>
<th>k</th>
<td>Selection value (usually linked to the number of<br />
	wins).</td>
</tr>
<tr>
<th>p</th>
<td>Single-trial probability (usually linked to<br />
	wins).</td>
</tr>
<tr>
<th>P(<i>cond</i>)</th>
<td>Total probability, with the condition.</td>
</tr>
</table>
</div>
<p><!--<br />
<div class="note" id="id-binom-std">
<div  class="nhcare">Equation imprecise</div>

</p>
<p>
I should probably mention that while Eq&nbsp;1 is<br />
correct, it is imprecise.
</p>
<p>
</div>
<br />
&#8211;></p>
<p>
Here&#8217;s an example of its use. Say you have 7 dice (7d6) and you want to<br />
know the probability of throwing 3 sixes. This means you have<br />
<i>n</i>&nbsp;=&nbsp;7, <i>k</i>&nbsp;=&nbsp;3 and <i>p</i>&nbsp;=&nbsp;1/6, and the condition is<br />
<i>W</i>&nbsp;=&nbsp;<i>k</i>&nbsp;=&nbsp;3.
</p>
<h4>Divide and conquer</h4>
<p>
The next step is to split the equation into the two parts that are<br />
of true relevance, namely:
</p>
<p><div id="img-binom-div" class="cptfr" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"><b>Fig&nbsp;1. </b></span>
</div>
</p>
<ol>
<li>
    The base chance of getting a specific result that satisfies your<br />
	conditions.
  </li>
<li>
    The number of results that satisfies the conditions (each with the<br />
	same base probability).
  </li>
</ol>
<p>
I&#8217;ve always found this division to make the most sense. Note that I&#8217;ve<br />
split it into two parts, not three. The terms involving <i>p</i> and<br />
(1&minus;<i>p</i>) belong in the same group, as I&#8217;ll explain later. The<br />
nice thing about this division is that the two parts neatly correspond<br />
to two concepts of mathematics: probability and combinatorics. If you<br />
understand those two, equations like Eq&nbsp;1 should<br />
start to make sense.
</p>
<div class="lblock">
</div>
<p><h2 id="sec-prob">2
Probability and its rules
</h2>
</p>
<p>
When I say you need to understand probability theory to understand<br />
the binomial distribution, what I really mean is that you understand<br />
the <i>rules</i> or probability, and how to combine single chance<br />
occurrences into larger conditions. See also<br />

<a href="http://en.wikipedia.org/wiki/Probability%23Mathematical_treatment">wiki:probability</a>.
</p>
<p><h3 id="ssec-prob-def">2.1
Probability definition
</h3>
</p>
<p>
The probability of a selected case <i>x</i> is the number of times it<br />
occurs relative to the total pool of cases. This is the fraction given in<br />
Eq&nbsp;2. All other rules are the result of this one.
</p>
<p><table class="eqtbl" id="eq-prob-def">
<tr>
<td class="eqnrcell">(2)</td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?P%28X%29%20%3D%20%7B%7B%23%20%5Ctext%7BSelected%20case%7D%7D%20%5Cover%20%7B%20%23%20%5Ctext%7BTotal%20cases%7D%7D%7D'<br />
	title="P(X) = {{# \text{Selected case}} \over { # \text{Total cases}}}"<br />
	alt="P(X) = {{# \text{Selected case}} \over { # \text{Total cases}}}" /><br />
</td>
</tr>
</table></p>
<p>
For example, we roll a d6 and we&#8217;re interested in getting a six.<br />
Since there are 6 sides and only 1 six, the probability is<br />
<i>P</i>(<i>1&nbsp;six</i>)&nbsp;=&nbsp;1/6.
</p>
<p><h3 id="ssec-prob-range">2.2
Probability range
</h3>
</p>
<p>
Since the total number of items is <i>at least</i> as large as the<br />
selection, each probability itself is at most 1. A probability can&#8217;t be<br />
lower than zero either, because counts are natural numbers.
</p>
<p>
This also holds for the sum probability of multiple items. Also, the<br />
probability to get any result at all is 1, because obviously something<br />
needs to happen. If you sum up probabilities and you get an answer<br />
greater than 1, some of the cases you&#8217;ve counted actually overlap. If<br />
you add up all probabilities and you get less than 1, you&#8217;ve missed<br />
a few cases.
</p>
<p><table class="eqtbl" id="eq-prob-range">
<tr>
<td class="eqnrcell">(3)</td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?0%20%5Cle%20P%28X%29%20%5Cle%201'<br />
	title="0 \le P(X) \le 1"<br />
	alt="0 \le P(X) \le 1" /><br />
</td>
</tr>
</table></p>
<p><h3 id="ssec-prob-not">2.3
Complementary rule : NOT
</h3>
</p>
<p>
If the probability of some event is <i>P</i>(<i>X</i>) and the sum<br />
probability of all events, then the<br />
probability of it <b>not</b> happening is 1&minus;<i>P</i>(<i>X</i>). The<br />
symbol for &ldquo;not&rdquo; is &not;.
</p>
<p><table class="eqtbl" id="eq-prob-not">
<tr>
<td class="eqnrcell">(4)</td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?P%28%5Ctext%7Bnot%7D%5C%2CX%29%20%3D%20P%28%5Cneg%20X%29%20%3D%201%20-%20P%28X%29'<br />
	title="P(\text{not}\,X) = P(\neg X) = 1 - P(X)"<br />
	alt="P(\text{not}\,X) = P(\neg X) = 1 - P(X)" /><br />
</td>
</tr>
</table></p>
<p>
For example, if the probability of a six on a d6 is 1/6, the<br />
probability of <i>not</i> getting a six is <i>P</i>(~<i>six</i>)&nbsp;=&nbsp;5/6.
</p>
<p><h3 id="ssec-prob-xor">2.4
Disjoint conditions : XOR
</h3>
</p>
<p>
If you have multiple conditions that are <b>mutually exclusive</b><br />
(disjoint), the probabilities add. This corresponds to an &ldquo;or&rdquo;<br />
case.
</p>
<p>
Please note the &ldquo;mutually&rdquo; here. It must be <i>either</i><br />
<i>X</i> <i>or</i> <i>Y</i>. For the programmers: the English word<br />
&ldquo;or&rdquo; actually mean an exclusive OR ( ^ in C), not an<br />
inclusive OR ( | ). This difference is the main reason why calculated<br />
probabilities can end up greater than 1. There are several symbols<br />
that can be used for a disjoint condition, all of which are problematic.<br />
I&#8217;ll use the boolean XOR symbol,  &oplus;, because even though it may<br />
be a little obscure for most people, at least it&#8217;s non-ambiguous.
</p>
<p><table class="eqtbl" id="eq-prob-or">
<tr>
<td class="eqnrcell">(5)</td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?P%28X%5Ctext%7B%20or%20%7DY%29%20%3D%20P%28X%20%5Coplus%20Y%29%20%3D%20P%28X%29%20%2B%20P%28Y%29'<br />
	title="P(X\text{ or }Y) = P(X \oplus Y) = P(X) + P(Y)"<br />
	alt="P(X\text{ or }Y) = P(X \oplus Y) = P(X) + P(Y)" /><br />
</td>
</tr>
</table></p>
<p>
For example, the chance of getting a 6 <b>or</b> a 5 on a single d6.<br />
is <i>P</i>(<i>six</i> or <i>5</i>)&nbsp;=&nbsp;1/6&nbsp;+&nbsp;1/6&nbsp;=&nbsp;1/3. You can also<br />
approach it from the definition of Eq&nbsp;2, where<br />
you still have a total of 6, but now you have 2 valid cases, leading<br />
directly to 2/6.
</p>
<p><div class="note" id="nt-xor">
<div  class="nhcare">Language issues and silly symbols</div>

</p>
<p>
The term &#8220;or&#8221; is one of those areas where human languages, mathematics<br />
and logic are at odds. As said, the word &ldquo;or&rdquo; actually<br />
means an exclusive or (one of the two, but not both), even though in math<br />
and logic it&#8217;s used for the union (the full combination; and/or).
</p>
<p>
It gets even more vexing when one looks at the symbols used. The C<br />
equivalent for OR (the inclusive OR) is <code>|</code> or<br />
<code>||</code>. However, the <code>|</code> symbol is also used for<br />
a 
<a href="http://en.wikipedia.org/wiki/conditional%20probability">conditional probability</a>. So that&#8217;s out. I can&#8217;t use the<br />
C XOR symbol, <code>^</code>either, as that actually means AND in logic.<br />
There&#8217;s also the union symbol, <code>&cup;</code>, but I think that<br />
stands for <i>in</i>clusive OR, not exclusive. So in the end it comes<br />
down to the O-plus, &oplus;. While relatively unknown, at least it<br />
only has a single meaning.
</p>
<p>
If anyone has a better idea, I&#8217;d love to hear it.
</p>
<p>
</div>
</p>
<p><h3 id="ssec-prob-and">2.5
Joint conditions : AND
</h3>
</p>
<p>
When you have two independent conditions that both need to be true,<br />
the probabilities multiply. Think of it as a sub-selection, where you<br />
have to get a fraction of a fraction. This corresponds to an<br />
&ldquo;and&rdquo; case. The logical symbol for it is a cap ( &cap; ),<br />
but since it looks too much like a cup, I&#8217;ll use the actual AND-symbol<br />
( &amp; ).
</p>
<p><table class="eqtbl" id="eq-prob-and">
<tr>
<td class="eqnrcell">(6)</td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?P%28X%5Ctext%7B%20and%20%7DY%29%20%3D%20P%28X%20%5C%26%20Y%29%20%3D%20P%28X%29%20%5Ccdot%20P%28Y%29'<br />
	title="P(X\text{ and }Y) = P(X \&amp; Y) = P(X) \cdot P(Y)"<br />
	alt="P(X\text{ and }Y) = P(X \&amp; Y) = P(X) \cdot P(Y)" /><br />
</td>
</tr>
</table></p>
<p>
An example of this rule is the chance to throw two sixes with two dice.<br />
First, you need to throw a six with one for a 1/6 chance, and in the<br />
event that that happens, there&#8217;s another 1/6 chance for the other,<br />
combining into<br />
<i>P</i>(<i>six</i> and <i>six</i>)&nbsp;=&nbsp;1/6&nbsp;&middot;&nbsp;1/6&nbsp;=&nbsp;1/36. You<br />
can also get this result from the definition. With 2 dice you have 36<br />
possibilities in total, and only one of them will contain (6,6). Note<br />
that for a 5 and 6 the rules are different, since both (5,6) and (6,5)<br />
are possible here.
</p>
<p><h3 id="ssec-prob-use">2.6
Usage in general and binomials in particular
</h3>
</p>
<p>
When considering probabilities, you&#8217;ll often have multiple<br />
trials/samples and a diffent type of answer for each trial. For example,<br />
say you have three different options, <i>a</i>, <i>b</i> and <i>c</i>.<br />
Each option has a different probability,<br />
<i>p</i><sub>a</sub>, <i>p</i><sub>b</sub>, and <i>p</i><sub>c</sub>.<br />
Now I&#8217;m looking for the probability of getting 2 <i>a</i>, 3 <i>b</i>s<br />
and 4 <i>c</i>s. In other words, the number of results for each<br />
possibility is <i>k</i><sub>a</sub>&nbsp;=&nbsp;2,<br />
<i>k</i><sub>b</sub>&nbsp;=&nbsp;3 and <i>k</i><sub>c</sub>&nbsp;=&nbsp;4, for a total<br />
number of trials<br />
<i>n</i>&nbsp;=&nbsp;&Sigma;<sub>i</sub>&nbsp;<i>k</i><sub>i</sub>&nbsp;=&nbsp;10. Now look<br />
at one possible result that satisfies the condition, say,<br />
&#8220;aabbbcccc&#8221;. This is an AND case, so probabilities multiply. Each<br />
trial result gets the probability belonging to that answer, which<br />
in this case leads to
</p>
<p><table class="eqtbl">
<tr>
<td class="eqnrcell"></td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?P%28%5Ctext%7Bexactly%20%7D%20aabbbcccc%29%20%3D%20p_a%5E2%5C%2Cp_b%5E3%5C%2Cp_c%5E4.'<br />
	title="P(\text{exactly } aabbbcccc) = p_a^2\,p_b^3\,p_c^4."<br />
	alt="P(\text{exactly } aabbbcccc) = p_a^2\,p_b^3\,p_c^4." /><br />
</td>
</tr>
</table></p>
<p>
The generalized case for this has <i>m</i> classes, labelled<br />
<i>X</i><sub>j</sub>, and we&#8217;re the number of outcomes we&#8217;re looking<br />
for for each class is <i>n</i><i>j</i>. The probability for a<br />
<i>single</i> result that satisfies this condition is<br />
Eq&nbsp;7. It may look a little hairy, but all it<br />
really says is that you should multiply the probability of each of the<br />
result in the condition.
</p>
<p><table class="eqtbl" id="eq-prob-single">
<tr>
<td class="eqnrcell">(7)</td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?P%28k_1%20X_1%5C%2C%5C%26%5C%2Ck_2%20X_2%5C%2C%5C%26%20...%20%5C%26%5C%2Ck_m%20X_m%29%20%3D%20p_1%5E%7Bk_1%7D%20%5C%2C%5Ctimes%5C%2C%20p_2%5E%7Bk_2%7D%20%5C%2C%5Ctimes%5C%2C%20...%20%5C%2C%5Ctimes%5C%2C%20p_m%5E%7Bk_m%7D%20%3D%20%5Cprod_%7Bj%3D1%7D%5Em%20p_j%5E%7Bk_j%7D'<br />
	title="P(k_1 X_1\,\&amp;\,k_2 X_2\,\&amp; ... \&amp;\,k_m X_m) = p_1^{k_1} \,\times\, p_2^{k_2} \,\times\, ... \,\times\, p_m^{k_m} = \prod_{j=1}^m p_j^{k_j}"<br />
	alt="P(k_1 X_1\,\&amp;\,k_2 X_2\,\&amp; ... \&amp;\,k_m X_m) = p_1^{k_1} \,\times\, p_2^{k_2} \,\times\, ... \,\times\, p_m^{k_m} = \prod_{j=1}^m p_j^{k_j}" /><br />
</td>
</tr>
</table></p>
<p>
Now, look back at the binomial probability. In that case, you have two<br />
options, <b>W</b>in and <b>F</b>ail, with probabilities<br />
<i>p</i><sub>w</sub> and <i>p</i><i>f</i>, respectively. Let&#8217;s look at<br />
the case for <i>k</i> wins. That is<br />
<i>W</i>&nbsp;=&nbsp;<i>k</i><sub>w</sub>&nbsp;=&nbsp;<i>k</i>. Now, because there are only<br />
two options (that&#8217;s the &ldquo;bi-&rdquo; in binomial), the<br />
probabilities of the fail-case are now also set. The probability for<br />
failing is <i>p</i><sub>f</sub>&nbsp;=&nbsp;<i>p</i><sub>&not;w</sub>&nbsp;=&nbsp;1&minus;<i>p</i><sub>w</sub>.<br />
As for the number of failed cases, remember that the binomial looks<br />
for <i>exactly</i> <i>k</i> wins, meaning the rest of the cases fail,<br />
leading to <i>k</i><sub>f</sub>&nbsp;=&nbsp;<i>n</i>&minus;<i>k</i>. This little<br />
fact is never mentioned explicitly, but it shouldn&#8217;t be overlooked.
</p>
<p>
In the end, what you<br />
get is Eq&nbsp;8. The only difference with the<br />
actual binomial equation is that the subscript has been removed in the<br />
latter. Never underestimate the mathematician&#8217;s laziness when it comes<br />
to writing stuff down.
</p>
<p><table class="eqtbl" id="eq-prob-binom-single">
<tr>
<td class="eqnrcell">(8)</td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?P%28W%3Dk_w%5C%2C%5C%26%5C%2C%20F%3Dk_f%29%20%3D%20p_w%5E%7Bk_w%7D%5C%2Cp_f%5E%7Bk_f%7D%20%3D%20p_w%5Ek%5C%2C%281-p_w%29%5E%7Bn-k%7D'<br />
	title="P(W=k_w\,\&amp;\, F=k_f) = p_w^{k_w}\,p_f^{k_f} = p_w^k\,(1-p_w)^{n-k}"<br />
	alt="P(W=k_w\,\&amp;\, F=k_f) = p_w^{k_w}\,p_f^{k_f} = p_w^k\,(1-p_w)^{n-k}" /><br />
</td>
</tr>
</table></p>
<p>
There&#8217;s still one thing missing though: both<br />
Eq&nbsp;7 and Eq&nbsp;8<br />
only cover the possibility of one <i>specific</i> valid result. In<br />
most cases, there will be others as well. In the <i>a</i>,<i>b</i>,<i>c</i><br />
case, for example, I only looked at &#8220;aabbbcccc&#8221;, but &#8220;bbbaacccc&#8221;,<br />
&#8220;abcabcbcc&#8221;, or &#8220;cccbbaaa&#8221; would have worked as well, as would any<br />
other combination. You need take all of these into account, but for<br />
that you need a way to quickly find all variations first. And that&#8217;s<br />
the topic of the next section: combinatorics.
</p>
<p><h2 id="sec-cmb">3
Combinatorics : counting evolved
</h2>
</p>
<p>
Very briefly, 
<a href="http://en.wikipedia.org/wiki/combinatorics">combinatorics</a> is the study of counting<br />
discrete variations. In particular, how you can <b>quickly</b> count<br />
them all in an orderly and correct fashion.<br />
In this case, what I&#8217;ll need is a way to quickly count the different<br />
possible ways of distributing items over a number of bins. What also<br />
matters is whether the items are <b>unique</b> (that is to say, whether<br />
you can tell them apart from other items) or <b>non-unique</b>.
</p>
<p>
I&#8217;ll start with unique items and then show how to incorporate<br />
non-unique ones. This will involve factorials (<i>n</i>!). Along the<br />
way, we&#8217;ll pick up permutations (<i>n</i>P<i>r</i>) and<br />
combinations (<i>n</i>C<i>r</i>), which are merely special cases of the<br />
general formula.
</p>
<p><h3 id="ssec-cmb-unique">3.1
Arrangements with unique items
</h3>
</p>
<p>
The specific task here is to find out in how many ways you can<br />
distribute <i>n</i> unique objects over <i>n</i> different slots. This<br />
is a case of combinatorics <dfn>without replacement</dfn>, because once<br />
you&#8217;ve placed an object in a particular slot, you can&#8217;t use it anywhere<br />
else.
</p>
<p>
I&#8217;ll start by looking at an example with four objects,<br />
<i>a</i>, <i>b</i>, <i>c</i> and <i>d</i>. Naturally, there will also<br />
be four slots to put them in. To count the possibilities, we&#8217;ll make<br />
a tree (see Fig&nbsp;2). There are two ways to fill the<br />
tree: by a slot or by item. When working without replacement, it&#8217;s more<br />
convenient to fill by item. Right now it won&#8217;t matter that much,<br />
because when you start dealing with groups of non-unique items, it has<br />
a nice way of grouping all of those on the same depth.
</p>
<div class="cblock">
<div id="img-tree-abcd" class="cptc" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"><b>Fig&nbsp;2. </b></span>
</div>

</div>
<p>
As you can see in Fig&nbsp;2, we start with four open<br />
slots and four items. First we place <i>a</i>, which has a choice of<br />
all four slots. For <i>b</i>, only three slots are left open; <i>c</i><br />
has only 2 and <i>d</i> takes the last remaining slot. The point here<br />
is that each next item has one fewer slot. The last column has all the<br />
different arrangements, and as you can see there are 24 in total.<br />
The really important point, though, is to note that all the branches<br />
for a given level has the same number of sub-branches. This means that<br />
you can simply multiply the number of slots left, leading to<br />
4&middot;3&middot;2&middot;1. In other words, it&#8217;s simply the<br />
factorial: 4!.
</p>
<p>
Generalizing this, given <i>n</i> unique items, the number of variations<br />
is <i>n</i>!.
</p>
<p><h3 id="ssec-cmb-non-unique">3.2
Arrangements with non-unique items
</h3>
</p>
<p>
Now lets look at what happens when there are also identical-looking<br />
items. For example, lets take one <i>a</i>, one <i>b</i> and<br />
<b>three</b> <i>c</i>s, for a total of five items<br />
(see Fig&nbsp;3). Technically, for<br />
five items you&#8217;d get 5! variations, however because the <i>c</i>s are<br />
identical some solutions are actually the same: we&#8217;ve overcounted.<br />
To resolve this, we need to know how many variations are actually the<br />
same. This is simply the number of variations within the<br />
<i>c</i>-group. With 3 <i>c</i>s, that means 3!. So to get the final<br />
answer, we divide by 3!.
</p>
<div class="cblock">
<div id="img-tree-abccc" class="cptc" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"><b>Fig&nbsp;3. </b></span>
</div>
</p>
<p>
This is becoming similar to the case in section 2.6.<br />
Again, take the case that you have <i>m</i> groups,<br />
<i>k</i><sub>j</sub> identical items per group, and<br />
<i>n</i>&nbsp;=&nbsp;&Sigma;<sub>j</sub>&nbsp;<i>k</i><sub>j</sub> items in total.<br />
If all items were unique, you&#8217;d get <i>n</i>! variations, but in each<br />
group you&#8217;re counting <i>k</i><sub>j</sub>! times too many. The proper<br />
number is <i>n</i>! divided by all the overcounts. This term is called<br />
the <dfn>
<a href="http://en.wikipedia.org/wiki/Multinomial_theorem">multinomial coefficient</a></dfn>,<br />
and defined as:
</p>
<p><table class="eqtbl" id="eq-cmb-mnom">
<tr>
<td class="eqnrcell">(9)</td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?A%28k_1%20X_1%2C%20...%2C%20k_m%20X_m%29%20%3D%20%7B%20n%20%5Cchoose%20k_1%2C%5C%2C...%2C%5C%2Ck_m%20%7D%20%3D%20%7B%20%7B%20%5C%28k_1%20%2B%20...%20%2B%20k_m%5C%29%21%20%7D%20%5Cover%20%7B%20k_1%21%20%5C%2C%5Ccdot%5C%2C%20...%20%5C%2C%5Ccdot%5C%2C%20k_m%21%20%7D%20%7D%20%3D%20%7B%20%7Bn%21%7D%20%5Cover%20%7B%20%5Cprod_%7Bj%3D1%7D%5Em%5C%2C%20k_j%21%7D%20%7D'<br />
	title="A(k_1 X_1, ..., k_m X_m) = { n \choose k_1,\,...,\,k_m } = { { \(k_1 + ... + k_m\)! } \over { k_1! \,\cdot\, ... \,\cdot\, k_m! } } = { {n!} \over { \prod_{j=1}^m\, k_j!} }"<br />
	alt="A(k_1 X_1, ..., k_m X_m) = { n \choose k_1,\,...,\,k_m } = { { \(k_1 + ... + k_m\)! } \over { k_1! \,\cdot\, ... \,\cdot\, k_m! } } = { {n!} \over { \prod_{j=1}^m\, k_j!} }" /><br />
</td>
</tr>
</table></p>
<p>
As an extra example of this, consider again the case with 2 <i>a</i>s,<br />
3 <i>b</i>s and 4 <i>c</i>s. That is, <i>k</i><sub>a</sub>&nbsp;=&nbsp;2,<br />
<i>k</i><sub>b</sub>&nbsp;=&nbsp;3 and <i>k</i><sub>c</sub>&nbsp;=&nbsp;4, and<br />
<i>n</i>&nbsp;=&nbsp;9. The number of arrangements is<br />
n! / (<i>k</i><sub>a</sub>! <i>k</i><sub>b</sub>!<br />
<i>k</i><sub>c</sub>!)&nbsp;=&nbsp; 9!/(2! 3! 4!) = 1260.
</p>
<p><div>&nbsp;</div></p>
<p>
There&#8217;s also a neat little way of describing this graphically, via a<br />
table (see Table&nbsp;2). First, you take the most regular<br />
answer, where everything&#8217;s divided into groups, like<br />
<i>aabbbcccc</i>. Write the indices above each term, ultimately<br />
resulting in <i>n</i>!. Now break up the string into groups index<br />
each group, giving you  all the <i>k</i><sub>j</sub>! terms. The<br />
result is dividing the full indexed part with the group-parts.
</p>
<div class="lblock">
<table id="tbl-mnom"<br />
  border=0 cellpadding=2 cellspacing=0><br />
<caption>
  <b>Table&nbsp;2</b>. Multinomial expressed in tabular form.<br />
</caption>
<tr>
<td>
<table border=0 cellpadding=2 cellspacing=0>
<tr>
<td class="bdrL">9</td>
<td>8</td>
<td>7</td>
<td>6</td>
<td>5</td>
<td>4</td>
<td>3</td>
<td>2</td>
<td class="bdrR">1</td>
</tr>
<tr class="bdrT bdrB">
<th class="bdrL">a</th>
<th class="bdrR">a</th>
<th>b</th>
<th>b</th>
<th class="bdrR">b</th>
<th>c</th>
<th>c</th>
<th>c</th>
<th class="bdrR">c</th>
</tr>
<tr>
<td class="bdrL">2</td>
<td class="bdrR">1</td>
<td>3</td>
<td>2</td>
<td class="bdrR">1</td>
<td>4</td>
<td>3</td>
<td>2</td>
<td class="bdrR">1</td>
</tr>
</table>
</td>
<td>
<p><img src='http://www.coranac.com/cgi-bin/mimetex.cgi?%5C%3B%5C%3B%5CRightarrow%5C%3B%5C%3B%7B%209%21%20%5Cover%202%21%203%21%204%21%7D'<br />
	title="\;\;\Rightarrow\;\;{ 9! \over 2! 3! 4!}"<br />
	alt="\;\;\Rightarrow\;\;{ 9! \over 2! 3! 4!}" /></p>
</td>
</tr>
</table>
</div>
<p><h3 id="ssec-cmb-pc">3.3
Permutations and combinations
</h3>
</p>
<p>
Permutations and combinations are merely special cases of<br />
Eq&nbsp;9. This is not how it&#8217;s generally taught, but<br />
it&#8217;s still true. In  <dfn>permutation</dfn>, you have <i>r</i> <b>unique</b><br />
items and <i>n</i> slots. In other words, you have <i>n</i>&minus;<i>r</i><br />
identical, empty slots. You only have an overcount for the empty<br />
slots, so you end up with
</p>
<p><table class="eqtbl" id="eq-cmb-perm">
<tr>
<td class="eqnrcell">(10)</td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?%5EnP_r%20%3D%20%7B%20%7B%20n%21%7D%20%5Cover%20%7B%20%5Cunderbrace%7B1%21...1%21%7D_%7Br%5C%2C%5Ctext%7Btimes%7D%7D%20%28n-r%29%21%20%7D%20%7D%20%3D%20%7B%20%7B%20n%21%7D%20%5Cover%20%7B%28n-r%29%21%20%7D%20%7D.'<br />
	title="^nP_r = { { n!} \over { \underbrace{1!...1!}_{r\,\text{times}} (n-r)! } } = { { n!} \over {(n-r)! } }."<br />
	alt="^nP_r = { { n!} \over { \underbrace{1!...1!}_{r\,\text{times}} (n-r)! } } = { { n!} \over {(n-r)! } }." /><br />
</td>
</tr>
</table></p>
<p>
This also has another name: the <dfn>
<a href="http://en.wikipedia.org/wiki/falling%20factorial">falling factorial</a></dfn>,<br />
written as <i>n</i><sub>(r)</sub>. It&#8217;s called that because it&#8217;s<br />
basically the top <i>r</i> terms of a factorial. For example,<br />
<sup>7</sup>P<sub>3</sub> = 7<sub>(3)</sub> = 7&middot;6&middot;5.<br />
It&#8217;s written out in the equation below. Notice how the lower terms<br />
cancel out.
</p>
<p><table class="eqtbl">
<tr>
<td class="eqnrcell"></td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?%5E7P_3%20%3D%20%5Cfrac%7B7%21%7D%7B%287-3%29%21%7D%20%3D%20%5Cfrac%7B7%21%7D%7B4%21%7D%20%3D%20%5Cfrac%7B7%20%5Ccdot%206%20%5Ccdot%205%20%5Ccdot%7D%7B%5C%2C%7D%20%5Cfrac%7B4%20%5Ccdot%203%20%5Ccdot%202%20%5Ccdot%201%7D%7B4%20%5Ccdot%203%20%5Ccdot%202%20%5Ccdot%201%7D%3D%207%20%5Ccdot%206%20%5Ccdot%205'<br />
	title="^7P_3 = \frac{7!}{(7-3)!} = \frac{7!}{4!} = \frac{7 \cdot 6 \cdot 5 \cdot}{\,} \frac{4 \cdot 3 \cdot 2 \cdot 1}{4 \cdot 3 \cdot 2 \cdot 1}= 7 \cdot 6 \cdot 5"<br />
	alt="^7P_3 = \frac{7!}{(7-3)!} = \frac{7!}{4!} = \frac{7 \cdot 6 \cdot 5 \cdot}{\,} \frac{4 \cdot 3 \cdot 2 \cdot 1}{4 \cdot 3 \cdot 2 \cdot 1}= 7 \cdot 6 \cdot 5" /><br />
</td>
</tr>
</table></p>
<p>
For <b>combinations</b>, you have <i>r</i> <b>non-unique</b> items<br />
over <i>n</i> slots. In this case you have two groups with overcounts,<br />
one of size <i>r</i> and one of size <i>n</i>&minus;r. This becomes
</p>
<p><table class="eqtbl" id="eq-cmb-combi">
<tr>
<td class="eqnrcell">(11)</td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?%5EnC_r%20%3D%20%7B%20n%20%5Cchoose%20r%20%7D%20%3D%20%7B%20n%21%20%5Cover%20r%21%20%28n-r%29%21%20%7D%20%3D%20%7B%5EnP_r%20%5Cover%20r%21%7D.'<br />
	title="^nC_r = { n \choose r } = { n! \over r! (n-r)! } = {^nP_r \over r!}."<br />
	alt="^nC_r = { n \choose r } = { n! \over r! (n-r)! } = {^nP_r \over r!}." /><br />
</td>
</tr>
</table></p>
<p>
The combination has three interesting properties.
</p>
<ol>
<li>
    It can be interpreted as a variation from the permutation,<br />
	namely by switching from unique to non-unique items. That&#8217;s<br />
	where the division by <i>r</i>! comes from.
  </li>
<li>
    Two, it&#8217;s symmetric between <i>r</i> and <i>n</i>&minus;<i>r</i>.<br />
	That is, <sup>n</sup>C<sub>r</sub> and <sup>n</sup>C<sub>n&minus;r</sub><br />
	are identical.
  </li>
<li>
    Three, it uses two groups of identical items, which is exactly<br />
	what you have in the case of the binomial distribution: one set<br />
	of wins and one set of fails. This is why it shows up as a<br />
	multiplier in Eq&nbsp;1, and why the combination<br />
	is also called the <dfn>binomial coefficient</dfn>.
  </li>
</ol>
<p><div>&nbsp;</div></p>
<p>
Instead of looking at unique versus non-unique, you can also<br />
interpret permutation and combination by looking at whether the order<br />
of the positions matter. If it does (that is, &#8220;123&#8243; is not the same as<br />
&#8220;132&#8243;), then it&#8217;s a permutation. If the order doesn&#8217;t matter, you have<br />
a combination.
</p>
<p><div>&nbsp;</div></p>
<p>
In the above , I&#8217;ve considered the binomial coefficient as a special<br />
case of the multinomial, but you can also do the reverse: string<br />
multiple binomials together to form a multinomial. In<br />
this case, you first distribute <i>k</i><sub>1</sub> elements over the<br />
whole <i>n</i> slots. This can be done in <sup>n</sup>C<sub>k1</sub><br />
ways. At this point, you&#8217;ve got <i>n</i>&minus;<i>k</i><sub>1</sub> slots<br />
remaining, over which you distribute <i>k</i><sub>2</sub>. This<br />
leaves <i>n</i>&minus;<i>k</i><sub>1</sub>&minus;<i>k</i><sub>2</sub> for group<br />
3, and so on until you&#8217;ve got no slots and items left. This is illustrated<br />
by Eq&nbsp;12. Note how one part of the denominator of<br />
one term cancels out against the numerator of the next.
</p>
<p><table class="eqtbl" id="eq-cmb-mnom2">
<tr>
<td class="eqnrcell">(12)</td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?%5Cbegin%7Beqnarray%7D%20%7B%20n%20%5Cchoose%20k_1%20%7D%20%7B%20n-k_1%20%5Cchoose%20k_2%20%7D%20%7B%20n-k_1-k_2%20%5Cchoose%20k_3%20%7D%20%5Cdots%20%7B%20k_m%20%5Cchoose%20k_m%20%7D%20%26%3D%26%20%7B%20n%21%20%5Cover%20k_1%21%20%28n-k_1%29%21%20%7D%5C%2C%20%7B%20%28n-k_1%29%21%20%5Cover%20k_2%21%20%28n-k_1-k_2%29%21%20%7D%20%5C%2C%5Ccdots%5C%2C%20%7B%20k_m%21%20%5Cover%20k_m%21%200%21%20%7D%20%5C%5C%20%26%3D%26%20%7B%20n%21%20%5Cover%20k_1%21%5C%2Ck_2%21%5C%2C%5Ccdots%5C%2Ck_m%21%20%7D%20%5C%5C%20%26%3D%26%20%7B%20n%20%5Cchoose%20k_1%2C%5C%2C%20k2%2C%20%5C%2C...%5C%2C%20%2C%5C%2C%20k_m%20%7D%20%5Cend%7Beqnarray%7D'<br />
	title="\begin{eqnarray} { n \choose k_1 } { n-k_1 \choose k_2 } { n-k_1-k_2 \choose k_3 } \dots { k_m \choose k_m } &amp;=&amp; { n! \over k_1! (n-k_1)! }\, { (n-k_1)! \over k_2! (n-k_1-k_2)! } \,\cdots\, { k_m! \over k_m! 0! } \\ &amp;=&amp; { n! \over k_1!\,k_2!\,\cdots\,k_m! } \\ &amp;=&amp; { n \choose k_1,\, k2, \,...\, ,\, k_m } \end{eqnarray}"<br />
	alt="\begin{eqnarray} { n \choose k_1 } { n-k_1 \choose k_2 } { n-k_1-k_2 \choose k_3 } \dots { k_m \choose k_m } &amp;=&amp; { n! \over k_1! (n-k_1)! }\, { (n-k_1)! \over k_2! (n-k_1-k_2)! } \,\cdots\, { k_m! \over k_m! 0! } \\ &amp;=&amp; { n! \over k_1!\,k_2!\,\cdots\,k_m! } \\ &amp;=&amp; { n \choose k_1,\, k2, \,...\, ,\, k_m } \end{eqnarray}" /><br />
</td>
</tr>
</table></p>
<p>
The binomial and multinomial coefficients are usually written as a<br />
2-by-1 matrix between parentheses (see Eq&nbsp;13).<br />
The construct is pronounced &ldquo;<i>n</i> choose <i>k</i>&rdquo;.<br />
No, I don&#8217;t know why either.
</p>
<p><table class="eqtbl" id="eq-cmb-choose">
<tr>
<td class="eqnrcell">(13)</td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?%5Cbegin%7Beqnarray%7D%20%5Ctext%7BBinomial%3A%20%7D%26%20%7B%20n%20%5Cchoose%20k%7D%3D%20%7B%20n%21%20%5Cover%20k%21%5C%2C%28n-k%29%21%20%7D%20%5C%5C%20%5Ctext%7BMultinomial%3A%20%7D%26%20%7B%20n%20%5Cchoose%20k_1%2C%20k_2%2C%20%5C%2C...%5C%2C%2C%20k_m%20%7D%3D%20%7B%20n%21%20%5Cover%20k_1%21%5C%2Ck_2%21%5C%2C%5Ccdots%5C%2Ck_m%21%20%7D%20%5Cend%7Beqnarray%7D'<br />
	title="\begin{eqnarray} \text{Binomial: }&amp; { n \choose k}= { n! \over k!\,(n-k)! } \\ \text{Multinomial: }&amp; { n \choose k_1, k_2, \,...\,, k_m }= { n! \over k_1!\,k_2!\,\cdots\,k_m! } \end{eqnarray}"<br />
	alt="\begin{eqnarray} \text{Binomial: }&amp; { n \choose k}= { n! \over k!\,(n-k)! } \\ \text{Multinomial: }&amp; { n \choose k_1, k_2, \,...\,, k_m }= { n! \over k_1!\,k_2!\,\cdots\,k_m! } \end{eqnarray}" /><br />
</td>
</tr>
</table></p>
<p><h3>
Back to the binomial
</h3>
</p>
<p>
Now that both parts of the division has been covered, lets go back to<br />
the binomial distribution and see how they fit together. For<br />
convenience, here&#8217;s what we were talking about again.
</p>
<p><table class="eqtbl" id="eq-binom-ex">
<tr>
<td class="eqnrcell">(14)</td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?%5Cbegin%7Beqnarray%7D%20P%28W%3Dk%20%5Ctext%7B%20in%20%7D%20n%29%20%26%3D%26%20%7Bn%5Cchoose%20k%7D%20p%5Ek%20%281-p%29%5E%7Bn-k%7D%20%5C%5C%20%5Ctext%7Bor%7D%20%5C%5C%20P%28W%3Dk%2C%20F%3Dn-k%29%20%26%3D%26%20%7Bn%5Cchoose%20k%7D%20p_w%5Ek%20%5C%2C%20p_f%5E%7Bn-k%7D%20%5Cend%7Beqnarray%7D'<br />
	title="\begin{eqnarray} P(W=k \text{ in } n) &amp;=&amp; {n\choose k} p^k (1-p)^{n-k} \\ \text{or} \\ P(W=k, F=n-k) &amp;=&amp; {n\choose k} p_w^k \, p_f^{n-k} \end{eqnarray}"<br />
	alt="\begin{eqnarray} P(W=k \text{ in } n) &amp;=&amp; {n\choose k} p^k (1-p)^{n-k} \\ \text{or} \\ P(W=k, F=n-k) &amp;=&amp; {n\choose k} p_w^k \, p_f^{n-k} \end{eqnarray}" /><br />
</td>
</tr>
</table></p>
<ol>
<li>
    The base chance of getting a specific result that satisfies your<br />
	conditions.
  </li>
<li>
    The number of results that satisfies the conditions (each with the<br />
	same base probability).
  </li>
</ol>
<p>
The thing about these two parts is that they actually represent two of<br />
the rules of probability, namely those describing how probabilities<br />
combine. Part 1, the base chance is a joint condition; an AND case.<br />
The second part covers all the mutually exclusive ways that the joint<br />
condition can be satisfied.
</p>
<p>
For example with 2 <i>a</i>s and 1 <i>b</i>,<br />
the ways the cases combine are <i>aab</i>, <i>aba</i> or <i>baa</i>. If<br />
you were to write it out completely, you&#8217;d get
</p>
<p><table class="eqtbl">
<tr>
<td class="eqnrcell"></td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?P%28A%3D2%2CB%3D1%29%20%3D%20%5Cbegin%7Beqnarray%7D%20%28%5C%2CP%28A%29%20%5Ctext%7B%20and%20%7D%20P%28A%29%20%5Ctext%7B%20and%20%7D%20P%28B%29%5C%2C%29%20%26%5Ctext%7B%20or%20%7D%20%5C%5C%20%28%5C%2CP%28A%29%20%5Ctext%7B%20and%20%7D%20P%28B%29%20%5Ctext%7B%20and%20%7D%20P%28A%29%5C%2C%29%20%26%5Ctext%7B%20or%20%7D%20%5C%5C%20%28%5C%2CP%28B%29%20%5Ctext%7B%20and%20%7D%20P%28A%29%20%5Ctext%7B%20and%20%7D%20P%28A%29%5C%2C%29%20%26%20%5Cend%7Beqnarray%7D'<br />
	title="P(A=2,B=1) = \begin{eqnarray} (\,P(A) \text{ and } P(A) \text{ and } P(B)\,) &amp;\text{ or } \\ (\,P(A) \text{ and } P(B) \text{ and } P(A)\,) &amp;\text{ or } \\ (\,P(B) \text{ and } P(A) \text{ and } P(A)\,) &amp; \end{eqnarray}"<br />
	alt="P(A=2,B=1) = \begin{eqnarray} (\,P(A) \text{ and } P(A) \text{ and } P(B)\,) &amp;\text{ or } \\ (\,P(A) \text{ and } P(B) \text{ and } P(A)\,) &amp;\text{ or } \\ (\,P(B) \text{ and } P(A) \text{ and } P(A)\,) &amp; \end{eqnarray}" /><br />
</td>
</tr>
</table></p>
<p>
Obviously, you&#8217;re not going to write this out all the time,<br />
especially not when the numbers get large, but this is really what<br />
you&#8217;re looking for. The use of the base-chance and combinations are<br />
ways of shortcircuiting this. As said, the base-chance is the<br />
probability of the string of ANDs, which will be the same for case.<br />
Because of this, the addition of all the (X)ORs simply becomes a<br />
multiplication by the number of (X)ORs that you have, which is<br />
given by the binomial, or multinomial if you have more than one option.
</p>
<p><div>&nbsp;</div></p>
<p>
Another interesting point is that the binomial and multinomial<br />
coefficients themselves can be read as probabilities as well. It&#8217;s just<br />
that because we&#8217;re certain <i>k</i><sub>j</sub> items will exist if<br />
we&#8217;re just arranging items, the probability for each group is 1, so<br />
the whole probability part is unnecessary.
</p>
<p><h2 id="sec-eg">4
Examples
</h2>
</p>
<p>
Because I know all of this can be a little mesmerizing at first, I<br />
thought I&#8217;d give a few examples as well.
</p>
<p><h3 id="ssec-eg-binom">4.1
Beastly dice
</h3>
</p>
<p>
First, simple example of the binomial distribution. Say we have<br />
five dice (5d6) and we&#8217;re looking at the different ways of getting<br />
exactly three sixes. Note that this also means the remaining cases<br />
should be a non-six!
</p>
<p>
First, the probability of a six is <i>p</i><sub>6</sub>&nbsp;=&nbsp;1/6, and<br />
of a non-six <i>p</i><sub>&not;6</sub>&nbsp;=&nbsp;5/6. As for the group-counts,<br />
we have 2 groups with <i>k</i>&nbsp;=&nbsp;<i>k</i><sub>6</sub>&nbsp;=&nbsp;3 and<br />
<i>k</i><sub>&not;6</sub>&nbsp;=&nbsp;2, and <i>n</i>&nbsp;=&nbsp;5. Putting this together<br />
results in Eq&nbsp;15. Note the base chance fo getting<br />
any triple-six result, and the number of ways you can vary this<br />
over five dice.
</p>
<p><table class="eqtbl" id="eq-eg-666">
<tr>
<td class="eqnrcell">(15)</td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?P%283%20%5Ctimes%206%20%5Ctext%7B%20in%20%7D%205%29%20%3D%20P%283%20%5Ctimes%206%20%5C%2C%5C%26%5C%2C%202%20%5Ctimes%20%5Cnot6%29%20%3D%20%7B%205%20%5Cchoose%203%7D%20p_6%5E3%20p_%7B%5Cnot6%7D%5E2%20%3D%2010%5Ccdot%5C%28%5Cfrac16%5C%29%5E3%5C%28%5Cfrac56%5C%29%5E2%20%3D%203.21%25'<br />
	title="P(3 \times 6 \text{ in } 5) = P(3 \times 6 \,\&amp;\, 2 \times \not6) = { 5 \choose 3} p_6^3 p_{\not6}^2 = 10\cdot\(\frac16\)^3\(\frac56\)^2 = 3.21%"<br />
	alt="P(3 \times 6 \text{ in } 5) = P(3 \times 6 \,\&amp;\, 2 \times \not6) = { 5 \choose 3} p_6^3 p_{\not6}^2 = 10\cdot\(\frac16\)^3\(\frac56\)^2 = 3.21%" /><br />
</td>
</tr>
</table></p>
<p>
There&#8217;s also another way of getting to this result, namely by direct<br />
use of the definition of probability, Eq&nbsp;2. To do<br />
this, we need know the total number of possibilities, and how many<br />
will result in 3 sixes. With five dice, the total is<br />
<i>T</i>&nbsp;=&nbsp;6<sup>5</sup>. There are <sup>5</sup>C<sub>3</sub>&nbsp;=&nbsp;10<br />
ways of getting exactly 3 sixes in five dice and 5 non-six options<br />
for the remaining two dice, leading to a total of valid cases of<br />
10&middot;5<sup>2</sup>&nbsp;=&nbsp;250.
</p>
<p><table class="eqtbl">
<tr>
<td class="eqnrcell"></td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?P%283%20%5Ctimes%206%20%5Ctext%7B%20in%20%7D%205%29%20%3D%20%7B%20%23%283%5Ctimes%206%20%5Ctext%7B%20in%20%7D%205%29%20%5Cover%20%23%5Ctext%7Btotal%7D%20%7D%20%3D%20%7B%2010%20%5Ccdot%205%5E2%20%5Cover%205%5E6%20%7D%20%3D%20%5Cfrac%7B250%7D%7B7776%7D%20%3D%203.21%25'<br />
	title="P(3 \times 6 \text{ in } 5) = { #(3\times 6 \text{ in } 5) \over #\text{total} } = { 10 \cdot 5^2 \over 5^6 } = \frac{250}{7776} = 3.21%"<br />
	alt="P(3 \times 6 \text{ in } 5) = { #(3\times 6 \text{ in } 5) \over #\text{total} } = { 10 \cdot 5^2 \over 5^6 } = \frac{250}{7776} = 3.21%" /><br />
</td>
</tr>
</table></p>
<p><h3 id="ssec-eg-full">4.2
Yahtzee : full house
</h3>
</p>
<p>
More dice, this time looking at the yahtzee game. A full house is three<br />
of a kind plus a pair, like 66655, 11122 or 22333, and any variation<br />
thereof. In this particular case I want to look at getting a full house<br />
in one go, because to take all three turns into account is way too<br />
hairy.
</p>
<p>
The case is actually similar to the previous one in that you have<br />
3 of one group and 2 of another, but the probabilities are a little<br />
different. For a specific full house, say 11122 the base chance is<br />
1/6<sup>5</sup>. However, we&#8217;re not looking for a specific one, but any<br />
full house. This means that there will be 6 options for the first group,<br />
and 5 for the second. The final probability is
</p>
<p><table class="eqtbl" id="eq-eg-full">
<tr>
<td class="eqnrcell">(16)</td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?P%28%5Ctext%7Bany%20full%20house%7D%29%20%3D%206%20%5Ccdot%205%20%5Ctimes%20P%28%5Ctext%7Bfull%20house%7D%29%20%3D%2030%5Ccdot%7B%205%20%5Cchoose%203%20%7D%20%5Ctimes%20%5C%28%5Cfrac16%5C%29%5E5%20%3D%2030%5Ccdot10%20%5Ctimes%20%5Cfrac1%7B7776%7D%20%3D%203.86%25'<br />
	title="P(\text{any full house}) = 6 \cdot 5 \times P(\text{full house}) = 30\cdot{ 5 \choose 3 } \times \(\frac16\)^5 = 30\cdot10 \times \frac1{7776} = 3.86%"<br />
	alt="P(\text{any full house}) = 6 \cdot 5 \times P(\text{full house}) = 30\cdot{ 5 \choose 3 } \times \(\frac16\)^5 = 30\cdot10 \times \frac1{7776} = 3.86%" /><br />
</td>
</tr>
</table></p>
<p>
An alternative approach is to consider the group-determining dice to be<br />
&ldquo;free&rdquo;, giving the probability 6/6 and 5/6 for the first<br />
and second group, respectively. After that, the remaining dice have to<br />
follow suit to give (1/6)<sup>3</sup>.
</p>
<p><h3 id="ssec-eg-wheel">4.3
Multinomial : spinning wheels
</h3>
</p>
<p><div id="img-wheel" class="cptfr" style=";">
  <a href="" target="_blank">
    <img src=""><br>
  </a>
    <span class="caption"><b>Fig&nbsp;4. </b></span>
</div>
</p>
<p>
And now for an application of the multinomial. Consider the<br />
wheel from Fig&nbsp;4. It has 2 <i>a</i>s, 3 <i>b</i>s<br />
and 5 <i>c</i>s: <i>n</i><sub>a</sub>&nbsp;=&nbsp;2,<br />
<i>n</i><sub>b</sub>&nbsp;=&nbsp;3, <i>n</i><sub>c</sub>&nbsp;=&nbsp;5.<br />
The probabilities for each letter follow from the probability definition,<br />
resulting in<br />
<i>p</i><sub>a</sub>&nbsp;=&nbsp;2/10&nbsp;=&nbsp;20%,<br />
<i>p</i><sub>b</sub>&nbsp;=&nbsp;3/10&nbsp;=&nbsp;30% and<br />
<i>p</i><sub>c</sub>&nbsp;=&nbsp;5/10&nbsp;=&nbsp;50%.
</p>
<p>
The question is: what&#8217;s the chance of getting 3 <i>a</i>s, 2 <i>c</i>s<br />
in 9 spins?
</p>
<p><div>&nbsp;</div></p>
<p>
Well, first you have to note that 3+2 is less than 9, so there&#8217;s a<br />
hidden condition: the remaining 4 tries should be a <i>b</i>. This<br />
transforms the question into 3 <i>a</i>s, 4 <i>b</i>s and 2 <i>c</i>s,<br />
or<br />
<i>k</i><sub>a</sub>&nbsp;=&nbsp;3,<br />
<i>k</i><sub>b</sub>&nbsp;=&nbsp;4,<br />
<i>k</i><sub>c</sub>&nbsp;=&nbsp;2, Also note that the number of results have<br />
nothing to do with how many appear on the wheel.
</p>
<p><table class="eqtbl" id="eq-eg-wheel">
<tr>
<td class="eqnrcell">(17)</td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?%5Cbegin%7Beqnarray%7D%20P%28A%3D3%2CC%3D2%20%5Ctext%7B%20in%20%7D%209%29%20%26%3D%26%20P%28A%3D3%2CB%3D4%2CC%3D2%29%20%5C%5C%20%5Cvspace%7B10%7D%20%5C%5C%20%26%3D%26%20%7B%20%5C%28k_a%20%2B%20k_b%20%2B%20k_c%5C%29%21%20%5Cover%20k_a%21%5C%2Ck_b%21%5C%2Ck_c%21%20%7D%20p_a%5E%7Bk_a%7D%5C%2Cp_b%5E%7Bk_b%7D%5C%2Cp_c%5E%7Bk_c%7D%5C%2C%20%5C%5C%20%5Cvspace%7B10%7D%20%5C%5C%20%26%3D%26%20%7B%20%283%2B4%2B2%29%21%20%5Cover%203%21%204%21%202%21%20%7D%20%5C%28%5Cfrac2%7B10%7D%5C%29%5E3%20%5C%2C%20%5C%28%5Cfrac3%7B10%7D%5C%29%5E4%20%5C%2C%20%5C%28%5Cfrac5%7B10%7D%5C%29%5E2%5C%2C%20%5C%5C%20%5Cvspace%7B10%7D%20%5C%5C%20%26%3D%26%201260%20%5Ccdot%20%5Cfrac%7B8%20%5Ccdot%2081%20%5Ccdot%2025%20%7D%7B10%5E9%7D%20%3D%202.04%20%25%20%5Cend%7Beqnarray%7D'<br />
	title="\begin{eqnarray} P(A=3,C=2 \text{ in } 9) &amp;=&amp; P(A=3,B=4,C=2) \\ \vspace{10} \\ &amp;=&amp; { \(k_a + k_b + k_c\)! \over k_a!\,k_b!\,k_c! } p_a^{k_a}\,p_b^{k_b}\,p_c^{k_c}\, \\ \vspace{10} \\ &amp;=&amp; { (3+4+2)! \over 3! 4! 2! } \(\frac2{10}\)^3 \, \(\frac3{10}\)^4 \, \(\frac5{10}\)^2\, \\ \vspace{10} \\ &amp;=&amp; 1260 \cdot \frac{8 \cdot 81 \cdot 25 }{10^9} = 2.04 % \end{eqnarray}"<br />
	alt="\begin{eqnarray} P(A=3,C=2 \text{ in } 9) &amp;=&amp; P(A=3,B=4,C=2) \\ \vspace{10} \\ &amp;=&amp; { \(k_a + k_b + k_c\)! \over k_a!\,k_b!\,k_c! } p_a^{k_a}\,p_b^{k_b}\,p_c^{k_c}\, \\ \vspace{10} \\ &amp;=&amp; { (3+4+2)! \over 3! 4! 2! } \(\frac2{10}\)^3 \, \(\frac3{10}\)^4 \, \(\frac5{10}\)^2\, \\ \vspace{10} \\ &amp;=&amp; 1260 \cdot \frac{8 \cdot 81 \cdot 25 }{10^9} = 2.04 % \end{eqnarray}" /><br />
</td>
</tr>
</table></p>
<p><h2 id="sec-summary">5
Summary
</h2>
</p>
<p>
As this post covers quite a bit, I think a summary might be in order.
</p>
<ul>
<li>
    Rules of probability:</p>
<ol>
<li>
	    <b>Definition</b>: the probability of event <i>X</i> is the<br />
		number of occurances over the total number of events.<br/></p>
<p><img src='http://www.coranac.com/cgi-bin/mimetex.cgi?P%28X%29%20%3D%20%7B%7B%23%20%5Ctext%7BXs%7D%7D%20%5Cover%20%7B%20%5Ctext%7BAll%20events%7D%7D%7D'<br />
	title="P(X) = {{# \text{Xs}} \over { \text{All events}}}"<br />
	alt="P(X) = {{# \text{Xs}} \over { \text{All events}}}" /><br />
<br/><br />
		Do not forget this rule, as its the basis for all the others.
	  </li>
<li>
	    <b>Complementary rule (NOT)</b>. The probability of not getting<br />
		<i>X</i> is the rest of the cases.<br/></p>
<p><img src='http://www.coranac.com/cgi-bin/mimetex.cgi?P%28%5Cneg%20X%29%20%3D%201%20-%20P%28X%29'<br />
	title="P(\neg X) = 1 - P(X)"<br />
	alt="P(\neg X) = 1 - P(X)" /></p>
</li>
<li>
	    <b>Disjoint/Parallel condition ((X)OR)</b> :<br />
		intersection of cases; probabilities add.<br/></p>
<p><img src='http://www.coranac.com/cgi-bin/mimetex.cgi?P%28X%20%5Coplus%20Y%29%20%3D%20P%28X%29%20%2B%20P%28Y%29'<br />
	title="P(X \oplus Y) = P(X) + P(Y)"<br />
	alt="P(X \oplus Y) = P(X) + P(Y)" /></p>
</li>
<li>
	    <b>Joint/Serial condition (AND)</b> :<br />
		union of cases; probabilities multiply.<br/></p>
<p><img src='http://www.coranac.com/cgi-bin/mimetex.cgi?P%28X%20%5C%26%20Y%29%20%3D%20P%28X%29%20%5Ccdot%20P%28Y%29'<br />
	title="P(X \&amp; Y) = P(X) \cdot P(Y)"<br />
	alt="P(X \&amp; Y) = P(X) \cdot P(Y)" /></p>
</li>
</ol>
<p>	The NOT, XOR and AND terms have commonalities with those used in<br />
	boolean logic, and electrical engineering.
  </li>
<li>
    Compound-condition probabilities usually involve both AND and<br />
    OR conditions, making up the two parts of a<br />
	binomial/multinomial probability.</p>
<ol>
<li>The AND conditions results in the probability of<br />
	    <i>one</i> solution, which multiplies all the probabilities of<br />
	    each sub-sample.
	  </li>
<li>
	    The OR condition counts how many solutions there are,<br />
		given by the bi-/multinomial coefficient.
	  </li>
</ol>
</li>
</ul>
<p><div>&nbsp;</div></p>
<ul>
<li>
    <b>Factorial ( <i>n</i>! )</b>.<br />
	The factorial represents the number of ways you can arrange<br />
	<i>n</i> unique/distinct items.<br/></p>
<p><img src='http://www.coranac.com/cgi-bin/mimetex.cgi?n%21%20%3D%201%5Ccdot2%5Ccdot%20%5C%2C...%5C%2C%20%5Ccdot%28n-1%29%5Ccdot%20n'<br />
	title="n! = 1\cdot2\cdot \,...\, \cdot(n-1)\cdot n"<br />
	alt="n! = 1\cdot2\cdot \,...\, \cdot(n-1)\cdot n" /></p>
</li>
<li>
    <b>Permutation ( <sup>n</sup>P<sub>r</sub> )</b>.<br />
	Permutation refers to how many ways you can distribute <i>r</i><br />
	unique/distinct items over <i>n</i> slots, or when the order<br />
	of the elements matters.<br/></p>
<p><img src='http://www.coranac.com/cgi-bin/mimetex.cgi?%5EnP_r%20%3D%20n_%7B%28r%29%7D%20%3D%20%7B%20%7B%20n%21%7D%20%5Cover%20%7B%28n-r%29%21%20%7D%20%7D'<br />
	title="^nP_r = n_{(r)} = { { n!} \over {(n-r)! } }"<br />
	alt="^nP_r = n_{(r)} = { { n!} \over {(n-r)! } }" /></p>
</li>
<li>
    <b>Combination ( <sup>n</sup>C<sub>r</sub> )</b>.<br />
	Combination refers to how many ways you can distribute <i>r</i><br />
	non-unique/indistinct items over <i>n</i> slots, or when the order<br />
	of the elements does not matter.<br/></p>
<p><img src='http://www.coranac.com/cgi-bin/mimetex.cgi?%5EnC_r%20%3D%20%7B%5EnP_r%7D%2Fr%21%20%3D%20%7B%20n%21%20%5Cover%20r%21%28n-r%29%21%20%7D'<br />
	title="^nC_r = {^nP_r}/r! = { n! \over r!(n-r)! }"<br />
	alt="^nC_r = {^nP_r}/r! = { n! \over r!(n-r)! }" /></p>
</li>
<li>
    <b>Binomial / Multinomial coefficient (<br />
	<i>n</i> choose <i>k</i>(<sub>1</sub>,<br />
	<i>k</i><sub>2</sub>, &hellip; <i>k</i><sub>m</sub>) )</b>,<br />
	The binomial is the number of ways you can arrange 2 groups with<br />
	<i>k</i> and <i>n</i>&minus;<i>k</i> non-unique elements over <i>n</i><br />
	bins. This is basically the same thing as the combination.<br />
	The multinomial is the extension to <i>m</i> groups, with<br />
	<i>k</i><sub>j</sub> elements in each group. In both cases<br />
	you take the base <i>n</i>! for the unique variations, and divide<br />
	by <i>k</i><sub>j</sub>! for the overcounts for all the groups.<br/></p>
<p><img src='http://www.coranac.com/cgi-bin/mimetex.cgi?%5Cbegin%7Beqnarray%7D%20%5Ctext%7BBinomial%3A%20%7D%26%20%7B%20n%20%5Cchoose%20k%7D%3D%20%7B%20n%21%20%5Cover%20k%21%5C%2C%28n-k%29%21%20%7D%20%5C%5C%20%5Ctext%7BMultinomial%3A%20%7D%26%20%7B%20n%20%5Cchoose%20k_1%2C%20k_2%2C%20%5C%2C...%2C%5C%2C%20k_m%20%7D%3D%20%7B%20n%21%20%5Cover%20k_1%21%5C%2Ck_2%21%5C%2C%5Ccdots%5C%2Ck_m%21%20%7D%20%5Cend%7Beqnarray%7D'<br />
	title="\begin{eqnarray} \text{Binomial: }&amp; { n \choose k}= { n! \over k!\,(n-k)! } \\ \text{Multinomial: }&amp; { n \choose k_1, k_2, \,...,\, k_m }= { n! \over k_1!\,k_2!\,\cdots\,k_m! } \end{eqnarray}"<br />
	alt="\begin{eqnarray} \text{Binomial: }&amp; { n \choose k}= { n! \over k!\,(n-k)! } \\ \text{Multinomial: }&amp; { n \choose k_1, k_2, \,...,\, k_m }= { n! \over k_1!\,k_2!\,\cdots\,k_m! } \end{eqnarray}" /></p>
</li>
</ul>
<p>
And lastly,
</p>
<ul>
<li><b>Bi-/multinomial probability</b>.<br />
  When you have <i>m</i> groups with probability <i>p</i><sub>j</sub><br />
  for each group and you want to know the chance of drawing exactly<br />
  <i>k</i><i>j</i> items in<br />
  <i>n</i>&nbsp;=&nbsp;&Sigma;<sub>j</sub>&nbsp;<i>k</i><i>j</i> samples, the<br />
  probability is:<br/><br />
  <table class="eqtbl" id="eq-prob-mnom">
<tr>
<td class="eqnrcell">(18)</td>
  <td class="eqcell"><br />
<img src='http://www.coranac.com/cgi-bin/mimetex.cgi?%5Cbegin%7Beqnarray%7D%20P%28X_1%3Dk_1%5C%2C...%5C%2CX_m%3Dk_m%29%20%26%3D%26%20%7B%20n%20%5Cchoose%20k_1%2C%5C%2C...%2C%5C%2Ck_m%20%7D%20%26%5Ccdot%26%20%5Cprod_%7Bj%3D1%7D%5Em%20p_j%5Em%20%5C%5C%20%26%3D%26%20%7B%20n%21%20%5Cover%20k_1%21%5Ccdot%5C%2C...%5C%2C%20%5Ccdot%20k_m%21%20%7D%20%26%5Ccdot%26%20p_1%5E%7Bk_1%7D%5Ccdot%5C%2C...%5C%2C%5Ccdot%20p_m%5E%7Bk_m%7D%20%5Cend%7Beqnarray%7D'<br />
	title="\begin{eqnarray} P(X_1=k_1\,...\,X_m=k_m) &amp;=&amp; { n \choose k_1,\,...,\,k_m } &amp;\cdot&amp; \prod_{j=1}^m p_j^m \\ &amp;=&amp; { n! \over k_1!\cdot\,...\, \cdot k_m! } &amp;\cdot&amp; p_1^{k_1}\cdot\,...\,\cdot p_m^{k_m} \end{eqnarray}"<br />
	alt="\begin{eqnarray} P(X_1=k_1\,...\,X_m=k_m) &amp;=&amp; { n \choose k_1,\,...,\,k_m } &amp;\cdot&amp; \prod_{j=1}^m p_j^m \\ &amp;=&amp; { n! \over k_1!\cdot\,...\, \cdot k_m! } &amp;\cdot&amp; p_1^{k_1}\cdot\,...\,\cdot p_m^{k_m} \end{eqnarray}" /><br />
</td>
</tr>
</table><br/><br />
  And remember that this holds for just two groups (the binomial case)<br />
  as well, except that often they&#8217;ll just pretend that the second<br />
  group isn&#8217;t really there. Which is unfortunate, as<br />
  that&#8217;s where the (1&minus;p) and (<i>n</i>&minus;<i>k</i>) terms come from.
  </li>
</ul>
<p><!-- EOF --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.coranac.com/2010/05/probabilities-in-simple-random-samples/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>setds 1.01 and an annoying yet oddly fitting bug</title>
		<link>http://www.coranac.com/2010/04/setds-1-01/</link>
		<comments>http://www.coranac.com/2010/04/setds-1-01/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 19:09:21 +0000</pubDate>
		<dc:creator>cearn</dc:creator>
				<category><![CDATA[nds]]></category>
		<category><![CDATA[setds]]></category>

		<guid isPermaLink="false">http://www.coranac.com/?p=189</guid>
		<description><![CDATA[It seems that a bug in the hiscore entry code that I thought I&#8217;d fixed over a month ago got resurrected in setds v1.0. So I fixed it &#8211; refixed it &#8211; today and we&#8217;re now at setds v1.01. &#160; &#8230; <a href="http://www.coranac.com/2010/04/setds-1-01/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
It seems that a bug in the hiscore entry code that I <i>thought</i> I&#8217;d fixed over a month ago got resurrected in setds v1.0. So I fixed it &ndash; <i>re</i>fixed it &ndash; today and we&#8217;re now at <a href="[$HOME/projects/setds">setds v1.01</a>.
</p>
<p><div>&nbsp;</div></p>
<p>
<small>Sigh. Gaddammit <kbd>&gt;_&lt;</kbd></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.coranac.com/2010/04/setds-1-01/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!--
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
</head>
<body>
<p>
My database has called in sick. Please imagine some 
annoying elevator tune till he gets back.
</p>
<p>
<small>[[Doo-di-doo tooo. Dum-di-dum-di-doo-dooo.]]</small>
</p>
</body>
</html>

-->
