Proving that 1/8 Is Larger Than 1/4

Yep, you’ve read that right. Here we go (log below means log10, so log with base 10): 3 > 2 3 log(1/2) > 2 log(1/2) log[(1/2)³] > log[(1/2)²] (1/2)³ > (1/2)² 1/8 > 1/4 Convinced? If not, what’s wrong with the proof above? Click to see solution In reality log10(1/2) is negative, so the second […]

Basics of Permutations

In how many ways can you arrange a group of 4 items? Most people (well, programmers at least) know the answer for that is 24, which is 4!. But what about the more generic case where you have n items and want to permutate only k of them at a time, how many permutations are […]

MySQL Basic Commands

Below you’ll find some basic MySQL commands in case you are new to it. First of all I recommend using the MySQL terminal to connect to your database server, because it forces you to learn the commands by hand. Using a GUI tool like PHPMyAdmin makes the job easier but removes the learning curve. I […]

Facebook Hacker Cup 2012: Alphabet Soup Solution

This code appeared in the Facebook Hacker Cup 2012 – Qualification Round Alfredo Spaghetti really likes soup, especially when it contains alphabet pasta. Every day he constructs a sentence from letters, places the letters into a bowl of broth and enjoys delicious alphabet soup. Today, after constructing the sentence, Alfredo remembered that the Facebook Hacker […]

Facebook Hacker Cup 2012: Qualification Round

This past weekend the Facebook Hacker Cup 2012 took place. I found it was very well organized, and everything was working fine, including the submissions and the scoreboard. If you haven’t participated this year, I highly recommend you do so next year. The qualification round consisted of 3 problems, and any participant solving at least […]

CodeSprint 2 Problem: Subsequence Weighting

Another problem from CodeSprint 2: A subsequence of a sequence is a sequence which is obtained by deleting zero or more elements from the sequence. You are given a sequence A in which every element is a pair of integers i.e A = [ (a1, w1) , (a2, w2) ,…,(aN, wN)]. For a subseqence B […]

CodeSprint 2 Problem: How Many Coin Tosses to Get N Heads?

I am participating in InterviewStreet’s CodeSprint this weekend. It’s basically a 48-hour coding competition. Some of the problems are quite interesting, and I’ll be talking about them here. The first one I tried had this description: You have an unbiased coin which you want to keep tossing until you get N consecutive heads. You’ve tossed […]