Saturday, April 19, 2008

Alphabot

A friend of mine had put a this link up in Google Talk status message:

http://playfreeonlinegames.eu/playonline/typethealphabet.html

and his record of 2.84 seconds. In an exhausted state, after having spent a day running after some compatibility issue in some code, my first shot earned me 6.89 seconds.

Huh?!


Deciding to take matters a wee bit more seriously I decided to ... umm... cheat. I wrote this Java code:

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;

public class alphabot {

public static void main(String[] args) {

try {

Robot robot = new Robot();

robot.delay(5000);

robot.keyPress(KeyEvent.VK_A);
robot.keyPress(KeyEvent.VK_B);
robot.keyPress(KeyEvent.VK_C);
robot.keyPress(KeyEvent.VK_D);
robot.keyPress(KeyEvent.VK_E);
robot.keyPress(KeyEvent.VK_F);
robot.keyPress(KeyEvent.VK_G);
robot.keyPress(KeyEvent.VK_H);
robot.keyPress(KeyEvent.VK_I);
robot.keyPress(KeyEvent.VK_J);
robot.keyPress(KeyEvent.VK_K);
robot.keyPress(KeyEvent.VK_L);
robot.keyPress(KeyEvent.VK_M);
robot.keyPress(KeyEvent.VK_N);
robot.keyPress(KeyEvent.VK_O);
robot.keyPress(KeyEvent.VK_P);
robot.keyPress(KeyEvent.VK_Q);
robot.keyPress(KeyEvent.VK_R);
robot.keyPress(KeyEvent.VK_S);
robot.keyPress(KeyEvent.VK_T);
robot.keyPress(KeyEvent.VK_U);
robot.keyPress(KeyEvent.VK_V);
robot.keyPress(KeyEvent.VK_W);
robot.keyPress(KeyEvent.VK_X);
robot.keyPress(KeyEvent.VK_Y);
robot.keyPress(KeyEvent.VK_Z);




} catch (AWTException e) {
e.printStackTrace();
}
}
}



This is an awt robot which can be given the control of your mouse and keyboard. This particular one waits for 5 seconds to let you click or focus your mouse someplace, and then "types" in the letters of the English alphabet.

I compiled it and ran it (as such things go), and before my 5 seconds were up, went to the Webpage to click on 'a' and wait. And , lo! 0.03 secs. Not bad at all ...


This is where I should have ideally finished my post and not written this statement and the few that follow it had I not remembered a puzzle I recently read:

Place 50 balls in 9 boxes so that each box contains an odd number of balls.

At first glance this seems impossible since the sum of an odd number of odd integers cannot be even. Its, however, achievable if you place a box inside another. Talk about a puzzle that forces you to think outside the box to only lead you back to inside one.

Yawn!