Tuesday, July 31, 2012

Insertion sort in python

This is my implementation with a lot of comments for insertion sort implementation in python. Hopefully the comments can help people understand insertion sort better (like the reason for starting at index 1). You can also view it here https://gist.github.com/3216903 :

Monday, July 23, 2012

8 balls problem and solution

Given 8 identical balls, there is a fake ball, which may be either heavier or lighter. Assume that there is a balancing-scale available.
To identify the fake ball,
1.) how many rounds of comparisons are needed?
2.) how many rounds of comparisons are required if the number of balls is n?

A useful definition :
A control ball : A ball that did not cause the scale to tip. Since we know that there is only one ball that is different  select a control ball intuitively form the n-1 possible ones.

1.) 3 weighings.
Number the balls 1-8
  • Weigh 1-2 / 3-4 Three outcomes: 
    • 1-2 is lighter : Weigh 1 / 2 . Three outcomes: 
      • 1 is lighter. Yup then 1 IS lighter 
      • 2 is lighter. Yup then 2 IS lighter
      • Equal. Well weigh 3 / 4 and one is bound to be heavier :) 
    • 3-4 is lighter : proceed same as 1-2 is lighter. 
    • Equal - Weigh 5-6 Three outcomes: 
      • 5 is lighter : Weigh against a control ball (any from 1-4). If same 6 is heavy otherwise 5 is light. 
      • 6 is lighter : same as 5 is lighter 
      • WORST CASE equal: Weigh 7 and a control ball (any from 1-4). Answer should be evident. 
Since in each step you split your sample space in half.  So in general you need log(n,base2) steps. 

Further analysis
If you know whether the ball is heavier OR lighter the weighings reduce to log(n) -1. Also if you need to know whether the fake ball was heavy or light (not just identify the ball). You will need one more weighing, in case 7 was not fake, you would know 8 is fake but not if its heavy or light.

Bad approach
The first intuition is to try and weigh 4 balls / 4 balls instead of 2 balls / 2 balls shown here. The problem with 4/4 approach is that you do not know which particular set of balls have a problem. You only find the direction of the problem for a set of 4 balls. You need to focus on discriminating the balls and that will intuitively lead you to a classification of 2 / 2 balls initially which tells you WHICH 4 balls have the problem.

Friday, July 20, 2012

Manage remote audio in Skype on Mac OSX

Disabling your microphone is a common task that you can do from the Skype call window. This is not what this post is about.

Sometimes you just want to look at the Skype camera and not listen to the audio feed from the other side. This is super easy to do with Skype on Mac OSX. Go to skype -> Preferences -> Audio / Video and adjust the volume as shown:

This volume is independent of your computer volume.

Optionally you can use the quick keyboard shortcuts Command Option Up / Command Option Down. You get a nice indication of the current volume :

Monday, July 16, 2012

Getting the bleeding edge of MonoTouch / MonoForAndroid

If you want to know which version of MonoTouch you have installed you can find that in MonoDevelop using About MonoDevelop:

And click on Version information: 
You can see that my Monotouch version is 5.2.12 which as of this writing is the latest stable version. But in case there is a feature you badly want in the beta / alpha version you can switch over to those quite easily. 

Going Bleeding Edge
Just start MonoDevelop and go to Check for Updates as shown:

Next, now change your Update channel: 
And you will be able to see the Beta / Alpha version available. If you like what you see. Just click on Switch Channel as shown: 

It will start downloading and running the updates. Enjoy!

Sunday, July 15, 2012

Useful bookmarks for MonoTouch

Just in case its useful to have these links handy :

A list of bugs that have been already raised:

A list of bugs that were fixed in each release:

Friday, July 13, 2012

Setting up Git with MonoDevelop on Mac OS X

MonoDevelop on Mac ships with Git integration built in.

As an aside: My preferred source code provider is https://bitbucket.org/ because they provide unlimited free private repositories. I obviously use the same account for my open source projects as well. So this is the provider I tested.

First of all create a new git repository on BitBucket. Note down the git url as highlighted below:

Now open up MonoDevelop and select Version Control -> Checkout as shown:

Next select Registered Repositories and select Add and then in type Select Git as shown:

Next Copy paste that git url in the url field as shown, This will automatic fill most of the fields for you (cool) :

Just type in the Name (already shown in the previous image MondrianEvolved) and click Ok.

Next specify the newly added repository and select the target directory as a new directory you want created for this repository (make sure you end on /):

Click Ok, And when prompted type in the password as shown:
Your project will download. You are ready to rock and roll :

Most git operations, you can now do from the context menu as shown:

And overall operations from the Menu :

commit messages:

And push changes:

Also if you are doing Git/Hg on Mac OS X I highly recommend you check out SourceTree : http://www.sourcetreeapp.com/
It picks up where MonoDevelop leaves off.


Sunday, July 8, 2012

Uninstalling an application in Mac OS X

The standard way that people uninstall an application in Mac OS X is to simply drag an application from the applications folder into the trash.

This however can leave preference files used by the application behind. These file are generally stored in Library/Preferences  folder (since Mac OS X does not have a concept of a registry).

To ensure that these files are also removed when you delete an application take a look at a neat little free application called AppTrap : http://onnati.net/apptrap/

Thursday, July 5, 2012

Disabling reopen closed windows in Mac OS X

By default Mac OS X Lion reopens any windows that an application had open once you quit an application (command Q) unless you close the windows (command W) before quitting the application. 

This is extra annoying with preview since you open an image, Close the application, open another image and now you will suddenly have two images open. 

You can disable this option from system preferences and unchecking "restore windows when quitting and re-opening applications" as shown below. 

Wednesday, July 4, 2012

Notepad / Wordpad on a Mac

There are third party tools but by default Mac comes with TextEdit which is more like wordpad instead of notepad. 

To use TextEdit as notepad you can switch to plaintext by going to preferences and changing to plaintext mode. 

The keyboard shortcut for this is : Shift Command T 

Tip for studying at ANU

I am currently enrolled in the Master of Computing (computer science) program at ANU (Australian National University). It is useful to know what to expect in which course. Here are a couple of links that an help you in determining that:

For finding out how other students have rated each course:

For past exam papers: