I out on a party tonight - so the new puzzle is going to be delayed by a day.
The other thing I am excited about is the Java Treasure Hunt. I think I got the base ready and if things work out as plan there be some really intereting updates soon. I am still thinking of a good name for the event - any suggestions?
Other than tha a few other small changes planned for the blog!!:)
I have extended the deadline for the last puzzle by a day -You might want to have a peek if you have not done so yet :)
Wednesday, May 13, 2009
Twister & Treasure Hunt Updates
Sunday, May 10, 2009
Puzzle 23 – Implement the Unimplemented! (Code Complete – 1)
Language – Java | Type – Problem (Code) | Last date 14-May-2009 9:00 p.m. IST | Points 3
Twisters were started with the objective of having cute Java puzzles – puzzles that are based on really simple principles yet stubble enough to make you pause and think.
However somewhere down the line I though some of the puzzle were too simple – you could just pick the code compile it and punch in the output as the answer. I decided to raise the bar a bit and see how things go.
So here the first puzzle of the new series Code Complete (well its called code complete – because that's what you have to do - complete the code!)
Get this code to compile - You may add (but not delete) any additional amount of code you like with one exception -
you may not implement the getA() method inside the TwistedClass. Feel free to make any other additions!
Commenting out any existing code - is considered as deleting. Cute statements like public class Twisted /*implements TwistedInterface*/ don't count as correct answer thought I really do appreciate ingenuity! -:)
I think this is a tough puzzle – in case you disagree you might want to leave your solution here.
I'd like feedback for this particular puzzle – is it hard or still too easy? Feedback is as always highly appreciated!
Twisters were started with the objective of having cute Java puzzles – puzzles that are based on really simple principles yet stubble enough to make you pause and think.
However somewhere down the line I though some of the puzzle were too simple – you could just pick the code compile it and punch in the output as the answer. I decided to raise the bar a bit and see how things go.
So here the first puzzle of the new series Code Complete (well its called code complete – because that's what you have to do - complete the code!)
package com.twisters;
interface TwistedInterface{void getA();}
public class TwistedClass implements TwistedInterface {
public static void main(String[] args) {
System.out.println("In Main");
}
}
Get this code to compile - You may add (but not delete) any additional amount of code you like with one exception -
you may not implement the getA() method inside the TwistedClass. Feel free to make any other additions!
Commenting out any existing code - is considered as deleting. Cute statements like public class Twisted /*implements TwistedInterface*/ don't count as correct answer thought I really do appreciate ingenuity! -:)
I think this is a tough puzzle – in case you disagree you might want to leave your solution here.
I'd like feedback for this particular puzzle – is it hard or still too easy? Feedback is as always highly appreciated!
Puzzle 22 – Solution
This is a pretty classic puzzle with a pretty classic solution. The program below swaps two numbers without using a temporary variable.
This program works for all values of integer even if we overflow them. Don’t believe me – go ahead and give it a try!!
Congrats to
1. Behive
for getting the right solution.
package com.twister;
import java.util.Scanner;
public class Swap{
public static void swap(int a,int b){
System.out.println("Numbers before change are "
+ a + " and " + b);
a = a + b;
b = a - b;
a = a - b;
System.out.println("Numbers after change are "
+ a + " and " + b);
}
public static void main(String args[]){
swap(new Scanner(System.in).nextInt(),
new Scanner(System.in).nextInt());
}
}
This program works for all values of integer even if we overflow them. Don’t believe me – go ahead and give it a try!!
Congrats to
1. Behive
for getting the right solution.
Wednesday, May 6, 2009
Puzzle 22 - Swap again!
Language – Java/C++ | Type – Problem (Code) | Last date 10-May-2009 12:00 p.m. IST | Points 5
This is one of those classic puzzles …
Write a program that swaps two numbers.
Twist: Do not use a temporary variable while doing the swap.
Think this one is pretty easy? You might want to try out its tougher variation here.
Got an answer? Why don’t you leave it here.
This is one of those classic puzzles …
Write a program that swaps two numbers.
Twist: Do not use a temporary variable while doing the swap.
Think this one is pretty easy? You might want to try out its tougher variation here.
Got an answer? Why don’t you leave it here.
Subscribe to:
Posts (Atom)