Sunday, July 14, 2013

Inky Pinky Ponky, a Kids Game.... Amazon Coding Contest

Amazon Coding Contest:
Inky Pinky Ponkey:
In the kid’s game of inky pinky ponkey, you start with a N kids standing in a circle. Your group has a secret chant that has K words in it. Starting from the first Kid, you count off each kid for each of the words in the Chant (note, the number of words in the chant may exceed the number of kids, you may count off a kid multiple times). The kid who is counted off last is considered eliminated. The chanting begins with the next kid, the chanting/counting is repeated with the remaining kids. This is repeated till N-1 kids are eliminated, leaving with one victor.
Accept input N and K and simulate the game, display the number (1-N) corresponding to the number of the winning Kid.
In trivial case, N=5, K=1, the last kid will be left.


#include<stdio.h>
#include<stdlib.h>
 
int InkyPinkyPonky(int kid,int words)
{  int  m = 0;
   int  i = 2;
   while( i <= kid)
   {
     m = (m + words) % i;
     i+= 1;
   }
return m+1;
}   
int main(void)
{  int kid,words;
    printf("Enter the no. of Kids and no. of words int the chant\n");
    scanf("%d%d",&kid,&words);
    printf("out of %d kid, Winnig kid is %d",kid,InkyPinkyPonky(kid,words));
    return 0 ;
}
Happy coding.....

No comments:

Post a Comment