Facebook Hacker Cup : Studious Student Problem Solution

Photo CreditPhoto Credit : Helen Morgan

The Third and final problem of the Facebook Qualification 2011 Round was Studious Student. The problem goes like this:

Studious Student

You’ve been given a list of words to study and memorize. Being a diligent student of language and the arts, you’ve decided to not study them at all and instead make up pointless games based on them. One game you’ve come up with is to see how you can concatenate the words to generate the lexicographically lowest possible string.

Read More …

Facebook Hacker Cup : Peg Game Problem Solution

Continuing with my earlier solution of the First Problem “Double Square”, here is solution and analysis for Second Problem “Peg Game”

Peg Game

At the arcade, you can play a simple game where a ball is dropped into the top of the game, from a position of your choosing. There are a number of pegs that the ball will bounce off of as it drops through the game. Whenever the ball hits a peg, it will bounce to the left with probability 0.5 and to the right with probability 0.5.

Read More …

Facebook Hacker Cup : Double Squares Problem Solution

A lot of people have participated and qualified in Qualification Round of Facebook Hacker Cup. Luckily I am also qualified for First Round. Facebook Hacker Cup Qualification Round consisted 3 problems. All of these problems were programmatically easy but tricky. Lots of people made very simple mistakes while solving these problem(including me).

First Problem of the round was:

Double Squares

A double-square number is an integer X which can be expressed as the sum of two perfect squares. For example, 10 is a double-square because 10 = 32+ 12.

Read More …

RegEx to Convert String in TitleCase (Python / Django)

During web development I very often come across a problem to convert any string into TitleCase. Those who don’t know title case is the style of writing having first letter as a majuscule (upper-case letter) and the remaining letters in minuscules (lower-case letters).

So here is the python function to do that:

def title(value):
    """Converts a string into titlecase."""
    t = re.sub("([a-z])'([A-Z])", lambda m: m.group(0).lower(), value.title())
    return re.sub("\d([A-Z])", lambda m: m.group(0).lower(), t)

Happy Coding

Read More …

Introducing PNRCheck.com

I don’t know when this picture was taken, or is it actually of India or not, but condition of Indian Railways is not a lot different from this. The trains are always crowded, and it is difficult to get reservation in train. Every train traveler might faced the problem of non-availability of tickets in Indian Railways. Anyways, here I am not going to discuss the condition of Indian Railways.

In this post I want to Introduce one of the web-service which I built for my use, and I think it would be useful for you as well.

Read More …

Energy Saving Javascript

Energy Saving ScriptTitle of this post may seem strange to you but this is true, You can actually save some energy by using this Javascript on your website. Let me tell you how.

This javascript turns the webpage black if there is no user activity on the page for some time. As the page predominantly turn black the script in-effect saves energy.

Image displayed is primarily a function of the user’s color settings and desktop graphics, as well as the color and size of open application windows; a given monitor requires more power to display a white (or light) screen than a black (or dark) screen.

Read More …

WordPress Hacks : Export and Redirect Posts based on their Category

wordpress

WordPress is an excellent blogging engine. It is easy to setup and even easier to use. It has got a huge collection of themes and plugins. Because of all these things WordPress has got so widespread use.

WordPress has the concept of categories to segregate posts in different types.  When number of posts in some category becomes really huge, its good to make a separate website for this particular category.

I faced similar problem for one of my website and I decided to migrate all of my posts in “XYZ” category to a different domain.

Read More …

Sexy Tooltip using CSS3 (no images)

CSS is Awesome, but “CSS3” is Awesomely Awesome.

With CSS3 we can make our pages even more beautiful without using additional images and extra markup.

In this post I have tried to make tooltips using CSS3. This is just a sample implementation for tooltip, you can have even better variants.

Read More …