Thoughts on Test Driven Development

There is a simple process to follow for TDD (a.k.a. Test Driven Development). It’s relatively simple to follow and understand and is somewhat a standard in the software development industry:

  1. Think: Find out what test will move code towards completion.
  2. Red: Write short test code and watch it fail.
  3. Green: Write short production code. This can even be hard-coded initially just to watch the test pass.
  4. Refactor: Now that tests are passing, you can refactor the code without risking breaking anything. Run the test every time you change code to see if the tests still pass.
  5. Repeat: Goto 1. And again, and again.

This works well because you’re following a very standard baby-step-based TDD process wherein you’re constantly generating a new hypothesis and checking it. This also helps you to always think about design, which is a good thing!

Posted in Uncategorized | Leave a comment

Google Interview Question – Pattern Matching With Strings

Problem Statement: Imagine you were given a set of strings [“HiHello”, “HelloYou”, “HelloYouThere”]. Create a pattern matching algorithm that would match one or more of the strings on input like “HH”, “HY” and “HYT.”



Posted in Uncategorized | Leave a comment

Reading a non-standard input format with C++

Previously, I have written about the power of Java’s BigInteger class. Now, I would like to express my love for C++ with a small demonstration of it’s amazing abilities. Especially the use of a trivial and commonly ignored functions that you’ve all seen before, to do something extraordinary!

Problem statement: The first line of input is an integer N. This is followed by N lines, each starting with the character ‘0’, followed by a dot ‘.’, then followed by an unknown number of digits (up to 100 digits), and finally terminated with three dots ‘’.

Sample Input:

To solve the problem, we can quickly whip up a C++11 program as follows:

To test the program, you’ll have to run it as follows:


Posted in Uncategorized | Leave a comment

Java to the rescue with BigInteger!

Though I love programming with C++11, sometimes, it gets annoying and I’d very much rather solve a specific problem in Java because of the amazing libraries and classes it has. One such example is the Java BigInteger class that has saved me my a lot of hassle.

Try writing a program that can calculate 25! (25-factorial). The result is so big, it won’t even fit in a long long int. That’s where Java gets handy.

Result: 15511210043330985984000000 (This is 26-bytes in size whereas long long int can store 64-bits or 8-bytes)

Posted in Uncategorized | Leave a comment

Why all this fuss with Java I/O?

If you’re new to Java programming, you’ll notice that I/O in Java seems a little convoluted at first, and you may ask “Why?” Here is how it works:

  1. InputStream objects (like read raw data from various input sources without formatting the data.
  2. InputStreamReader objects format the data into characters (which are typically 2 bytes long).
  3. BufferedReader objects compose the characters into entire lines of text.

Here is a simple Java class that echo’s an input line:


Posted in Uncategorized | Leave a comment

Project Euler – Problem 9 – Special Pythagorean Triplet

Problem statement:

This one seemed rather easy. The code doesn’t do one of the necessary checks (a < b < c), but it was easy to eliminate that by eye.


Posted in Uncategorized | Leave a comment

Hello world!

Welcome to WordPress. This is your first post. Edit or delete it, then start writing!

Posted in Uncategorized | 1 Comment