Thursday, March 23, 2006

All about positioning !

For those who dont know, I commute to my office at ITPL by bus :-(. However I should accept that it has been a fine ride till now. The ride is more than "fine" if you get a "comfortable" place to sit.This comfort is dictated by your neighbour,I mean the person sitting next to you in the bus. Of course, the size of your neighbour does make a lot of difference, but there are few guys(even skinny ones) who just think that they have come from some other planet ! Some guys just spread their legs and have no care in the world.Some of them even use your leg as a resting place. This is no way a new experience to me. I travelled by bus for 4 years during engineering and had similar problems even then. The way it was dealt at that time was either through a warning tone or a humble request and when both didn't had to resort to physical force. (I am sure our mysore group has some valuable comments on this :-)) Anyway I am going to deviate from this and explain how I take my position in the ITPL bus while coming back home. Most of the ITPL buses are 3+2 seat type. My algorithm for a "comfortable" place is this:

Status main(Bus b)
{
Status twoSeatStat,threeSeatStat;
/* Search for 2 seaters first */
if((twoSeatStat = search2Seater()) == FAILURE)
Status threeSeatStat = search3Seater()    ;
else
return twoSeatStat;

/* check the status of 3 seater search */
if(threeSeatStat == FALIURE)
/* go on searching the next bus..hmm might cause a stack overflow */
return main(NextBus)
else
return threeSeatStat;
}



Status search2Seater()

{
for(every 2 seater in the bus)
{
  if (both seats empty)
  {
      /* aisle is definitely not recommended, since you cant predict
who your neighbour is going to be */
      occupy the window place;
      pray for a skinny guy/gal:-) to sit next to you;
      if(skinny)
      {
          if(gal)
          {
              return LUCKYDAY;
 /* haha my wife is going to kill me seeing this scenario
 and return value */                                                              
          }
      else if(guy)
      {
          return HMMMBADLUCK;
      }
/* wondering why this check.. see the next return statement */
      else
          return GODSAVEME;
  }
  else /* not skinny */
  {
      if (gal)
      return CANMANAGEIGUESS;
      else
      return GODSAVEMEAGAIN;  

  }
} /* no 2 seater with both seats empty :-( */
else
if(single seat is available)
{
  /* this is definitely subjective */
  if( checksize(neighbour)!= too much)
  sit next to him/her;
  return CANMANAGEIGUESS;
}

/*no 2 seater , guess need to search in a 3 seater*/
return FAILURE;
}
}

Status search3seater()
{
for(each 3 seater)
{
/* I am already exhausted writing up to here..so i am keeping the flow SIMPLE :-) */
if(all 3 empty)
{
occupy the window seat;
pray for skinny neighbourS;
return PRAYFORTHEBEST;
}
else
/* assuming the guy/gal is sitting in one corner */
if(only 1 is occupied)
{
occupy whichever corner seat is available;
pray for a skinny guy/gal for the middle seat
return PRAYFORTHEBEST;
}
/* man! left with the last option before searching the next bus */
if(corner seat available)
  go grab it;
  return CANMANAGEIGUESS;
else
if(middle seat available)
{
if(both sides gal)
    return AIN'TILUCKY;
else
if(one side guy and one side gal)
   return BETTERTHANTHENEXTCASE;
if(both sides guy)
 if(checksize(neighbourS) != too much)
   grab that place;
   return HOPEFORTHEBEST;

}
/* return FAILURE so that I go search in the next bus */
return FAILURE;
}
I am definitely not expecting any bug related comments in the above logic, I used the above approach, because it saves me the time of typing the scenario in detail.... I am sure other people's logic in a similar situation will be different and the return STATUS will definitely be different ... do post ur logic and your "STATUS" values in the comments section...will be interesting to see how the other minds handle the same situation. And somehow I am still not convinced with the title of the blog .. Please do suggest some nice titles also :)

10 comments:

Venu said...

If somebody know how to format the code let me know..I did format but once I save the post, the formatting goes off

Harish said...

Venu, being the core member of wve you shouldn't be asking such questions as to how to format using html. all you have to do is use & nbsp ; tag like this.
Status main(Bus b)
{
    Status twoSeatStat,threeSeatStat;
    .......
}

PS: you can also use a pre tag (which is what i wanted to post first, but the comments didnt accept the pre tag :D.

Harish said...

Oh, talking only abt formatting, forgot abt ur post. It was good, start writing algos for more such problems and u can rename this blog as
Algos for Real Life ;)

Harish said...

And Venu one more thing, if u find typing nbsps boring, write a program to replace all spaces(or tabs) with nbsps - just a 1 line code in java :D

Venu said...

pre tag worked...thanks..harish

Anonymous said...

U sure have lot of time in life :D

Anonymous said...

maga u need to try hitchhiking.

Anonymous said...

Where did you find it? Interesting read District columbia malpractice attorneys Advertising email strategic Backpack laptop wheels cell phone data cable canada zyban information online online http://www.zyban-5.info/quitting-zyban.html Anal destruction clips welbutrin vs zyban Cabinet refinishing atlanta Daewoo vacuum cleaners find compare read black model non nude teen zyban effects

Anonymous said...

Wonderful and informative web site. I used information from that site its great. Phone dialer skins http://www.merchant-account-9.info british flag swimwear Camion occasion renault Michigan boating vacations dr swimwear Marines scholarships veterans http://www.buxom-sweater.info/thong-swimsuit-sale.html best protein supplements mix 2000 isuzu rodeo specs Proactiv ads Cut diamond emerald necklace Steam bath steam bath saunas steam bath Maxtor data recovery perfume marc jacobs windaz perfumes

Anonymous said...

You have an outstanding good and well structured site. I enjoyed browsing through it » »