Programming Archives

Java Implementation of “Inception”

Posted on August 14, 2010 at 21:14 Java 2 Comments

Inception

Feedback from friends, positively spoken and written (statuses), kept me wondering what the movie really was all about. I never set my eyes on it because the trailer didn’t intrigue nor enlighten me as a layman. But as it turns out, it’s way more nerve-wracking than you can think of.

After seeing a pseudocode post from my adviser and visiting the big screen, I knew I just had to make my own — a recursive one. To experience euphoria, I dug an implementation. What the program does is very simple. It asks for the levels of dream you wish to experience, and then prints out the time spent on each level. You’ll see…

Inception.java

void dream(int level) {
   if(level <= 0) {
      return;
   }

   try {
      System.out.print("Level " + level + ": ");
      long startTime = System.currentTimeMillis();
      Thread.sleep(1000*level);
      long endTime = System.currentTimeMillis();
      System.out.println((endTime-startTime) + " ms");
   } catch(InterruptedException ie) {}

   dream(level-1);
}

Running C and gcc in Windows (XP)

Posted on July 21, 2009 at 23:25 C No Comments

If you’ve been conditioned that coding and running C codes in Windows is nearly impossible, think again. It’s actually as easy as X-Y-Z (c’mon people, A-B-C is so yesterday).

Continue reading…