23/12/2013
Here is the program which solves a game, whose problem statement/rule is as follows :
There are bunch of kids(n) who are standing in a circle and reciting a rhyme(having m words).
* Each kid recites only a single word from the rhyme and
the next kid recites the next word.
* The kid who recites the last word has to leave the circle
and then the next kid starts the rhyme again from
beginning until another kid leaves the circle. Likewise,
They continue till only 1 kid remain(the winner).
Example:
* Number of kids =6
* Rhyme =""Twinkle twinkle little star"-(4 words)
So inputs are 6 and 4
Output:
Round 1-1,2,3,4,5,6(kid 4 has to leave the circle;kid 5 will start the rhyme)
Round 2-1,2,3,5,6(kid 2 has to leave the circle;kid 3 will start the rhyme)
Round 3-1,3,5,6(kid 1 has to leave the circle;kid 3 will start the rhyme)
Round 4-3,5,6(kid 3 has to leave the circle;kid 5 will start the rhyme)
Round 5-5,6(kid 6 has to leave the circle;kid 5 is winner)
/*
(c) Copyright 2013, CodingGuru.
The logic used is:
Finding no_words'th kid to mark him as lost by rotating through the array(if not found within upper bound of array).
The next variable tracks where we are in the array to find next loser. It is implied from the ploblem statement that
number_of_kids-1 loosers will be present, when found the winner. So we run through loop till loosers_count equals
number_of_kids-1.
Note : The behaviour of the program is unknown for inputs other than integer.
*/
WON 1
LOST 0
int main()
{
int no_words, no_kids, i, called, next, skip;
int *play;
int loser;
int losers_count;
read: printf("How many kids want to play: ");
scanf("%d",&no_kids);
printf("With how many words: ");
scanf("%d",&no_words);
if(no_kids