Wednesday, February 25, 2009

Puzzle 2 –Divide and (Multiply) Rule

Language – Java | Type – Concept | Last date 4-Mar-2009 9:00 p.m. IST | Points 2

I always considered myself to be good at algebra. I had no problems with equations, trigonometry and multiplication. But it takes Java to make simple algebra tricky. Do you know what this code does and why?
package com.twisters;
public class MulAndDiv {
public static void main(String[] args) {
double result;
result = 2.0*2/4+2/4;
System.out.println("The result is : "+ result);
}
}


Puzzle 1 - Solution

The key to solving this puzzle is ' Ascii Characters have a numeric equivalent.'

Solution 1 - A simple approach is to print the Ascii Value of 'W' directly.
package com.twisters;
public class Hello {
public static void main(String args[]){
System.out.println("Hello "+(char)87+"orld");
}
}
Solution 2 - You can make use of the overloaded '+' operator to perform character additions.
package com.twisters;
public class Hello {
public static void main(String args[]){
char letter = 'V' + 1;
System.out.println("Hello "+letter+"orld");
}
}
Solution 3 - A cheeky solution is to use double 'U' to form a 'W'
package com.twisters;
public class Hello {
public static void main(String args[]){
System.out.println("Hello UUorld");
}
}
Congrats to
1. COMMANDER RV
for getting the right answer.

I'll be putting up a score board soon. Stay tuned for the next puzzle...

Sunday, February 22, 2009

Puzzle 1 – Hello World

Language – Java/C++ | Type – Problem (Code) | Last date 25-Feb-2009 9:00 p.m. IST | Points 5

Well here I was trying to write my first Java code. I was pretty excited. I started typing just to realize that the ‘W’ key on my keyboard wasn’t working. That’s when I had to write my Hello World code without a ‘W’. Do you think you can help me out with this?

Write a program to print “Hello World”.
Twist: Do not use the letter ‘W’ or ‘w’ in the source code.

Pretty simple stuff, but then it’s just the beginning of a long journey …

Saturday, February 14, 2009

Twister - Updates

Technically there should just be questions and answers out here. Practically that’s not what is going to happen.

I’m going to add start up news, general updates, even tips and tricks and my latest work (everything in Java of course).

I like to give myself around a week to set this up. The first question should be up and ready by 22 Feb 09 which I like to consider as the ‘official’ start date of Twisters.

So get ready for the Twister Xperience!