<?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>a+bi</title>
	<atom:link href="http://www.aplusbi.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.aplusbi.com</link>
	<description>What does aploosby mean?</description>
	<lastBuildDate>Wed, 02 Jun 2010 23:25:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>dwm and dvtm patches</title>
		<link>http://www.aplusbi.com/?p=180</link>
		<comments>http://www.aplusbi.com/?p=180#comments</comments>
		<pubDate>Wed, 02 Jun 2010 20:18:32 +0000</pubDate>
		<dc:creator>Niki</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.aplusbi.com/?p=180</guid>
		<description><![CDATA[A new version of dwm has been released so I have updated the Fibonacci spiral patch. I&#8217;m still working on the movestack patch. The updated dwm patch can be found here. I have also created a Fibonacci layout patch for dvtm &#8211; the dynamic virtual terminal manager. The dvtm patch can be found here.]]></description>
			<content:encoded><![CDATA[<p>A new version of <a href="http://dwm.suckless.org">dwm</a> has been released so I have updated the Fibonacci spiral patch.  I&#8217;m still working on the movestack patch.  The updated dwm patch can be found  <a href="http://www.aplusbi.com/?page_id=23">here</a>.  I have also created a Fibonacci layout patch for <a href="http://www.brain-dump.org/projects/dvtm/">dvtm</a> &#8211; the dynamic virtual terminal manager.  The dvtm patch can be found <a href="http://www.aplusbi.com/?page_id=175">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aplusbi.com/?feed=rss2&amp;p=180</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Signing Android applications</title>
		<link>http://www.aplusbi.com/?p=170</link>
		<comments>http://www.aplusbi.com/?p=170#comments</comments>
		<pubDate>Sat, 15 May 2010 23:27:29 +0000</pubDate>
		<dc:creator>Niki</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.aplusbi.com/?p=170</guid>
		<description><![CDATA[In order to install an Android Application onto the emulator or the phone you must first cryptographically sign it. When you do a debug build (using &#8220;ant debug&#8221;) ant will automatically sign the binary with an auto-generated debug key. This key is set to expire 365 days after it was auto-generated (the first time you [...]]]></description>
			<content:encoded><![CDATA[<p>In order to install an Android Application onto the emulator or the phone you must first <a href="http://developer.android.com/guide/publishing/app-signing.html">cryptographically sign it</a>.  When you do a debug build (using &#8220;ant debug&#8221;) ant will automatically sign the binary with an auto-generated debug key.</p>
<p>This key is set to expire 365 days after it was auto-generated (the first time you did a debug build).  If a debug build fails due to an expired key, you simply need to delete the current debug key and a new one will be auto-generated.  To do this, navigate to where the debug key is located and delete it.  On Linux and Mac OS X this is ~/.android and the key is the file &#8220;debug.keystore&#8221;.</p>
<p>Signing your application with a debug key is fine for testing purposes but for release the application should be signed with a unique key that you have generated just for that purpose.  If you plan on release the application on the Android Market then the key should also contain correct identifying information (your name or company) and should expire <b>no earlier than October 22, 2033</b>.</p>
<p>To generate a key you need to have the keytool application that come with Java.  You need to specify the key-store (the file name), the alias for the key, which algorithm to use (we want RSA) and how long it should be valid for.  Let&#8217;s create a key stored in the file &#8220;release.keystore&#8221; with the alias &#8220;release&#8221; that will be valid for 10,000 days:</p>
<p><code>niki@redblacktree:~/.android$ keytool -genkey -v -key-store release.keystore -alias release -keyalg RSA -validity 10000</code></p>
<p>Keytool will then ask you a bunch of questions:</p>
<p><code>Enter keystore password:<br />
Re-enter new password:<br />
What is your first and last name?<br />
  [Unknown]:  Niki Yoshiuchi<br />
What is the name of your organizational unit?<br />
  [Unknown]:  aplusbi<br />
What is the name of your organization?<br />
  [Unknown]:  aplusbi<br />
What is the name of your City or Locality?<br />
  [Unknown]:  New York<br />
What is the name of your State or Province?<br />
  [Unknown]:  NY<br />
What is the two-letter country code for this unit?<br />
  [Unknown]:  US<br />
Is CN=Niki Yoshiuchi, OU=aplusbi, O=aplusbi, L=New York, ST=NY, C=US correct?<br />
  [no]:  y</p>
<p>Generating 1,024 bit RSA key pair and self-signed certificate (SHA1withRSA) with a validity of 10,000 days<br />
        for: CN=Niki Yoshiuchi, OU=aplusbi, O=aplusbi, L=New York, ST=NY, C=US<br />
Enter key password for <release><br />
        (RETURN if same as keystore password):<br />
[Storing release.keystore]</code></p>
<p>And you&#8217;re done!  You&#8217;ll notice that I ran keytool out of the ~/.android directory so that release.keystore is located in the same place as debug.keystore.</p>
<p>Now onto signing applications.  Let&#8217;s go back to our Hello Android project and do a release build:</p>
<p><code>niki@redblacktree:~/projects/android/hello$ ant release</code></p>
<p>Once this has finished there should be a new apk located in the bin directory called &#8220;HelloAndroid-unsigned.apk&#8221;.  We need to sign it with the key we created earlier using jarsigner:</p>
<p><code>niki@redblacktree:~/projects/android/hello$ jarsigner -keystore ~/.android/release.keystore HelloAndroid-unsigned.apk release</code></p>
<p>And now &#8220;HelloAndroid-unsigned.apk&#8221; has been signed.  It can now be installed using adb.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aplusbi.com/?feed=rss2&amp;p=170</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating an Android project from the Command Line</title>
		<link>http://www.aplusbi.com/?p=164</link>
		<comments>http://www.aplusbi.com/?p=164#comments</comments>
		<pubDate>Fri, 14 May 2010 18:36:12 +0000</pubDate>
		<dc:creator>Niki</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>

		<guid isPermaLink="false">http://www.aplusbi.com/?p=164</guid>
		<description><![CDATA[Android&#8217;s developer guide has a section on Developing in other IDEs for those who don&#8217;t want to use Eclipse. However the documentation leaves out a few details and all of the examples use Eclipse with perhaps a token paragraph discussing the CLI. The rest of this post will assume that you have already installed the [...]]]></description>
			<content:encoded><![CDATA[<p>Android&#8217;s developer guide has a section on <a href="http://developer.android.com/guide/developing/other-ide.html">Developing in other IDEs</a> for those who don&#8217;t want to use Eclipse.  However the documentation leaves out a few details and all of the examples use Eclipse with perhaps a token paragraph discussing the CLI.  The rest of this post will assume that you have already installed the SDK and properly configured it (added the SDK to your path and installed the appropriate SDK components).</p>
<p>The first thing to do is to figure out which version of Android you want to target.  Version 1.6 (aka &#8211; &#8220;Donut&#8221;) is a pretty good lowest-common-denominator.  Using the Android tool we will figure out the ID for 1.6:</p>
<p><code>niki@redblacktree:~$ android list targets</code></p>
<p>Which will give you a list of all the targets available (this depends on which <a href="http://developer.android.com/sdk/adding-components.html">SDK components</a> you have added).  My output looks like this:</p>
<p><code>Available Android targets:<br />
id: 1 or "android-3"<br />
     Name: Android 1.5<br />
     Type: Platform<br />
     API level: 3<br />
     Revision: 1<br />
     Skins: QVGA-L, QVGA-P, HVGA (default), HVGA-P, HVGA-L<br />
id: 2 or "android-4"<br />
     Name: Android 1.6<br />
     Type: Platform<br />
     API level: 4<br />
     Revision: 1<br />
     Skins: WVGA854, QVGA, HVGA (default), WVGA800<br />
id: 3 or "android-7"<br />
     Name: Android 2.1<br />
     Type: Platform<br />
     API level: 7<br />
     Revision: 1<br />
     Skins: WVGA854, WQVGA400, QVGA, HVGA (default), WVGA800, WQVGA432</code></p>
<p>The target ID for version 1.6 is 2.  Knowing that, let&#8217;s set up an Android Virtual Device (AVD) for our emulator using the android tool, specifying the target with the &#8211;target option and giving it a name with the &#8211;name option.  We will use the default hardware configuration:</p>
<p><code>niki@redblacktree:~$ android create avd --name donut<br />
Android 1.6 is a basic Android platform.<br />
Do you wish to create a custom hardware profile [no]<br />
Created AVD 'test' based on Android 1.6, with the following hardware config:<br />
hw.lcd.density=160<br />
</code></p>
<p>Finally, let&#8217;s setup a project.  Again well use the android tool, this time to create a new project.  I&#8217;m going to create the project in the directory ~/projects/android/hello:</p>
<p><code>niki@redblacktree:~/projects/android/hello$ android create project --name HelloAndroid --activity HelloAndroid --path ./ --package com.examples.helloandroid --target 2</code></p>
<p>This will create a new project in the current directory (&#8211;path ./) with the name &#8220;HelloAndroid&#8221; (&#8211;name HelloAndroid).  It will be targeted towards Android 1.6 (&#8211;target 2).  It will create a Java source file containing an <a href="http://developer.android.com/reference/android/app/Activity.html">Activity</a> &#8220;HelloAndroid&#8221; (&#8211;activity HelloAndroid) and will be in the namespace &#8220;com.examples.helloandroid&#8221; (&#8211;package com.examples.helloandroid).</p>
<p>We can now use Apache Ant to build our project:</p>
<p><code>niki@redblacktree:~/projects/android/hello$ ant debug</code></p>
<p>This will build a debug version of our project and place the &#8220;HelloAndroid-debug.apk&#8221; in the bin directory.  This application has been signed using a default debug key and is ready to be installed on a device.  To do that, let&#8217;s fire up the emulator, using the virtual device we created earlier:</p>
<p><code>niki@redblacktree:~$ emulator -avd donut</code></p>
<p>Once the emulator has finished booting, we can get a list of attached devices using the Android Debug Bridge or adb:</p>
<p><code>niki@redblacktree:~/projects/android/hello$ adb devices<br />
List of devices attached<br />
emulator-5554	device<br />
</code></p>
<p>If there is only one device attached, then you can install the application using ant:</p>
<p><code>niki@redblacktree:~/projects/android/hello$ ant install</code></p>
<p>Which will automatically remove any previous versions installed on the device and install the current build.  Alternatively you can use adb to install the application:</p>
<p><code>niki@redblacktree:~/projects/android/hello$ adb install bin/HelloAndroid-debug.apk</code></p>
<p>This will fail, however, if you have already installed a previous version of the application on the device.  If that is the case, you need to uninstall it first:</p>
<p><code>niki@redblacktree:~/projects/android/hello$ adb uninstall com.examples.helloandroid</code></p>
<p>Note that you must specify the application by the name of its package.</p>
<p>Finally if you have more than  one device attached, (say, a phone and an emulator) then you must specify which device (using the name returned from adb devices) using -s:</p>
<p><code>niki@redblacktree:~/projects/android/hello$ adb -s emulator-5554 install bin/HelloAndroid-debug.apk</code></p>
<p>Now you can just navigate to the application on the emulator or on your phone and run it!  You&#8217;ll notice by default it says &#8220;Hello World, HelloAndroid!&#8221;</p>
<p>That&#8217;s the basics of setting up, building and running an application using the CLI instead of eclipse.  In the next post I&#8217;ll go over release builds and signing your applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aplusbi.com/?feed=rss2&amp;p=164</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Android Development without Eclipse</title>
		<link>http://www.aplusbi.com/?p=161</link>
		<comments>http://www.aplusbi.com/?p=161#comments</comments>
		<pubDate>Thu, 13 May 2010 19:19:44 +0000</pubDate>
		<dc:creator>Niki</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>

		<guid isPermaLink="false">http://www.aplusbi.com/?p=161</guid>
		<description><![CDATA[I have owned an Android-based phone (the G1) for awhile now and have been meaning to develop applications for it since day one. I have finally gotten around to learning how. So far it hasn&#8217;t been easy for me: I don&#8217;t know Java and I don&#8217;t use Eclipse which are the primary development tools for [...]]]></description>
			<content:encoded><![CDATA[<p>I have owned an Android-based phone (the G1) for awhile now and have been meaning to develop applications for it since day one.  I have finally gotten around to learning how.  So far it hasn&#8217;t been easy for me: I don&#8217;t know Java and I don&#8217;t use Eclipse which are the primary development tools for Android.</p>
<p>Fortunately Google released the Android NDK, or Native Development Kit which can be used to program applications in C or C++ and be compiled for the  ARM architecture.  This introduces new complexities however.  The NDK still requires some Java as the compiled code is executed using JNI.  In other words I still need to learn a minimal amount of Java and learn how to interface it with native code.</p>
<p>Finally, most of the information online assumes the use of Eclipse.  Google provides some tools for creating ant build files but I have found the documentation to be lacking a bit.  Through some trial and error I have figured out how to compile the NDK samples and in my next post will present a tutorial for doing so.</p>
<p>Topics so far:<br />
* <a href="http://www.aplusbi.com/?p=164">Creating an Android project from the Command Line</a><br />
* <a href="http://www.aplusbi.com/?p=170">Signing Android applications</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.aplusbi.com/?feed=rss2&amp;p=161</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Glow Artisan</title>
		<link>http://www.aplusbi.com/?p=157</link>
		<comments>http://www.aplusbi.com/?p=157#comments</comments>
		<pubDate>Fri, 08 Jan 2010 21:05:41 +0000</pubDate>
		<dc:creator>Niki</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[work]]></category>
		<category><![CDATA[nitendo dsi game]]></category>

		<guid isPermaLink="false">http://www.aplusbi.com/?p=157</guid>
		<description><![CDATA[A game that I worked on during my time at Powerhead Games was just released: Glow Artisan! It&#8217;s a puzzle game for the Nintendo DSi and it is quite addictive. It has already received a number of glowing (groan) reviews: Nitendo Life 9/10 Game Set Watch If you have a DSi I highly recommend forking [...]]]></description>
			<content:encoded><![CDATA[<p>A game that I worked on during my time at <a href="http://www.powerheadgames.com">Powerhead Games</a> was just released: <a href="http://www.glowartisan.com/">Glow Artisan!</a>  It&#8217;s a puzzle game for the Nintendo DSi and it is quite addictive.  It has already received a number of <i>glowing</i> (groan) reviews:</p>
<p><a href="http://dsiware.nintendolife.com/reviews/2009/12/glow_artisan_dsiware">Nitendo Life 9/10</a><br />
<a href="http://www.gamesetwatch.com/2010/01/dsiware_receives_another_secre.php">Game Set Watch</a></p>
<p>If you have a DSi I highly recommend forking over the $5 to buy it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aplusbi.com/?feed=rss2&amp;p=157</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updated dwm patches</title>
		<link>http://www.aplusbi.com/?p=152</link>
		<comments>http://www.aplusbi.com/?p=152#comments</comments>
		<pubDate>Wed, 09 Sep 2009 19:35:07 +0000</pubDate>
		<dc:creator>Niki</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>

		<guid isPermaLink="false">http://www.aplusbi.com/?p=152</guid>
		<description><![CDATA[After becoming increasingly fed up with Ubuntu I decided to reinstall Debian. I had used Debian for a number of years but eventually left it in favor of Ubuntu as I initially saw Ubuntu as Debian with more complete repositories. At first Ubuntu was quite promising however as I diverged from the default install I [...]]]></description>
			<content:encoded><![CDATA[<p>After becoming increasingly fed up with Ubuntu I decided to reinstall Debian.  I had used Debian for a number of years but eventually left it in favor of Ubuntu as I initially saw Ubuntu as Debian with more complete repositories.  At first Ubuntu was quite promising however as I diverged from the default install I became annoyed at some of the idiosyncrasies of the system.  After attempting to upgrade from Hardy to Intrepid (which requires a graphical installer &#8211; and all the directions/tutorials I found online assume you are using gnome/xfce/kde) I realized that what I really wanted was Debian with some additional external repositories.</p>
<p>In the process of setting up my system I decided to update dwm to the latest version (5.6.1).  There have been some significant changes to dwm since 5.2 including better multi-head support.  Even though I&#8217;m not currently using a multi-head system the changes affected my patches and they needed updating.  The new diff files can be found on the <a href="http://www.aplusbi.com/?page_id=23">dwm projects page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aplusbi.com/?feed=rss2&amp;p=152</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New project: prime number storage</title>
		<link>http://www.aplusbi.com/?p=145</link>
		<comments>http://www.aplusbi.com/?p=145#comments</comments>
		<pubDate>Fri, 10 Jul 2009 01:00:11 +0000</pubDate>
		<dc:creator>Niki</dc:creator>
				<category><![CDATA[math]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>

		<guid isPermaLink="false">http://www.aplusbi.com/?p=145</guid>
		<description><![CDATA[I have added a new project to the projects page: Prime number storage. When I was in college a friend of mine and I came up with a method for compressing and storing prime numbers. While doing research on our method we discovered that it was already in use. However I recently decided to implement [...]]]></description>
			<content:encoded><![CDATA[<p>I have added a new project to the projects page: <a href="http://www.aplusbi.com/?page_id=134">Prime number storage</a>.  When I was in college a friend of mine and I came up with a method for compressing and storing prime numbers.  While doing research on our method we discovered that it was already in use.</p>
<p>However I recently decided to implement it anyway, as it was (and still is) interesting to me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aplusbi.com/?feed=rss2&amp;p=145</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How 21 got the Monty Hall problem wrong</title>
		<link>http://www.aplusbi.com/?p=79</link>
		<comments>http://www.aplusbi.com/?p=79#comments</comments>
		<pubDate>Thu, 07 May 2009 20:00:27 +0000</pubDate>
		<dc:creator>Niki</dc:creator>
				<category><![CDATA[math]]></category>
		<category><![CDATA[monty hall math 21]]></category>

		<guid isPermaLink="false">http://www.aplusbi.com/?p=79</guid>
		<description><![CDATA[Last night I watched the movie 21, based on the book Bringing Down the House, about the MIT blackjack team. There is a scene in the movie in which math professor Mickey Rosa poses the Monty Hall problem to a student, Ben Campbell. Predictably enough Ben is able to figure out the correct strategy and [...]]]></description>
			<content:encoded><![CDATA[<p>Last night I watched the movie <a href="http://www.amazon.com/gp/product/B0018CWW5K?ie=UTF8&#038;tag=abi05-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=B0018CWW5K">21</a><img src="http://www.assoc-amazon.com/e/ir?t=abi05-20&#038;l=as2&#038;o=1&#038;a=B0018CWW5K" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />, based on the book <i><a href="http://www.amazon.com/gp/product/0743249992?ie=UTF8&#038;tag=abi05-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0743249992">Bringing Down the House</a><img src="http://www.assoc-amazon.com/e/ir?t=abi05-20&#038;l=as2&#038;o=1&#038;a=0743249992" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></i>, about the <a href="http://en.wikipedia.org/wiki/MIT_blackjack_team">MIT blackjack team</a>.  There is a scene in the movie in which math professor Mickey Rosa poses the <a href="http://en.wikipedia.org/wiki/Monty_Hall_problem">Monty Hall problem</a> to a student, Ben Campbell.  Predictably enough Ben is able to figure out the correct strategy and realizes that switching doors yields a 2/3s probability of winning the car (which is roughly the same chance you&#8217;ll predict the entire plot of the movie within five minutes).  The problem is, he&#8217;s wrong.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/cXqDIFUB7YU&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/cXqDIFUB7YU&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>At first the error is subtle.  There is not enough information about the behavior of the host to determine whether the best strategy is to switch or not.  The problem is not constrained enough.  This is made glaringly obvious when Mickey Rosa asks &#8220;how do you know he&#8217;s not trying to play a trick on you?&#8221;  If there is the possibility that the host is trying to play a trick on you, then there is the possibility that the host only allows you to switch if you have already chosen the car.  In that case, switching doors would result in a 0% chance of winning the car.</p>
<p>Only when you constrain the problem does it make sense to switch doors.  If (and only if) the host always opens a door, the door always reveals a goat, and the host always offers the player the option of switching does switching result in winning the car 2/3s of the time.  <a href="http://en.wikipedia.org/wiki/Monty_Hall_problem#Bayesian_analysis">Wikipedia</a> has a good analysis of this constrained version using Bayesian products.  (The short answer, the host is essentially giving you the option of switching from your initial choice of one door, to the two remaining doors and if the car is behind one of those two, you win).</p>
<p>Of course if the host only gives you the option to switch when you&#8217;ve chosen the car it won&#8217;t take long for people to catch on, and everyone will win all the time.  It makes more sense for the host to offer a switch when you&#8217;ve selected the car with probability p, and offer a switch when you&#8217;ve selected a goat with probability q.  Thus the host opens the door with probability: <img src='http://www.aplusbi.com/blog/wp-content/latex/201/20112fedb4cb42bc7d095dcaa08605d7-ffffff-000000-0.png' alt='p \times \frac13 + q \times \frac23' title='p \times \frac13 + q \times \frac23' class='latex' />.</p>
<p>Borrowing from the analysis on the wikipedia page, we see that:</p>
<img src='http://www.aplusbi.com/blog/wp-content/latex/e28/e28c647bdacb5d2f8cb701164a8205cc-ffffff-000000-0.png' alt='P(H_{ij}|C_k) = \begin{cases}0 \text{ if } i=j\\0 \text{ if } j=k\\\displaystyle\frac{p}{2} \text{ if } i=k\\q \text{ if } i \neq k \text{ and } j \neq k\end{cases}' title='P(H_{ij}|C_k) = \begin{cases}0 \text{ if } i=j\\0 \text{ if } j=k\\\displaystyle\frac{p}{2} \text{ if } i=k\\q \text{ if } i \neq k \text{ and } j \neq k\end{cases}' class='latex' />
<p>We can now use this new piecewise function to determine the probability of winning the car by switching:</p>
<img src='http://www.aplusbi.com/blog/wp-content/latex/f25/f252e7ac0ea07bd224e7709bb0c146a3-ffffff-000000-0.png' alt='P(C_3|H_{12}) = \displaystyle\frac{P(H_{12}|C_3)P(C_3)}{P(H_{12})}\\P(H_{12}|C_3)P(C_3) = q \times \frac13\\P(H_{12}) = P(H_{12} \cap C_1) + P(H_{12} \cap C_2) + P(H_{12} \cap C_3)\\ = P(H_{12}|C_1)P(C_1) + P(H_{12}|C_1)P(C_2) + P(H_{12}|C_1)P(C_3)\\ = 0 \times \frac13 + \frac{p}{2} \times \frac13 + q \times \frac13 = \displaystyle\frac{p + 2q}{6}' title='P(C_3|H_{12}) = \displaystyle\frac{P(H_{12}|C_3)P(C_3)}{P(H_{12})}\\P(H_{12}|C_3)P(C_3) = q \times \frac13\\P(H_{12}) = P(H_{12} \cap C_1) + P(H_{12} \cap C_2) + P(H_{12} \cap C_3)\\ = P(H_{12}|C_1)P(C_1) + P(H_{12}|C_1)P(C_2) + P(H_{12}|C_1)P(C_3)\\ = 0 \times \frac13 + \frac{p}{2} \times \frac13 + q \times \frac13 = \displaystyle\frac{p + 2q}{6}' class='latex' />
<p>So:</p>
<img src='http://www.aplusbi.com/blog/wp-content/latex/c57/c57851e9034d0e7b03d397e175f4530c-ffffff-000000-0.png' alt='P(C_3|H_{12}) = \displaystyle\frac{2q}{p+2q}' title='P(C_3|H_{12}) = \displaystyle\frac{2q}{p+2q}' class='latex' />
<p>If we let p = 1 and q = 1 (in other words, the host always opens a door) then the probability of winning the car by switching is 2/3s, which is what we should expect.</p>
<p><b>Update</b>:<br />
It makes the most sense for the host to always offer the switch when you&#8217;ve chosen the car (p=1), and to offer the switch when you&#8217;ve selected the goat with probability q.  By solving the inequality:</p>
<img src='http://www.aplusbi.com/blog/wp-content/latex/1a8/1a87f781c2a43d30cddf1df5fafb3b68-ffffff-000000-0.png' alt='\displaystyle\frac{2q}{1+2q} &gt; \frac12' title='\displaystyle\frac{2q}{1+2q} &gt; \frac12' class='latex' />
<p>We find that we should switch when q > 1/2.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aplusbi.com/?feed=rss2&amp;p=79</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>On statements and expressions in OCaml</title>
		<link>http://www.aplusbi.com/?p=74</link>
		<comments>http://www.aplusbi.com/?p=74#comments</comments>
		<pubDate>Fri, 01 May 2009 20:12:15 +0000</pubDate>
		<dc:creator>Niki</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ocaml]]></category>

		<guid isPermaLink="false">http://www.aplusbi.com/?p=74</guid>
		<description><![CDATA[I first tried to learn OCaml after hearing about it in my Programming Languages course in college. I didn&#8217;t get very far beyond the basics at the time for a variety of reasons involving both the language itself and the resources available to me. The problems I had that did not involve the language were [...]]]></description>
			<content:encoded><![CDATA[<p>I first tried to learn OCaml after hearing about it in my <em>Programming Languages</em> course in college.  I didn&#8217;t get very far beyond the basics at the time for a variety of reasons involving both the language itself and the resources available to me.  The problems I had that did not involve the language were not unique to OCaml (except perhaps the lack of available learning material) and were not particularly exceptional.  The problems I had understanding the language however were, and the worst offender was without a doubt the semi-colon.</p>
<p>I had a lot of trouble understanding when to use semi-colons and when I needed one of them or two.  I&#8217;m pretty sure my difficulty with this was not unique either.  It seems to me that very few OCaml tutorials or books go into enough detail with this&#8230;err&#8230;detail and leave it as an exercise for the reader.</p>
<p>Ultimately the problem comes down to the difference between statements and expressions and their relationship to OCaml.  There are a few different definitions of both statements and expressions, so for the sake of this post <em>statements</em> are going to refer to stand-alone elements of a programming language that do not return values (that is, they are evaluated solely for their side-effects) and <em>expressions</em> are combinations of values, variables, functions, etc . that are evaluated and return a value.</p>
<p>In an imperative language like C it&#8217;s easy to see the difference between the two.  An assignment is a statement, an operation is an expression.  It follows from this that statements can contain expressions (such as assigning a variable to the result of an operation) and that expressions can also contain expressions (chaining together operators or using the result of a function as the argument to another).</p>
<p>With OCaml it&#8217;s not so easy at first.  OCaml is a multi-paradigm language and one of those paradigms is imperative programming.  A lot of its syntax resembles the syntax of imperative languages like C, but it does not behave like an imperative language.  In OCaml <em>there are no statements</em>.  Everything is an expression.  Everything has a return value.  Sometimes that return value is of type unit (as in the case of assignment to a reference).  For example, and <em>if&#8230;else</em> block in C does not return a value.  However in OCaml it does &#8211; it&#8217;s value is the last expression evaluated within the block.  This is why the value of the expressions in both the if and the else block much have the same type.</p>
<p>This brings us back to the semi-colon.  The single semi-colon is an <em>operator</em> that behaves similarly to the comma operator in C.  It evaluates the expression on the left side of the semi-colon, then evaluates the expression on the right side of the semi-colon and returns the result of the right-side expression (effectively ignoring the value of the left-side expression).  So <em>(a;b)</em> would evaluate to <em>b</em>.  Since the left-side value is ignored, this is only useful when the left-side produces side-effects (the corollary being that side-effect free OCaml programs shouldn&#8217;t use the semi-colon operator).</p>
<p>The only book I&#8217;ve seen this in is <a href="http://www.csc.villanova.edu/~dmatusze/resources/ocaml/ocaml.html">A Concise Introduction to OCaml</a> which I unfortunately did not come across during my first attempt at learning the language.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aplusbi.com/?feed=rss2&amp;p=74</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The pocketknife paradox</title>
		<link>http://www.aplusbi.com/?p=71</link>
		<comments>http://www.aplusbi.com/?p=71#comments</comments>
		<pubDate>Sat, 18 Apr 2009 17:42:06 +0000</pubDate>
		<dc:creator>Niki</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.aplusbi.com/?p=71</guid>
		<description><![CDATA[A few months ago I was having a discussion with a few friends of mine and the subject of social awkwardness as it applies to telephone conversations arose. I am in many ways a stereotypical nerd and I am no stranger to social awkwardness. I have grown out of the worst of it, but telephone [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago I was having a discussion with a few friends of mine and the subject of social awkwardness as it applies to telephone conversations arose.  I am in many ways a stereotypical nerd and I am no stranger to social awkwardness.  I have grown out of the worst of it, but telephone calls are still difficult for me.</p>
<p>One of my friends could not believe that anyone could have trouble making a phone call or talking to someone on the phone.  At the time he worked in tech support and answered phones for a living.  It came very naturally to him and he had trouble believing that he had some special skill that made him good at his job.</p>
<p>Eventually I came to realize how his attitude mirrored my own, albeit about entirely different subjects.  I often have trouble understanding how some people are unable to understand basic logic or simple math.  It&#8217;s frustrating to encounter an otherwise intelligent person who barely understand a concept as simple as say, division.  There are certain skills that I possess that are &#8220;innate&#8221; (I don&#8217;t know if it&#8217;s genetic or environmental but it doesn&#8217;t matter either way) and that I take for granted.  These skills are so simple for me that I have to fight the temptation to write off as stupid people who have difficulty with the same tasks.</p>
<p>I call this the &#8220;pocketknife paradox&#8221; &#8211; I have a lock-back pocketknife that I typically carry on me.  I have observed that somewhere around half (and I believe it to be greater than half) of the people that I have lent it to are unable to figure out how to close it.  The mechanism to lock the knife in the open position is so intuitive to me that I forget that many people don&#8217;t observe things the same way I do.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aplusbi.com/?feed=rss2&amp;p=71</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
