Thursday, July 10, 2008

The Rubik's cube Solver bot

Rubik’s Cube Solving Robot ki kahani, project team members ki zubani! :)

Members of the project team : -

patty, amal, sathe

Narrated by Amaleshwar : -

We had planned out a proper training on robotics during our summer vacations. Thanx to pranav bhai, we got a chance at PARI ( Precision Automation and Robotics India Ltd.) We had no idea what exactly would we be doing at PARI. We had heard that they are basically an industrial robotics firm, with no relation with the grid navigators and obstacle avoiders we had been doing all this time. So, we thought that we might have a tough time competing with 3rd yrs. We, the IITians, had some pride of being IITians! And, this thing was at stake. But, still, the tempo was high, we had decided to learn something or the other! Whatever they would teach us, we would somehow or the other gobble up and learn something useful. With this mindset, pranav bhai approached the training-in-charge.

Then came the twist in the story. The man, named N. R .Kulkarni, or better known among us as Kulkarni, told us that our dreams cannot be fulfilled! i.e. They would not accept little facchas as trainees! L

And, to add to that, he was simply not ready to entertain 3 first years’ physical presence at the PARI campus. So…………hence……………..we were feeling the heat of our shattered dreams! L

But, kahaani mein twist hai mere dost….. he asked pranav to get an efficient algorithm to solve the most famed and mysterious puzzle in the world….. The Rubik’s Cube.

At that time… I was in Hyderabad. Literally makhaing with nothing to do.

That day, in the evening… pranav bhai called me up and told me about the disastrous chat he had with Mr.Kulkarni.

Here goes the conversation

Pranav: - Abe, woh rubik’s cube ke upar koi efficient algo dhoondne ko bola hai.

Amaleshwar: - Kaun sa cube????? Kuchh suna hua types lag raha hai.

Pranav: - Abe rubik’s cube! Maine bhi aaj hi suna hai! Who 3X3X3 ka hota hai na… har individual color ko ek unique side dena rehta hai.

Amaleshwar: - Abe teri! Haan yaad aya! Arre haan, aisa kuchh hota hai. Abe!!! Yeh kya diya hai??? Kuchh biped quadraped nahi mila kya usko? Yeh kya utha ke diya hai woh?

Pranav: - Kya karein yaar! Woh jo bola hai wohi karna padega! Apan decide nahi kar sakte hain apna project!

Amaleshwar : - Bhak!

And then, started the series of messaging controversies. Mr.Pushkar Sathe, or rather Sathe, was a quite a halu listener. We decided that I will do some fight maring at hyd, and pranav will do some along with sathe.

But, I think meri kismet kharab thi! Akele karne mein itna frustapa hoga yeh upar wala bhi nahi jaanta tha! L

Now, pranav continues with the narration : -

Pehle 3 din toh barbad the………..soch soch ke dimag ka lassi ho gaya tha, Dahi toh mamuli chiz hai!! J

Fourth day pe kucch kuchh samaz aa raha tha……..wen I was Trying to get how we change the positions of minicubes @ sathe’s house!!........

And WOW……………..i could place the First corner piece as per given in algo on my own after 3 days!!!!!!!!!(After huha Frustapa)

Uske baad bahot sara Fight marne ke baad……………FINALLY I SOLVED THE FIRST RUBIK’S CUBE IN MY LIFE @ 20th MAY 2008 ,4.30PM………….. JJJJJ

On the day after the next, I was supposed to call NRK but………..on 21st my Grandpa xpired……………..so I was unable to continue with d project 4 the time being!!!!..............Meanwhile………Amaleshwar

Was Fight maring on Algos……………..

Ya.one more thing to write……….beech me ek bar sathe ke pehchan ke ek prof the….who was teaching Maths in IITB few yrs ago!!.....Sathe was interested more in getting the Maths behind the cube(I was saying …………sale cube nahi ban raha hai……….maths ke peeche pada hai…….Fukka lagega maths me jindagi bhar)…….but we removed dat thought after following xplanation By Mr.prof

“You can find the 6 determinants for ‘every combination’ of the cube……..and in order to get the final solved cube you can perform determinant operations on that!!.............”

Funda toh accha tha but how does it look after hearing this

“ There are 43 billion combinations of this Damn Cube”

Now sathe was saying--- maths gaya bhad me…pehle cube banate hai!!!!!!!

Same case with me!! J

Finally after 8-10 days of frustapa………..we have got a decent enough human compatible algo to solve the cube!!!...I was gathering Courage 2 tell this to Mr.Kulkarni…………

!!

On 28th May i called NRK and told this to him…………..his reaction was “OK..thik hai”

I was saying –sale, itna fight marke algo laya hai…….kucch toh ‘gud’ ya ‘accha’ types bol

Now AMAL will continue------

To chalo bhai log.. continue karte hain… algo ke bare mein pranav ne bataya NRK ko… usne sirf “OK” keh ke use frust kiya. Uske baad, bot ke mech design ke bare mein fone pe hi bataya! Which was virtually impossible to be understood, even if u r AIR 1! So…. Pranav bhai halu ho ke dekh rahe the…. Jo samajh aya… mujhe bata diya…..aur mujhe aur bhi halu kar diya!! Kya karein bhai…..and… meanwhile sathe bhai peace mar rahe the…. Happy insaan!

Then, we decided to make the simulator and do some coding, in VB as said by NRK. But….. problems never end! We, little chaps having just one semester of experience in programming, were supposed to program an entire gigantic algorithm for a rubik’s cube, which was virtually impossible to implement even 50% of it manually!!

But…. Darne ki kya baat hai….. tempo jab saath hai!!!!

Now, I reached pune on 7th June, with just enough experience to solve the first layer of the cube. And, by that time, pranav had barely managed to solve the entire cube on his own. And, with this much experience… hum kuchh raahi… chal pade algorithm cracking ki raah par. Tab tak decide ho gaya ki kya karna hai kaise karna hai…………

Fir…. Arre bhai, load ana kabhi kam hota hai kya???? Tab tak sathe bhai hawa ho gaye! Dikh hi nahi rahe pune mein! Baad mein pata chala ki ghumne gaya hua tha. Aur, fir pranav bhai ke java classes waalon ne aur bhi load de diya. Timings badha diya… aur time kam ho gaya humare paas!

Lekin… fir bhi….hausla banaye rakha humne! :-D

Then, we started on our first day…. Built the simulator by coding around 670 lines. And, it was working perfectly! We were too happy with our first achievement in this project.

Then….. there came day… when I was all alone at home.. With nothing to do! Coding was impossible alone! I had to just sleep around! Huha frust hua tha bhai!!!

Fir…. That frustapa had a solution. Sathe came back from his tour.

Fir… shuru hua ek naya karyakram. Roz subah pranav java classes se pehle mujhe sathe ke ghar pe drop kar deta tha…. Aur fir aate waqt le jata tha…. Jaise bache ko crèche mein daal deta ho… aur fir le jata ho! :-D

By that time….we had cracked the first layer. Then.. the second layer was somehow completed alongwith sathe. Then, the third layer was cracked at night the next day at pranav’s house. But, it took 2-3 days to increase the efficiency of the algorithm.

Everything was going perfectly……..fir achanak sathe ko brainwave…. Nahi……… brainTsunami aya ki use bhi java class join karna chahiye. Fir to main huhaa ulti masto fundooo frust ho gaya! L

Ab kya karun??? I tried my best to convince sathe not to join the class…. But sathe to sathe raha… join kar hi liya…

Waise, meri kismet achhi thi ki tab tak coding ka kaam khatm tha. Aur, PARI ka mech design ka kaam poora nahi tha. So, we decided to meet NRK and find out the final solution to this problem. We met him on 12th evening…. Our first visit to the PARI campus. And, we were literally HALU at the campus…. After having a look at the big huha types machinery.

Till then, we had coded enough to show NRK the first two layers coded.

After waiting for abt half an hour, we met him…. And again………. NRK toh NRK thehra.. humari baatein thodi na suni usne! Woh to bhaiya…….hey bhagwaan! Kaise kahun!!! ….. woh to…. Humari kuchh na sun ke humein ulta funda dene laga mech design ka. Lekin, humne dhairya rakha…… funda suna uska… 75% funda kaan se filter hokar alag ho gaya… aur jo 25% useful tha… bas wahi register hua! J

When, we tried to show him our hardwork… he just appreciated our attitude that we have the confidence that this problem can be solved. That’s it! No appreciation for the hard work we had put in all these days.

We asked him if we could keep this project on hold for a few days, so that we could start work once pranav’s and sathe’s java classes are over. He agreed to that. Whew! Some relief at last!

So, I happily left for home…… but, by that time I discovered one algo, better known as speed cubing algorithm, by Lars Petrus, which took 30% less steps than the conventional layer-by-layer algo. So, we thought…. That when I come to pune for the second time, we can build up an entirely new code, based on the speed cubing algorithm. So, at home… fight maring on the speed cubing method continued.. and pranav and sathe were happily getting frust with their java classes! ( when I came to pune, I found this! ;-) )

Then…. I came back to pune on the 1st of july.

Now. Pranav bhai continues-----

Our algo was not 100% perfect…………beech me sala atkta tha kucch kucch cases pe!!!

After few Hrs of tiresome and Frustrating work we found out where the load was!!!..............second layer….ya Third layer……….or both!!.......ek toh cube solve karne ke liye our code was taking more than 150 steps……sumtimes it crossed the magic figures like 250!!! J………

So we Decided to say ‘Tata-ByeBye’ to this code and Start with new Speed Cubing algo!!!

Whoosh………actually this wasn’t much frustrating at first few moves as we were now familiar with the cube……………but as it went further………….Frustapa and Frustapa and Frustapa!!!! Nolthing Else…..

You can imagine wat our state wud be if we were supposed to handle 72 cases just for placing 3 Edges on the cube!!.............uff!!

But we handled the case with patience and intelligence!! Yes…….our coding for the 2*2*3 cube was ready and it was taking just 30-40 steps!!...wich was quite a big achievement for us!!

The whole day we were thinking of The cube , cube and Cube………..nothing else…..

And to add to our frustration beech beech me the code wich performed perfectly right a few hrs b4….started giving ERROR after few hrs!!!!!!!!’

That damn second layer was dreally a big Frustrating thing!!

We Worked Almost whole day on this second layer!!!.........We tried everything!!................

Amal found a Mathematical algo wich was really huha types!!!.........we programmed it with high tempo and waited for the result!!

But when we tried it on our simulator……………don ask the result!!!

Kucch Kucch Errors de raha tha sala!!............kucch ajib hi ho raha tha!!

Just too much for us to debug……………

Once again Amal thought a new Recursive Algo……and we decided to try dat one!!

We were used to errors………..main frust hoke lappy ka screen dekh raha tha…and Amal pressed “SOLVE” on the screen……………………..and suddenly……I saw the cube with its two Layers solved………The “ abe sala………….HUHA” sound broke the silence in the room!!!!!!!! Yes we have cracked the two layers with speed cubing…………....... There was nothing like that “machau feeling” at that time! J

Now we moved on to the Third layer………..which we thought to be very simple but in the end wich turned out the most difficult thing to deal with!!!

Now Amal will Continue-----

Hmm… the third layer. Was supposedly quite simple when we had done it last time with the layer by layer algo. Then, came a time when perfection is replaced by bare completion. This time, our task was to make this algo perfect! Humne pichhli baar jo program banaya tha sala kuchh kuchh cases mein seriously huha types error de raha tha! Humein to laga ki yahi agar submit kiya to NRK utha utha ke maarega. Fir..ab apne ko perfection lane ka tha. Isme, bhaiya perfection haasil karne ki koshish karo to load aana hi hai.

We directly used the previous function based on our older algorithm. But…. It gave errors still!!! And, the error was not a simple one. It made the program enter an infinite loop. We tried out the debugging. We didn’t find a single problem in the code. We still tried on for several hours………… in the end we found one case of the rubik’s cube which was quite tough to implement mathematically. We tried out all possible methods to solve it for the entire day, but, fruitlessly. I doubted whether it was mathematically possible to solve it. So, I constructed a software to find it out. And…. I found it mathematically impossible. Then… believe this or not….. apne pranav bhaiya ko tempo types aa gaya… fir isi code mein kuchh kuchh kuchh kuchh kuchh kuchh kiya………… aur fir woh SOLVE KARNE LAGA!!!!!!!!! Just imagine! Something mathematically impossible ko bana diya possible… without even knowing it. Aaj bhi humein nahi pata hai ki pranav ne usmein kya kiya hai jo woh kaam karne laga hai. And needless to say, pranav bhai ko bhi nahi pata hai!

Ab…….. jahan tak program ka sawal hai….. program to bindas peacefully kaam kar raha tha. Humne bana liya yeh program, with an estimated 30% reduction in the no. of steps. Fir bhaiyaa…. Kaise kahein…. Har case solve kar raha tha yeh zalim program. Khushi ke leher man mein daudne lage…

Aisa feel hua jaise hum duniya ke be-taaj badhshaah ho gaye! :-D

Fir….. shaam huyi… pranav ne puchha “abe, yeh jo steps ka list nikalta hai, isko dobara laga ke dekhte hain, aakhir yeh solve karta hai ya nahi”

We tried that……………and again….. shattered dreams production ltd………… it wasn’t working!!!! L

What the hellll?????? The program was solving the rubik’s cube according to the simulator. But, the steps which it gave out couldn’t do that??? Is that a joke? I was deeply shocked!!! Pranav had similar feelings too. We started out debugging at around 5 pm. Now, just imagine…. Searching for this bug in a 5,500 line program………… which is literally HUGE!!! But, still we moved on. And, after 3 hrs of pain, we found out the bug! And woah, it was working after fixing the bug.!!! And then…. Suddenly pranav and I shouted out “yaayyyyyyy!!!” loud enough to be heard 5 houses away! Just imagine our happiness. And………. I rang up home to tell this achievement of ours! J

Then….. comes the peace maring time. We have completed the project. It has ended well. And, as the saying goes, All’s well that ends well. And, now the final presentation to Mr.Kulkarni. We have to show them the entire thing.

Lekin ,sawal fir se man mein aane lage. Humne kaafi complexities mein algorithms ko code kiya hai. 4 algos combine kar ke yeh banaya hai. Fir, poora algo chamakne mein humein ek mahine types lag gaya, to bhala yeh kulkarni ek ghante mein kya ukhad lega?

Sochna pada kaafi kuchh. Dimaag mein confusion jama raha. Fir, plan kiya ki sirf working dikhayenge, algo samjhana gaya bhaad mein. Fir, working etc. sab document kar liya, cam pics kaise lega who bhi likh dala. Fir, parallel port pe fight chali, jispe hum teeno failure the! :-D

Uske baad, humne final soch liya, thoda sa documentation le jaayenge, ki is software ka working kya hai, aur iska mechanical steps mein break down kaise hoga. Bas!!

Fir, who din aya, jab kulkarni ke saath meeting hua. PARI campus pohonche.

Kulkarni ne kaha ki woh ek senior software engineer ko bulaya hai, jisko explain karenge iska working etc.

Fir, meeting chala achha khaasa 1 hr ka. Jispe humein aascharya tha ki kulkarni ne itna time humein kaise de diya! Kaafi kuchh explanation hua, working dikhaya. Explain kar kar ke main aur pranav huha types frust ho gaye.

Now, comes the good part, kulkarni sahib ne kaha… “Great!!”

Woh “great!” humare dilon ko chhu gaya…. Literally!

Humari mehnat rang laayi!

Humne kuchh kar dikhaya finally! J

yO!

Fir….. certi ki baat huyi, and he was ready to give a certi to us. But, stipend ki baat nahi ki L

Khair, jo bhi ho, 1st yr mein stipend expect bhi nahi kar raha tha! :-P

Anyways, us shaam ko camp area mein ghuma……aur raat ko train pakad ke hyd ke liye kat liya!

We became a happier team altogether!