Looking for the big game

On Jan 17th, while on a trip to mumbai for a friends wedding, I got a call from a friend whom I hadn’t talked to for almost 8 months. After the “where were you dude?” and “whats happening” conversation he suddenly switched to a more controlled vocal meter and began. ” I attended landmark forum and….

hmmm” I thought, “this I guess is the real reason for his call“.
Controlling my skepticism, I heard him out.

After sharing a little about his experience, he invited me for a Tuesday evening free session to introduce me to the course. Being a friend he warned me that there would be guerrilla marketing going on, but he would protect me as much as possible. I wasn’t too inspired, but hell, what else does one do on a Tuesday evening?

So Tuesday came, and the reminder call came, and I reached, albeit a little late. Surprisingly they started on time, and warned us in the beginning that it would go quite late. After a little gyan, the presenter asked for a volunteer. One bakra raised his hand and went on stage. What followed was really quite gripping. Starting with the volunteer’s complaint against the world, the presenter stripped away the layers of lies and half truths through conversation, until all that was left was the real person and his false perception of his world, and everyone in the audience knew that the message was meant for us all. In the end I found myself pressed back in my chair, as if I had been attacked, I didn’t understand my emotions at that time but I was interested. I saw the credit-card-swiping machine and swiped away a weekend of my life to landmark.

Two weeks later, without any expectations at all, and 10 minutes late, I found myself in a room of 230 people from all walks of life, Medicine, banks, biotech, business, house-wives, septuagenarians, physically challenged, college kids and of-course the ubiquitous software engineer.

The facilitator arrived, and we were underway. I wouldn’t be able to do justice to what happened, so I am not going to even try to describe it. In short though, in the days that followed, 230 people shared their lives, their pains and joys, their successful relationships and the broken ones and everything else that blocked them and gave them freedom in their lives. It was a roller-coaster ride of emotions, inspiring at times and sometimes palpably painful. Through expert guidance and a lot of “technology” we were given tips how to make our lives extraordinary and given assignments to begin the fixing process, which had to be finished in the short breaks. I met a lot of people from many walks of life, and many will remain friends forever.

The course is not easy, and requires you to place your life in the conversation. Trust me, its a heavy commitment, but the results will surprise you.

If I were to pick 3 things that hit me from the course (which I hope to convert to T-shirts someday), they would be (plagiarized from the trainers words)

“In Life, Hunt Big Game”

“Play all out” and

“All things begin with integrity”

figure it out or visit a forum 🙂

An interesting puzzle

I stumbled across this puzzle on a shopping trip to landmark (forum). I tried solving it at the store, but couldn’t, so took it home with me. After a couple of fruitless hours, I came to the conclusion that the only way to solve it was brute force, and as the number of combinations was 9^9 (9 to the power of 9), I needed a computer to solve it.
I have made a crude representation of the same below.

A neat puzzle

The letters represent color coded connectors.
b -> blue
B -> brown
y -> yellow
r -> red
g -> green

The Square grid at the top is the playboard. It is divided into nine parts of equal size and if you notice the “connectors” of each part match with adjacent connectors. You will also see at the bottom of the picture 8 “separate” cards. Each has a combination of connectors on it. The “separate” cards can be rotated on the plane of your screen. You need to place all 8 cards on the playboard so that all the adjacent connectors are of the same colour. Note that one of the squares will be from the playboard itself.

My first impulse was to go for brain-dead brute force, but it was way too slow, and unluckily for me, the solution was not in the early part of the combinatorial explosion. The basic problem I found is that I was spending too much time on configurations that were not physically viable (i.e no repeated cards etc). I decided I needed a better way to come up with the combinations that are valid.

What I needed was someway to create combinations without repeating the cards. I decided a tree would be best. With each level of the tree having to choose from the cards left after previous level’s choices. Python provides the ‘set’ builtin which can be used for this purpose.

>>> a=[1,2,3,4,5]
>>> b=[2]
>>> print str(set(a) – set(b))
set([1,3,4,5])
>>>

I tried creating a walkable dictionary in recursive way, but it was too heavy for my VM to handle. So instead of creating a dictionary I decided to check combinations as I found them in the tree. What this means is that I do a depth first walk of the tree and when I hit a leaf I check if it is a valid solution. Doing this I could check all possible configurations of a particular placement in 3 seconds.

Some explanation of terms before I go on. A “placement” is when I have decided where to put a “card”, while a “configuration” is when I have also decided the rotation of each card. Number of placements is slightly less than 9^9 while the number of configurations is (4*9)^9

I tried python threads, but that was slower than the threadless version (this is because the python interpreter is not thread safe, so only one thread can be on the cpu at a time, even if you have multiple cpu’s)

I then optimized the code a bit more by flagging a fail case as early as possible in the checking code. This way I could bring the time to check all possible configurations of a particular placement to about 1 second. 9^9 seconds was still too much. I still hadn’t even found a single solution.

Finally, I pushed the checking code as early as possible in the tree walk so that the moment you have a clash in the placement you shave off a whole subtree and voila, 5 seconds for all possible solutions. I then tried the solution on the board I had bought and it worked!

The heart of the code is below, (a bit messy, thanks to all the optimization) [a ‘>’ means single tab, ‘>>’ means 2 tabs and so on]

# this function basically does a quick check with whatever data we have collected so far.
# as you can see it only checks for consistency with squares to the left and above
def checkBehind(self, y, x):
> index = (y*3 + x)*2
> indexup = ((y-1)*3 + x)*2
> indexback = (y*3 + (x-1))*2
> board = (self.getPiece(self.config[index], self.config[index+1],x,y));
> boardup = (self.getPiece(self.config[indexup], self.config[indexup+1],x,y-1));
> boardback = (self.getPiece(self.config[indexback], self.config[indexback+1],x-1,y));
> if x!=0:
>> if board[3] != boardback[1]:
>>>return False;
> if y!=0:
>> if board[0] != boardup[2]:
>>> return False;
> return True

def descendTree(self, possibilities, prevChoice, depth):
> newNode=(possibilities - prevChoice)
> if len(possibilities) == 1:
>> # end of the road so check it
>> self.createCheckConfigBoard() # this is the final check function which will check squares to the right and bottom.
>> return
> for i in newNode:
>> for j in range(0,4):
>>> self.config[(depth*2)+1]=i;
>>> self.config[(depth*2)]=j;
>>> if self.checkBehind(depth/3,depth%3):
>>>> self.parseTree(newNode,set([i]),depth+1)
> return

# create a tree of all possibilities and run the tree
def searchTree(self):
> self.solutionNum=0
> self.possibilityNum = 0;
> possibilities=[0,1,2,3,4,5,6,7,8]
> depth = 0;
> for i in possibilities:
>> for j in range(0,4):
>>> self.config[(depth*2)+1]=i;
>>> self.config[(depth*2)]=j;
>>> self.descendTree(set(possibilities),set([i]),depth+1)

Megamind (2010)

4/5 Hilarious

So my bro and me wanted to spend some quality time together, “what better way to have a quiet dinner on a saturday night”, we thought. We barely survived the car journey, and by mutual consent decided to see a movie instead. I think Megamind saved the day ;-).

The movie is the story of Megamind, who, thanks to his blue skin colour, is treated unfairly by society and grows up into a great villain. Every great villain deserves a great hero, enter MetroMan. Adored and loved since birth Metroman is the darling of the city. The story is about the battle between these 2 arch rivals. Yet another battle between good and evil? Not this one!

The movie will keep you laughing till the very end. The jokes range from cynical jabs at society/life, to down-right-tom-foolery.

The star-studded cast are not readily recognizable in the characters, but this doesn’t make the movie less watchable.

I saw the 2D version, but 3D is going to come out soon, cant wait.