Skip to main content


Showing posts from November, 2013


The probability that at least two people share their birthday in a room of 23 people approximately 50% This is a pretty famous combinatorial problem, mainly because it is so counter intuitive.
Classic Combinatorial Method: If we were to use the classic combinatorial method to solve this problem, we would start by finding the probability that none of the n people share their birthday. The probability is,

Now, the probability that at least two people share their birthday is,

After some cancellation, the result is,

Monte Carlo Method:  First, create several "rooms" with n number of people. Randomly generate their birthday. For simplicity purposes, generating random integer from 1-365 is a good approach. Finally count the number of "rooms" where at least two people shared their birthday. The Monte Carlo Method estimates,

The result is (not always),

Java: importjava.util.ArrayList;importjava.util.Date;importjava.util.HashSet;importjava.util.Random;importo…


When designing an interface for an app or a website, the hex values for colors are needed. I just wanted a tool that allowed me to play around with hex values and see the result color. The main purpose for coding this was to experiment with WebView in Android. It also felt like a fun little 2-3 hours why-not-just-do-it project.
The three Slide bars correspond to Red, Green and Blue values respectively. First of all, a html script with background color information based on SlideBar inputs is generated. The Web View then uses the generated html script to build a html web-page.
Users can also use the EditText and Submit button to input hex values. Initially, I had not planned on putting this functionality. I later decided to add it because several people were giving bad ratings to similar app in the appstore for missing it. Also, it was a fairly simple addition.

Option 1: Slide the SeekBars to get required values.  For example, when Red SeekBar is changed:



After reading Uncle Petros and Goldbach's Conjecture, I wanted to write a program that would break an even number into two primes. However, I also decided to add functionalities like prime tests and my favourite functionality of all time - Real Random Generator (here: Real Random Prime Generator).
Part one: Primality Test

Depending on the size of the input string, two algorithms were implemented:

try{long inputhere = Long.parseLong(input);if(isPrime(inputhere)){}else{}}catch(NumberFormatException ee){if(probablePrime(input)){}else{}}
If the input string can be parsed into a long type, the following method was used:

booleanisPrime(long n){if(n <2)returnfalse;if(n ==2|| n ==3)returntrue;if(n %2==0|| n %3==0)returnfalse;long sqrtN =(long) Math.sqrt(n)+1;for(long i =6L; i <= sqrtN; i +=6){if(n %(i -1)==0|| n %(i +1)==0)returnfalse;}returntrue;}
If not, the input was cast into a BigInteger type and the following method was used:

booleanprobablePrime(String input){returnnewBigInte…


After missing couple of English Premier League Games due to the time difference between what I was used to and Nepal, I thought it would be wise to create an app that kept track of all Premier League fixtures in Nepal time.  
Step 1: Extracting, Parsing and Storing Since I wanted the fixtures to be available offline, I had to find a way to extract and store the data. After trying several implementations, I decided to use a csv file that I found online. I used CSVReader to parse through the csv file and added required html tags to change everything into web pages.The plan was to use WebView in android to display the fixtures.

For example, the follwing java code prints a full webpage for the month of October.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38;;;importjava.util.Calendar;;publicclass…