Re: [algogeeks] Re: Google Interview Question-Snake and Ladder Design

2010-09-17 Thread Anil Kumar S. R.
@bittu, we are here to discuss the way to solve it. Posting a code here will
not do anything good.

Anil Kumar S. R.
http://sranil.googlepages.com/

The best way to succeed in this world is to act on the advice you give to
others.


On 14 September 2010 13:33, bittu shashank7andr...@gmail.com wrote:

 #includestdlib.h
 #includestdio.h
 #includemath.h
 #includeconio.h
  ///O(N^2) solution  Does solution exits
 in O(n) or (nlogn)..? reply me sum1 git dis..
 //i will post analysis of dsi program later
 int turn, square;
 long game, totalgames;
 int seed;
 int chutehit[10], ladderhit[9];
 float RunningTurnTotal;
 float average;

 char reply;


 void ChuteStats()
 {printf(Chute and Ladder Statistics:\n\n);

 printf(Chute0: %d Ladder0: %d\n, chutehit[0], ladderhit[0]);
 printf(Chute1: %d Ladder1: %d\n, chutehit[1], ladderhit[1]);
 printf(Chute2: %d Ladder2: %d\n, chutehit[2], ladderhit[2]);
 printf(Chute3: %d Ladder3: %d\n, chutehit[3], ladderhit[3]);
 printf(Chute4: %d Ladder4: %d\n, chutehit[4], ladderhit[4]);
 printf(Chute5: %d Ladder5: %d\n, chutehit[5], ladderhit[5]);
 printf(Chute6: %d Ladder6: %d\n, chutehit[6], ladderhit[6]);
 printf(Chute7: %d Ladder7: %d\n, chutehit[7], ladderhit[7]);
 printf(Chute8: %d Ladder8: %d\n, chutehit[8], ladderhit[8]);
 printf(Chute9: %d\n, chutehit[9]);
 }



 int main()
 {
 printf(Welcome to the Chutes and Ladders simulation \n);
 printf(...\n);
 srand(1);

 //printf(How many games would you like me to run? __ );
 //scanf(%i,totalgames);
 ///printf(\n You have chosen to run %i games... thank you! \n,
 totalgames);

 totalgames+=2;
 RunningTurnTotal=0.0;
game=1;
do{

turn=0;
square=0; /** Reset game **/
 do   /** Begin game loop
 **/

{
++turn;
RunningTurnTotal = RunningTurnTotal + 1;

square = square + 1 + rand()%6;   /** Spin and move
 **/

printf(square =%d \n,square);

if (square == 1) {square=23; ++ladderhit[0];} /** Ladders?
 **/
if (square == 4) {square=14; ++ladderhit[1];}
if (square == 9) {square=31; ++ladderhit[2];}
if (square == 21) {square=42; ++ladderhit[3];}
if (square == 28) {square=84; ++ladderhit[4];}
if (square == 36) {square=44; ++ladderhit[5];}
if (square == 51) {square=67; ++ladderhit[6];}
if (square == 71) {square=91; ++ladderhit[7];}
if (square == 80) {square=100;++ladderhit[8];}/// so when 80
 comes raech to our goal exit



if (square == 98) {square=78; ++chutehit[0];} /** Chutes ?
 **/
if (square == 95) {square=75; ++chutehit[1];}
if (square == 93) {square=73; ++chutehit[2];}
if (square == 87) {square=24; ++chutehit[3];}
if (square == 62) {square=19; ++chutehit[4];}
if (square == 64) {square=60; ++chutehit[5];}
if (square == 56) {square=53; ++chutehit[6];}
if (square == 49) {square=11; ++chutehit[7];}
if (square == 48) {square=26; ++chutehit[8];}
if (square == 16) {square=6; ++chutehit[9];}

   } while (square100);//terminate if random no. is  100

   printf(\n\n Game over after %d turns\n, turn);
   printf(\nSimulation complete... beginning statistical
 analysis...\n\n);
  printf(Total number of games played: %d \n, game);
  printf(Total number of turns: %f \n, RunningTurnTotal);
  average = RunningTurnTotal / game;
  printf(Avg number of turns per game: %f \n, average);
  printf(\n);
  ChuteStats();
  printf(\n);

 ++game;
 printf(\n\n Would you like to run the simulation again?
 (1=Yes)...);
 scanf(%i,reply);
 if(reply==1)//e.g. reply==1
 totalgames+=1;
 else
 exit(0);// exit


  } while (gametotalgames);



 getch();
 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Google Interview Question-Snake and Ladder Design

2010-09-14 Thread siddharth srivastava
Hi

On 14 September 2010 13:33, bittu shashank7andr...@gmail.com wrote:

 #includestdlib.h
 #includestdio.h
 #includemath.h
 #includeconio.h
  ///O(N^2) solution  Does solution exits
 in O(n) or (nlogn)..? reply me sum1 git dis..
 //i will post analysis of dsi program later
 int turn, square;
 long game, totalgames;
 int seed;
 int chutehit[10], ladderhit[9];
 float RunningTurnTotal;
 float average;

 char reply;


 void ChuteStats()
 {printf(Chute and Ladder Statistics:\n\n);

 printf(Chute0: %d Ladder0: %d\n, chutehit[0], ladderhit[0]);
 printf(Chute1: %d Ladder1: %d\n, chutehit[1], ladderhit[1]);
 printf(Chute2: %d Ladder2: %d\n, chutehit[2], ladderhit[2]);
 printf(Chute3: %d Ladder3: %d\n, chutehit[3], ladderhit[3]);
 printf(Chute4: %d Ladder4: %d\n, chutehit[4], ladderhit[4]);
 printf(Chute5: %d Ladder5: %d\n, chutehit[5], ladderhit[5]);
 printf(Chute6: %d Ladder6: %d\n, chutehit[6], ladderhit[6]);
 printf(Chute7: %d Ladder7: %d\n, chutehit[7], ladderhit[7]);
 printf(Chute8: %d Ladder8: %d\n, chutehit[8], ladderhit[8]);
 printf(Chute9: %d\n, chutehit[9]);
 }



 int main()
 {
 printf(Welcome to the Chutes and Ladders simulation \n);
 printf(...\n);
 srand(1);

 //printf(How many games would you like me to run? __ );
 //scanf(%i,totalgames);
 ///printf(\n You have chosen to run %i games... thank you! \n,
 totalgames);

 totalgames+=2;
 RunningTurnTotal=0.0;
game=1;
do{

turn=0;
square=0; /** Reset game **/
 do   /** Begin game loop
 **/

{
++turn;
RunningTurnTotal = RunningTurnTotal + 1;

square = square + 1 + rand()%6;   /** Spin and move
 **/

printf(square =%d \n,square);

if (square == 1) {square=23; ++ladderhit[0];} /** Ladders?
 **/
if (square == 4) {square=14; ++ladderhit[1];}
if (square == 9) {square=31; ++ladderhit[2];}
if (square == 21) {square=42; ++ladderhit[3];}
if (square == 28) {square=84; ++ladderhit[4];}
if (square == 36) {square=44; ++ladderhit[5];}
if (square == 51) {square=67; ++ladderhit[6];}
if (square == 71) {square=91; ++ladderhit[7];}
if (square == 80) {square=100;++ladderhit[8];}/// so when 80
 comes raech to our goal exit



if (square == 98) {square=78; ++chutehit[0];} /** Chutes ?
 **/
if (square == 95) {square=75; ++chutehit[1];}
if (square == 93) {square=73; ++chutehit[2];}
if (square == 87) {square=24; ++chutehit[3];}
if (square == 62) {square=19; ++chutehit[4];}
if (square == 64) {square=60; ++chutehit[5];}
if (square == 56) {square=53; ++chutehit[6];}
if (square == 49) {square=11; ++chutehit[7];}
if (square == 48) {square=26; ++chutehit[8];}
if (square == 16) {square=6; ++chutehit[9];}

   } while (square100);//terminate if random no. is  100

   printf(\n\n Game over after %d turns\n, turn);
   printf(\nSimulation complete... beginning statistical
 analysis...\n\n);
  printf(Total number of games played: %d \n, game);
  printf(Total number of turns: %f \n, RunningTurnTotal);
  average = RunningTurnTotal / game;
  printf(Avg number of turns per game: %f \n, average);
  printf(\n);
  ChuteStats();
  printf(\n);

 ++game;
 printf(\n\n Would you like to run the simulation again?
 (1=Yes)...);
 scanf(%i,reply);
 if(reply==1)//e.g. reply==1
 totalgames+=1;
 else
 exit(0);// exit


  } while (gametotalgames);



 getch();
 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


Can you please write an algo for your program ?

-- 
Siddharth Srivastava

When you have learned to snatch the error code from the trap frame, it will
be time for you to leave.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.