07 September 2011

Mobme Codejam - Solutions

    I hope you have read about Mobme Codejam here. 
Here are my solutions to some of the contest problems.

Mirror
    Write a program which when given links to two images on the Internet, finds out how similar they are.
Bonus points if it ranks images on a similarity scale from 0 - very different to 100 - exactly the same. 
Here is my Solution

Ternary
    Write a number generator that keeps printing out 10 digit numbers, one in each line. Write a second program called filter that takes the output of this number generator and filters it based on its first digit: if the first digit starts with 0, write it to a file named 0.txt, if the first digit is 1, write it to a file named 1.txt, and so on. Write a third program that when run keeps a watch on these files and prints out the count of numbers in these files every second.
Note: Three separate programs are required here.  
Here is my Solution

Tricolour
    Write a program which will generate the Indian national flag. 
Here is my Solution


Spell
    Write a spell checking program which checks an input text with help of an English dictionary. Remember: the spell checker is better if it manages to catch the most likely errors.
[Bonus points if you use cool data structures, like say, a Bloom filter] 
Here is my Solution

Sandbox
    Write a simple TCP server that supports the following commands:
  • list - Lists all the files in the directory the server is running on.
  • pwd - Print the path of the directory the server is running on.
  • cat - Print the contents of the filename given as argument.
  • rm - Delete the filename given as argument.
  • touch - Create a file with name and content given as argument.
  • time - Returns the current time on the server.
Also implement a simple client program that uses this server. The client must create a file every minute on the server with a random filename and with the content being the current server time. 
Here is my Solution

Invariant
    Consider the following process done on 4 digit numbers:
Take any four digit number which has at least 2 different digits. (1111 is not allowed, but 1112 is)
Arrange the digits first in descending order to get another 4 digit number (2111) and then in ascending order to get one more four digit number (1112). Add leading zeroes if necessary.
Subtract smaller number from the larger number (eg: 2111 - 1112 = 0990)
Repeat from step b
Example - Starting with 1112
2111 - 1112 = 0999
9990 - 0999 = 8991
9981 - 1899 = 8082
8820 - 0288 = 8532
8532 - 2358 = 6174
It’s an interesting fact that this process when done on 4 digit numbers always ends up at 6174 after a few iterations. In the example above, 1112 took 5 iterations to evaluate to 6174.

Write a program that performs the above operation on all valid 4 digit numbers from 1000-9998 and find out how many iterations it takes each number to evaluate to 6174.

Also: print a frequency distribution table with number of iterations needed to reach 6174 as one column and the total count of numbers corresponding to that iteration as another. [Bonus marks if you can represent this as a nice looking graph.]
Example Output:
Iteration Total Count of Numbers
    1       10
    2      151
    3      240

Here is my Solution 
Here is the github hub of the solutions - https://github.com/jithusunny/Mobme-Codejam

No comments: