Please Watch This Space...

    Please watch this space for more information….

     

    Of course, after a certain amount time, you will notice a slight flicker in this generous whitespace devoid of any tangible information. Given the time and effort spent in your unwavering gaze, much later, the flicker will multiply into various coloured dots. These dots are a temporary phenomenon called retinal tear.

    But please do continue watching the space. Your answer will reveal in a couple of hours when you hear muffled giggles from the corner of your eyes. This means you have kept yourself still long enough to warrant attention from your colleagues. You have become an imminent and potentially future source of subversive humour. Let this insight not detract you from your current task at hand. Please continue watching the space.

    The passage of time might seem glacial, but it might have been only a few days elapsed since you embarked on this endeavour. The strange tickling sensations tracing a halo-like pattern around the crown of your head might be cobwebs-in-the-making by some opportunistic spiders. The occasional shrill noises at night might not be the usual crickets after all, but little rats ogling at you. The pithy tch, tch from the ceiling might be the most patient audience of them all, the stunned household lizards. They produce these sounds only when they are amazed at some still life which rival their own stillness, out of pure jealously, obviously. However, the good news is that the worst is probably over. So, please continue watching this space.

    In the midst of all this, please do not be surprised, if the prolonged presence of the white’space' burnt a hole on your LCD screen. This is perfectly natural and probably for the better. You will now have the unrestricted viewing pleasure of an actual space right in the middle of your screen. This is a real ‘window’ and gladly enough, cannot be closed or minimized by any means. This is wonderful news for a patient observer like you. So, please continue watching this space.

    In the meanwhile, the human race which, in evolutionary terms, quite recently got an upgrade from their always quibbling, tree jumping cousins, would have found themselves engaged in a major war of some kind. As a non-participant to this frivolous event, you would probably be quite indifferent to the comical sounding sirens around your place.

    Suddenly through the little window you have been gazing, somewhere in the distance, you might notice a bellowing angry red mushroom cloud. This might be accompanied by a brilliant bright flash of light. But…

    Please, please continue watching this space!

    Comments →

    The Dying Art of Talking Simple

    I am reading an excellent book called Presentation Zen by Garr Reynolds. The book arrived in Mangalore library last week thanks to our wonderful librarian :). The book is a feast for the eyes with its stunning images and beautiful typesetting.

    I read a very interesting passage from the book about the need for clarity of communications. The book says:

    Look at these two messages that address the same idea. One of them should seem very familiar to you.

    a. “Our mission is to become the international leader in the space industry through maximum team-centered innovation and strategically targeted aerospace initiatives."

    Or

    b. ”…put a man on the moon and return him safely by the end of the decade."

    The first message sounds similar to CEO-speak of today and is barely comprehensible, let alone memorable. The second message – which is actually from a 1961 speech by JFK – has every element of SUCCESs and it motivated a nation toward a specific goal that changed the world. JFK, or at least his speech writers, knew that abstractions are not memorable, nor do they motivate.

    There are many examples where I have read 2 to 3 page/screen emails without understanding a word of what they are trying to say. Communication has deteriorated to the point that we are now extremely thankful when someone can explain the gist of the message in a few words.

    The worst thing that can happen is the spread of this culture of obfuscation to the next generation. If that happens, we will lose the art of communicating ideas simply and the real message will be drowned in the noise.

    PS: Recently I delivered a talk on Relevance of IT in Business and used Presentation Zen ideas in my slides. The slides were well received and appeared on Slideshare homepage as well.

    Comments →

    5 gifts to get from your friends in USA

    From an Indian perspective, it will be very hard these days to think of a product which is not available in India. Be it gadgets or books, there are the several websites where one can order imported goods online.

    I had earlier sought suggestions for things to buy from USA which is not easily available in India. After much research, I realised that most of the things in USA are made in China. Well, no surprises there :). After some more serious research, I was able to come up with some items which are not easily available in India, yet have a really good value for money.

    This was 6 months ago. Fast forward to the present and the goodies bag have finally arrived. Let me list down it’s contents:

    • Leatherman Skeletools CX : One of the lightest multi-tools having a knife, wire cutter, universal bit driver (screwdriver) and bottle opener that fits your pocket. Has 25 years warranty

    • Stylus pro: Lightweight ultra-bright pen flashlight made of aircraft aluminium. Uses normal AAA batteries.

    • Board games (Pandemic, Carcassone, San Juan): Some of the most innovative and educational games ever developed for children and adults alike are not computer games but Board games. These three are probably the highest rated (at least two-player) and best value for money I could find.

    • Pound of Dice 100 Pieces: Are you into RPG games? Need a 20 or 30 sided dice? This might be the cheapest way to get a decent collection of dice. You will never be short of dice anymore.

    • Dragon Shield 100 Sleeves : This is for those innovative card games that one might design one day. Need sleeves for your freshly cut card printouts? Look no further.

    It is an eclectic collection, matching my tastes; but I hope there is something for most people here.

    Comments →

    Mars Rover in Python and Haskell

    Last week I tried to do something which I’ve been planning for quite sometime. Porting a Python program into Haskell. In case you didn’t know, Haskell is a purely functional programming language that’s recently become a hot favourite. It has a lot of cutting edge ideas from the academic world esp laziness and strong typing. It has an interesting way to solve the ‘multi-CPU problem’.

    Mars Rover is a famous programming problem used by Thoughtworks in their recruitments. I first solved the problem in Python and later attempted to solve the same in Haskell. I cannot say that I ported it from Python because the approach I’ve used is completely different.

    The Problem

    A squad of robotic rovers are to be landed by NASA on a plateau on Mars.

    This plateau, which is curiously rectangular, must be navigated by the rovers so that their on-board cameras can get a complete view of the surrounding terrain to send back to Earth.

    A rover’s position and location is represented by a combination of x and y co-ordinates and a letter representing one of the four cardinal compass points. The plateau is divided up into a grid to simplify navigation. An example position might be 0, 0, N, which means the rover is in the bottom left corner and facing North.

    In order to control a rover , NASA sends a simple string of letters. The possible letters are ‘L’, ‘R’ and ‘M’. ‘L’ and ‘R’ makes the rover spin 90 degrees left or right respectively, without moving from its current spot. ‘M’ means move forward one grid point, and maintain the same heading.

    Assume that the square directly North from (x, y) is (x, y+1).

    INPUT:

    The first line of input is the upper-right coordinates of the plateau, the lower-left coordinates are assumed to be 0,0.

    The rest of the input is information pertaining to the rovers that have been deployed. Each rover has two lines of input. The first line gives the rover’s position, and the second line is a series of instructions telling the rover how to explore the plateau.

    The position is made up of two integers and a letter separated by spaces, corresponding to the x and y co-ordinates and the rover’s orientation.

    Each rover will be finished sequentially, which means that the second rover won’t start to move until the first one has finished moving.

    OUTPUT

    The output for each rover should be its final co-ordinates and heading.

    INPUT AND OUTPUT

    Test Input:

    5 5
    1 2 N
    LMLMLMLMM
    3 3 E
    MMRMMRMRRM

    Expected Output:

    1 3 N
    5 1 E

    The Python solution

    The Python solution is actually smaller than the problem itself. The readability isn’t that great, but it is quite extensible. In fact, adding a new instruction like B(ackward) would need just one additional line. You can also extend the four cardinal directions to eight with minimal changes to the code.

        
    dirs = "NESW"                   # Notations for directions
    shifts=[(0,1),(1,0),(0,-1),(-1,0)] # delta vector for each direction
    # One letter function names corresponding to each robot instruction
    r = lambda x, y, a: (x, y, (a + 1) % 4)
    l = lambda x, y, a: (x, y, (a - 1 + 4) % 4)
    m = lambda x, y, a: (x + shifts[a][0], y + shifts[a][1], a)
    raw_input()                     # Ignore the grid size
    while 1:
        # parse initial position triplet
        x, y, dir = raw_input().split() 
        pos = (int(x),int(y),dirs.find(dir))
        # parse instructions
        instrns = raw_input().lower() 
        # Invoke the corresponding functions passing prev position
        for i in instrns: pos = eval('%s%s' % (i, str(pos)))
        print pos[0], pos[1], dirs[pos[2]]
    

    The Haskell solution

    I am a beginner in Haskell, so apologies for any bad coding practices. You might notice that rather than using Reflection as in the Python code, I have used Type-inference to invoke the correct function for each instruction. Yet again, this scales well while adding new instructions.

        
    import Data.List
        
    dirs = "NESW"
        
    shifts 0 = (0, 1)
    shifts 1 = (1, 0)
    shifts 2 = (0, -1)
    shifts 3 = (-1, 0)
        
    instrn (x, y, a) 'R' = (x, y, mod (a + 1) 4)
    instrn (x, y, a) 'L' = (x, y, mod (a - 1 + 4) 4)
    instrn (x, y, a) 'M' = (x+fst (shifts a), y+snd (shifts a), a)
        
    showpos (x, y, a) = show x ++ " " ++ show y ++ " " ++ [dirs !! a]
    finddir dirchar = 
        case elemIndex dirchar dirs of
          Nothing -> error "invalid direction"
          Just position -> position
    readpos line = (x, y, a)
            where a = finddir $ head $ drop 1 line3
                  [(y,line3)] = reads line2 :: [(Integer, String)]          
                  [(x,line2)] = reads line :: [(Integer, String)]
        
    robo = do
      posn <- getLine
      instrns <- getLine
      putStrLn (showpos (foldl instrn (readpos posn) instrns))
      robo
        
    main = do
      skip <- getLine               -- Skip reading the grid size
      robo
    

    Key learnings

    Since some of you might be interested in Haskell, I have tried to summarize my experience in Haskell programming

    1. There are no loop constructs. So everything must be done using recursion!
    2. Haskell I/O is very hard. This is because of my little knowledge of Monads. In fact, I solved the logic pretty quickly. It took me a while to figure out the input parsing.
    3. Type inference catches a lot of errors. This is quite handy but error messages are sometimes confusing
    4. I could have used Abstract Data Types for directions but it would have made the code lengthier

    In short, programming in Haskell is a mind-bending exercise. Highly recommended!

    Comments →

    The Trainees

    They started with fifteen cats. They were the finest, whitest, softest, cutest cats you can ever imagine. They would purr when stroked liked the sweet purring of a stroked cat. Except with extra cuteness that could only come from the finest breeds. Each one was hand-picked from various homes after a lengthy selection process. The Feline Resources Department visited around three hundred homes. They found only fifteen because the rest were an abomination to the word Cat. They were neither cute nor soft. I mean, what sort of a cat is neither cute nor soft? They were rejected immediately. The remaining fifteen were perfect - for work.

    Most hamsters were shocked to find cats at their office. After all, it was an office of hamsters. Every hamster had their own personal cage-icle and wheel. The perks were also good. The company had provided free flax seed machines at every floor. The cage farms were massive, sprawling and impressive structures. One had been designed like a inverted pyramid with the upper cages almost defying the laws of physics. One had a gigantic blue gel-filled sphere in the middle. Nobody knew what the sphere meant. Many thought it was aesthetically pleasing, while many also thought that it was a bloody waste of space.

    The older be-speckled hamsters raised an eyebrow when the new joinees cat-walked into the aisle. Could this be the end, they wondered. There is only so much that their tiny arthritis-ridden legs can run. Besides they weren’t getting any thinner with all the free flax and junk food. There is only so much that a wheel can carry. Some even did a mental math of the remaining instalments to their pension funds.

    The group was led by a particularly slender and attractive cat. She halted outside the Animal Resource Head’s door. The head, an elderly hamster motioned her inside. She smiled demurely as she confidently walked into his cabin accompanied by the rest of the clowder. The discussion lasted for about an hour.

    Finally, the leader exchanged pleasantaries and stepped out of the room with the dossier for their first assignment. With an expression of disbelief she opened the file and read their objective:

    PRODUCE 15 HAMSTERS IN ONE MONTH

    Comments →

    « Newer Page 15 of 39 Older »