Jump to content
BrainDen.com - Brain Teasers
  • 0


Guest
 Share

Question

We start with a roulette wheel that is numbered from 0 to 32 in order, clockwise around the wheel. The ball starts in the 0 slot. The ball has paint on it that won't dry, so it leaves a mark whenever it visits a slot on the wheel. We flip a fair coin to determine the ball's movements. If it comes up heads, the ball moves one spot clockwise. If we flip tails, it moves one spot counter-clockwise. We will continue flipping, until every slot gets marked with some paint. You have two tasks:

1. Determine which numbers, if any, are more likely than the others to be the last slot to get marked with paint (the 0 is out of the running as the wet ball starts there)

2. Support your answer with logic and simple English, no fancy formulas

Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0

agree with JLT but would add 17 as well as it is also 16 slots from 0. Seems to me the odds balance on either side of zero so it would be most likely to end at the least likely position. Would expect 0 to be the most likely number to be landed on so the least likely would be the farthest away from 0 requiring the most consecutive flips with the same result?

Link to comment
Share on other sites

  • 0

I've respected your request and did not use any formal calculations to solve this so there is a good chance that my logic is flawed. Anyways, here goes: It seems to me that it would be most likely to finish on 1,2,31 or 32. If it were to end on 1 the minimum number or flips would be 32, all 32 flips coming up tails. This is one fundamental way to get 1 as the last way. Every even number of flips after 32 adds permutations to this where a heads is flipped one or more times that is eventually balanced out by an equal number of tails. In order to land on 3 or 30 it takes a minimum of 34 flips and there is only one way to do it while there are 31 ways to land on 1 or 32. At 36 there is one way to land on 5 or 28, 31 ways to land on 3 or 30 and many more ways to land on 1 or 32. So for any even number of flips there will always be more ways to land on 1 or 32 than on 3,5,7,9,11,13,15,18,20,22,24,26,28 or 30. The same holds true for odd numbers and 2 and 31 which start at 33 flips.

Now once you get enough flips, you start getting into what you might call a harmonic. There is one way to get 1 or 32 with 63 flips. Namely 31 heads followed by 32 tails to end on 32. With 65 flips there is one way to get 3 or 30 but 62 ways to get 1 or 32. And so on as before.

So basically, for any number of flips there are more ways to get either 1,2,31 or 32 than any other number, therefore those numbers are more likely. The reason I say that 2,31 has equal probability to 1, 32 is that the 2,31 harmonic starts at 62 while 1,32 starts at 63. Not sure if this balances it out but I'm guessing it does.

Clear as mud eh?

Link to comment
Share on other sites

  • 0

First (and obvious to the most casual observer), all numbers have the same probability as those numbers with the same distance smallest distance to 0. (eg, 1 and 32, 2 and 31, 16 and 17, etc)

Second, really low and really high numbers are close to 0, so they will have a very low chance of being the last number painted.

Third, I believe it would be more likely to paint 16 and 17 before painting both 15 and 18, and also more likely to paint 15 through 18 before painting 14 and 19, etc. This is because once it gets to that area it would need to travel all the way back around to the other side to get the other number where it would be more likely to travel the short distance through.

So my guess will be 7-9 and 24-26.... something like that. Probably closer to 16-17 than that, but still somewhere close to 90 degrees away from 0.

I'm actually kinda interested now.... I'll code this up a little later and post code/results.

Link to comment
Share on other sites

  • 0

Wow. Never would have guessed, nor would I have believed you if you told me.

(Don't look at my spoilers if you haven't thought about the problem and decided on a solution...)

I started off and coded up a simulation quick, here's the result of 10 million trials:

1       32      =       381679

2       31      =       534351

3       30      =       534351

4       29      =       992367

5       28      =       839696

6       27      =       839695

7       26      =       381679

8       25      =       305344

9       24      =       916029

10      23      =       610687

11      22      =       839694

12      21      =       458016

13      20      =       763360

14      19      =       229007

15      18      =       687023

16      17      =       687022

202 seconds elapsed
It seemed to me to be a little biased toward the center of the list (I guess we really do see what we expect to see). I thought about running it for more trials, but I decided to replace my random number generator with the mersenne twister instead. Here's the results of the same test but with a much better random number generator:
1       32      =       624676

2       31      =       624941

3       30      =       625510

4       29      =       623761

5       28      =       626154

6       27      =       625327

7       26      =       623997

8       25      =       627124

9       24      =       624259

10      23      =       623916

11      22      =       625027

12      21      =       625957

13      20      =       626543

14      19      =       624957

15      18      =       624231

16      17      =       623620

680 seconds elapsed
Crazy, huh? Here's my code (includes code I did not write for the mersenne twister)
/* initializes mt[N] with a seed */

void init_genrand(unsigned long s);

/* initialize by an array with array-length */

/* init_key is the array for initializing keys */

/* key_length is its length */

/* slight change for C++, 2004/2/26 */

void init_by_array(unsigned long init_key[], int key_length);

/* generates a random number on [0,0xffffffff]-interval */

unsigned long genrand_int32(void);

/* generates a random number on [0,0x7fffffff]-interval */

long genrand_int31(void);

/* These real versions are due to Isaku Wada, 2002/01/09 added */

/* generates a random number on [0,1]-real-interval */

double genrand_real1(void);

/* generates a random number on [0,1)-real-interval */

double genrand_real2(void);

/* generates a random number on (0,1)-real-interval */

double genrand_real3(void);

/* generates a random number on [0,1) with 53-bit resolution*/

double genrand_res53(void);






//-------------------my code---------------------

#include <iostream>

using namespace std;

#include <time.h>

#include <stdio.h>


#define trials 10000000

int main(int argc, char **argv)

{

	srand(time(0)); rand();

	init_genrand(time(0));//thought I'd use mersenne twister

	long start = time(0);

	int results[17];

	memset(results,0,17*sizeof(int));//better be a 4 byte int...

	for(int i = 0; i < trials; i++)

	{

		unsigned int paint = 0;

		int place = 0;

		while (paint != -1)

		{

			place = (place+((genrand_int32()%2) ? 32 : 1))%33;

			//place = (place+((rand()%2) ? 32 : 1))%33;

			if (place) paint |= 1 << (place-1);

		}

		results[(place>16) ? 33-place : place]++;

		if (!((i+1)%100000))

		{

			for(int i = 1; i < 17; i++) cout << i << "\t" << 33-i << "\t=\t" << results[i] << endl;

			cout << (long)(time(0)) - start << " seconds elapsed" << endl << endl << endl;

		}

	}

	return 0;

}

//-------------------end my code--------------------------






/* 

   A C-program for MT19937, with initialization improved 2002/1/26.

   Coded by Takuji Nishimura and Makoto Matsumoto.


   Before using, initialize the state by using init_genrand(seed)  

   or init_by_array(init_key, key_length).


   Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,

   All rights reserved.                          

   Copyright (C) 2005, Mutsuo Saito,

   All rights reserved.                          


   Redistribution and use in source and binary forms, with or without

   modification, are permitted provided that the following conditions

   are met:


     1. Redistributions of source code must retain the above copyright

        notice, this list of conditions and the following disclaimer.


     2. Redistributions in binary form must reproduce the above copyright

        notice, this list of conditions and the following disclaimer in the

        documentation and/or other materials provided with the distribution.


     3. The names of its contributors may not be used to endorse or promote 

        products derived from this software without specific prior written 

        permission.


   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR

   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,

   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,

   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR

   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF

   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING

   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



   Any feedback is very welcome.

   http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html

   email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)

*/



/* Period parameters */  

#define N 624

#define M 397

#define MATRIX_A 0x9908b0dfUL   /* constant vector a */

#define UPPER_MASK 0x80000000UL /* most significant w-r bits */

#define LOWER_MASK 0x7fffffffUL /* least significant r bits */


static unsigned long mt[N]; /* the array for the state vector  */

static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */


/* initializes mt[N] with a seed */

void init_genrand(unsigned long s)

{

    mt[0]= s & 0xffffffffUL;

    for (mti=1; mti<N; mti++) {

        mt[mti] = 

	    (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti); 

        /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */

        /* In the previous versions, MSBs of the seed affect   */

        /* only MSBs of the array mt[].                        */

        /* 2002/01/09 modified by Makoto Matsumoto             */

        mt[mti] &= 0xffffffffUL;

        /* for >32 bit machines */

    }

}


/* initialize by an array with array-length */

/* init_key is the array for initializing keys */

/* key_length is its length */

/* slight change for C++, 2004/2/26 */

void init_by_array(unsigned long init_key[], int key_length)

{

    int i, j, k;

    init_genrand(19650218UL);

    i=1; j=0;

    k = (N>key_length ? N : key_length);

    for (; k; k--) {

        mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL))

          + init_key[j] + j; /* non linear */

        mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */

        i++; j++;

        if (i>=N) { mt[0] = mt[N-1]; i=1; }

        if (j>=key_length) j=0;

    }

    for (k=N-1; k; k--) {

        mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL))

          - i; /* non linear */

        mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */

        i++;

        if (i>=N) { mt[0] = mt[N-1]; i=1; }

    }


    mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */ 

}


/* generates a random number on [0,0xffffffff]-interval */

unsigned long genrand_int32(void)

{

    unsigned long y;

    static unsigned long mag01[2]={0x0UL, MATRIX_A};

    /* mag01[x] = x * MATRIX_A  for x=0,1 */


    if (mti >= N) { /* generate N words at one time */

        int kk;


        if (mti == N+1)   /* if init_genrand() has not been called, */

            init_genrand(5489UL); /* a default initial seed is used */


        for (kk=0;kk<N-M;kk++) {

            y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);

            mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];

        }

        for (;kk<N-1;kk++) {

            y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);

            mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];

        }

        y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);

        mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];


        mti = 0;

    }


    y = mt[mti++];


    /* Tempering */

    y ^= (y >> 11);

    y ^= (y << 7) & 0x9d2c5680UL;

    y ^= (y << 15) & 0xefc60000UL;

    y ^= (y >> 18);


    return y;

}


/* generates a random number on [0,0x7fffffff]-interval */

long genrand_int31(void)

{

    return (long)(genrand_int32()>>1);

}


/* generates a random number on [0,1]-real-interval */

double genrand_real1(void)

{

    return genrand_int32()*(1.0/4294967295.0); 

    /* divided by 2^32-1 */ 

}


/* generates a random number on [0,1)-real-interval */

double genrand_real2(void)

{

    return genrand_int32()*(1.0/4294967296.0); 

    /* divided by 2^32 */

}


/* generates a random number on (0,1)-real-interval */

double genrand_real3(void)

{

    return (((double)genrand_int32()) + 0.5)*(1.0/4294967296.0); 

    /* divided by 2^32 */

}


/* generates a random number on [0,1) with 53-bit resolution*/

double genrand_res53(void) 

{ 

    unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6; 

    return(a*67108864.0+b)*(1.0/9007199254740992.0); 

} 

/* These real versions are due to Isaku Wada, 2002/01/09 added */

If you rephrase the question as how far will the ball get before it stops and goes all the way back around to the next number, it may make a little more sense of the results of my code. Really, it can stop at any place (with equal probability!) and then go all the way around the other direction to finish painting.

Very cool. Thanks for posting.

Link to comment
Share on other sites

  • 0

Well, EventHorizon really put a lot of work into this one and his second simulation gets the correct answer. I will put the answer to question 1 in a separate spoiler in this reply. I will also give my answer to question 2 in a separate spoiler. I would suggest if you are tempted to look at spoilers, look at the answer to 1 and spend some time thinking about why, before looking at the answer for 2. Coming up with a simple way to explain the answer is more than half the fun of this problem:

Each number from 1 to 32 are exactly, equally likely to be the last number painted!

For a number to be the last number painted, it must achieve a parlay of sorts. First, the ball must land in a slot next that number. For example, if we are talking about the number 10, the ball must land in slot number 9 or slot number 11, having never landed in 10 yet.

Then, the ball must travel all the way around the wheel and paint the other slot that borders that number. Let's say the ball paints slot 9, it must now travel all the way around the wheel (this could take a long time of back and forth) and paint 11, before it ever paints 10. If that happens, 10 is the last number painted.

Now for the fun part. The first half of the "parlay" I described above will be achieved by every number on the wheel! If we think about number 19 for a random example, no matter how the ball travels around the wheel, at some point it will paint either 18 or 20, before it paints 19. The same can be said for 8. Either 7 or 9 will get painted before 8 gets painted, there's no way around this.

We can also look at the special cases of 32 and 1. Since 0 starts out painted, both of those numbers have achieved the first part of the parley, before the game begins. But, that doesn't make them any more likely than any of the other number, because all the other numbers will, at some point or another, find themselves with the ball right next to them, needing the ball to turn direction and travel all the way around the wheel, to complete the parlay.

Since every number on the wheel is 100% certain to achieve part 1 of the parlay, and the second half of the parlay will be equally hard to achieve for all numbers, every number will have an equal chance to be last.

First (and obvious to the most casual observer), all numbers have the same probability as those numbers with the same distance smallest distance to 0. (eg, 1 and 32, 2 and 31, 16 and 17, etc)

Second, really low and really high numbers are close to 0, so they will have a very low chance of being the last number painted.

Third, I believe it would be more likely to paint 16 and 17 before painting both 15 and 18, and also more likely to paint 15 through 18 before painting 14 and 19, etc. This is because once it gets to that area it would need to travel all the way back around to the other side to get the other number where it would be more likely to travel the short distance through.

So my guess will be 7-9 and 24-26.... something like that. Probably closer to 16-17 than that, but still somewhere close to 90 degrees away from 0.

I'm actually kinda interested now.... I'll code this up a little later and post code/results.

Link to comment
Share on other sites

  • 0

#==================================================================

# Program: Roulette Walk

# Programmer: Phillip Von Root

# Date: May 26, 2010

# Abstract: We start with a roulette wheel that is numbered from 0 to 32

#in order, clockwise around the wheel. The ball starts in the 0 slot. The

#ball has paint on it that won't dry, so it leaves a mark whenever it visits

#a slot on the wheel. We flip a fair coin to determine the ball's movements.

#If it comes up heads, the ball moves one spot clockwise. If we flip

#tails, it moves one spot counter-clockwise. We will continue flipping, until

#every slot gets marked with some paint. You have two tasks:

# 1. Determine which numbers, if any, are more likely than the others to be

#the last slot to get marked with paint (the 0 is out of the running as the

#wet ball starts there)

#2. Support your answer with logic and simple English, no fancy formulas

import random #input random module

COIN_FLIP = 2

def main(): #define main

print "This should determine what last position on the wheel"

print "gets painted most or least often"

count_max = raw_input("Enter total number of games to play: ")

count_max = count_max.strip() #i hate white spaces

while str(count_max).isdigit() == False: #while not a valid counter

count_max = raw_input("Enter the number of games to play: ")

count_max = count_max.strip() #more needless white spaces

count_max = int(count_max) #converting input to int

games_played = count_max #saving games_played

total_slot_land = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] #initialized list to

#number of times it lands on any slot

total_slot_ending = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]#initialized list to

#count how many times it ends on each slot

total_total_land = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]#initialized list to

#count how many total times it lands on any slot

current_slot = 0 #it starts at zero

hit_all = False #it hasn't hit_all yet

while count_max > 0: #while not end of user's defined iterrations

while hit_all == False: #countinue while haven't hit_all yet

if current_slot == -1:#simulating a circle

current_slot = 32 #because 1 less then zero is 32

elif current_slot == 33:#simulating a circle

current_slot = 0#because 1 more then 32 is zero

total_slot_land[current_slot] += 1#accumulate which slot it's on

total_total_land[current_slot] +=1#total accumulations

slots_hit = 0 #initializing test if slots_hit

for slot in total_slot_land:#test each slot in total_slot_land

if slot > 0:#if it's ever landed on it or not

slots_hit += 1#then it's hit this slot

if slots_hit == 33:#if it's hit all 33 slots

total_slot_ending[current_slot] += 1#accumulate for this slot

hit_all = True#it's hit all slots

total_slot_land = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

#reinitialize total_slot_land

current_slot += coin_flip() #move ball up 1 or down 1

hit_all = False#reset hit_all to do that again

count_max -= 1#decrement counter for user defined iterrations

index = 0 #used to print lists

print "Slot Ends Total Lands"

for slots in total_slot_land:

print "%2.01i" % index , " %2.01i" %\

total_slot_ending[index], " %2.01i" %\

total_total_land[index]

index += 1

index = 0

total_total_ending = 0

for slots in total_slot_land:#make sure ends up total = games_played

total_total_ending += total_slot_ending[index]

index +=1

print "Games Played %2.01i" % total_total_ending

def coin_flip(): #defines flipping a coin

choice = (random.randint(1,2)) #flips a coin

if choice < COIN_FLIP:

move = 1

else:

move = -1

return (move) #returns which way to move

main()

This should determine what last position on the wheel

gets painted most or least often

Enter total number of games to play: 1000000

Slot Ends Total Lands

0 0 16040142

1 45460 16028853

2 29994 16015356

3 30396 16019813

4 30257 16031610

5 30348 16027410

6 30253 16019402

7 30529 16008836

8 30471 15996387

9 30282 15992994

10 30164 15994661

11 30107 15999891

12 29960 15999982

13 30581 15996221

14 30406 15993249

15 30560 15990919

16 30413 15996149

17 30396 16006966

18 30173 16015242

19 30204 16011185

20 30266 16006917

21 30318 16012330

22 30456 16012260

23 30021 16010862

24 30142 16016318

25 30302 16015229

26 30362 16009093

27 30212 16010988

28 30463 16019433

29 30210 16028382

30 30413 16031237

31 30115 16030199

32 45766 16035759

Games Played 1000000

#==================================================================

# Program: Roulette Walk

# Programmer: Phillip Von Root

# Date: May 26, 2010

# Abstract: We start with a roulette wheel that is numbered from 0 to 32

#in order, clockwise around the wheel. The ball starts in the 0 slot. The

#ball has paint on it that won't dry, so it leaves a mark whenever it visits

#a slot on the wheel. We flip a fair coin to determine the ball's movements.

#If it comes up heads, the ball moves one spot clockwise. If we flip

#tails, it moves one spot counter-clockwise. We will continue flipping, until

#every slot gets marked with some paint. You have two tasks:

# 1. Determine which numbers, if any, are more likely than the others to be

#the last slot to get marked with paint (the 0 is out of the running as the

#wet ball starts there)

#2. Support your answer with logic and simple English, no fancy formulas

import random #input random module

COIN_FLIP = 2

def main(): #define main

print "This should determine what last position on the wheel"

print "gets painted most or least often"

count_max = raw_input("Enter total number of games to play: ")

count_max = count_max.strip() #i hate white spaces

while str(count_max).isdigit() == False: #while not a valid counter

count_max = raw_input("Enter the number of games to play: ")

count_max = count_max.strip() #more needless white spaces

count_max = int(count_max) #converting input to int

games_played = count_max #saving games_played

total_slot_land = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] #initialized list to

#number of times it lands on any slot

total_slot_ending = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]#initialized list to

#count how many times it ends on each slot

total_total_land = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]#initialized list to

#count how many total times it lands on any slot

current_slot = 0 #it starts at zero

hit_all = False #it hasn't hit_all yet

while count_max > 0: #while not end of user's defined iterrations

while hit_all == False: #countinue while haven't hit_all yet

if current_slot == -1:#simulating a circle

current_slot = 32 #because 1 less then zero is 32

elif current_slot == 33:#simulating a circle

current_slot = 0#because 1 more then 32 is zero

total_slot_land[current_slot] += 1#accumulate which slot it's on

total_total_land[current_slot] +=1#total accumulations

slots_hit = 0 #initializing test if slots_hit

for slot in total_slot_land:#test each slot in total_slot_land

if slot > 0:#if it's ever landed on it or not

slots_hit += 1#then it's hit this slot

if slots_hit == 33:#if it's hit all 33 slots

total_slot_ending[current_slot] += 1#accumulate for this slot

hit_all = True#it's hit all slots

total_slot_land = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

#reinitialize total_slot_land

current_slot += coin_flip() #move ball up 1 or down 1

hit_all = False#reset hit_all to do that again

count_max -= 1#decrement counter for user defined iterrations

index = 0 #used to print lists

print "Slot Ends Total Lands"

for slots in total_slot_land:

print "%2.01i" % index , " %2.01i" %\

total_slot_ending[index], " %2.01i" %\

total_total_land[index]

index += 1

index = 0

total_total_ending = 0

for slots in total_slot_land:#make sure ends up total = games_played

total_total_ending += total_slot_ending[index]

index +=1

print "Games Played %2.01i" % total_total_ending

def coin_flip(): #defines flipping a coin

choice = (random.randint(1,2)) #flips a coin

if choice < COIN_FLIP:

move = 1

else:

move = -1

return (move) #returns which way to move

main()

Well I don't think that's right. I'm not to keen on C(not having done it in 14 years) ... would have posted this a few days ago but I had to work and still wasn't sure about it. Why wouldn't this be right ... it's written in Python

Link to comment
Share on other sites

  • 0

I'm a newbie


#==================================================================

# Program:      	   Roulette Walk

# Programmer:   Phillip Von Root

# Date:         	   May 26, 2010

# Abstract:     We start with a roulette wheel that is numbered from 0 to 32

#in order, clockwise around the wheel. The ball starts in the 0 slot. The

#ball has paint on it that won't dry, so it leaves a mark whenever it visits

#a slot on the wheel. We flip a fair coin to determine the ball's movements.

#If it comes up heads, the ball moves one spot clockwise. If we flip 

#tails, it moves one spot counter-clockwise. We will continue flipping, until

#every slot gets marked with some paint. You have two tasks:

# 1. Determine which numbers, if any, are more likely than the others to be

#the last slot to get marked with paint (the 0 is out of the running as the

#wet ball starts there)

#2. Support your answer with logic and simple English, no fancy formulas 


import random                                       #input random module

COIN_FLIP = 2


def main():                                         #define main

    print "This should determine what last position on the wheel"

    print "gets painted most or least often"


    count_max = raw_input("Enter total number of games to play: ")

    count_max = count_max.strip()            #i hate white spaces

    while str(count_max).isdigit() == False: #while not a valid counter

            count_max = raw_input("Enter the number of games to play: ")

            count_max = count_max.strip()    #more needless white spaces

    count_max = int(count_max)               #converting input to int

    games_played = count_max                 #saving games_played


    total_slot_land = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

                       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] #initialized list to

                                         #number of times it lands on any slot

    total_slot_ending = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

                         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]#initialized list to

                                #count how many times it ends on each slot

    total_total_land = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

                        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]#initialized list to

                        #count how many total times it lands on any slot

    current_slot = 0   #it starts at zero

    hit_all = False    #it hasn't hit_all yet


    while count_max > 0:  #while not end of user's defined iterrations

        while hit_all == False:   #countinue while haven't hit_all yet

            if current_slot == -1:#simulating a circle

                current_slot = 32 #because 1 less then zero is 32

            elif current_slot == 33:#simulating a circle

                current_slot = 0#because 1 more then 32 is zero

            total_slot_land[current_slot] += 1#accumulate which slot it's on

            total_total_land[current_slot] +=1#total accumulations

            slots_hit = 0  #initializing test if slots_hit

            for slot in total_slot_land:#test each slot in total_slot_land

                if slot > 0:#if it's ever landed on it or not

                    slots_hit += 1#then it's hit this slot

                if slots_hit == 33:#if it's hit all 33 slots

                    total_slot_ending[current_slot] += 1#accumulate for this slot

                    hit_all = True#it's hit all slots

                    total_slot_land = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

                                       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

                                                #reinitialize total_slot_land

            current_slot += coin_flip() #move ball up 1 or down 1

        hit_all = False#reset hit_all to do that again

        count_max -= 1#decrement counter for user defined iterrations

    index = 0  #used to print lists

    print "Slot              Ends                        Total Lands"

    for slots in total_slot_land:

        print "%2.01i" % index , "               %2.01i" %\

              total_slot_ending[index], "                             %2.01i" %\

              total_total_land[index]

        index += 1

    index = 0

    total_total_ending = 0

    for slots in total_slot_land:#make sure ends up total = games_played

        total_total_ending += total_slot_ending[index]

        index +=1

    print "Games Played      %2.01i" % total_total_ending


def coin_flip():                              #defines flipping a coin

    choice = (random.randint(1,2))               #flips a coin

    if choice < COIN_FLIP:

        move = 1

    else:

        move = -1


    return (move)        #returns which way to move


main()

Results of 1,000,000 games

This should determine what last position on the wheel

gets painted most or least often

Enter total number of games to play: 1000000

Slot Ends Total Lands

0 0 16040142

1 45460 16028853

2 29994 16015356

3 30396 16019813

4 30257 16031610

5 30348 16027410

6 30253 16019402

7 30529 16008836

8 30471 15996387

9 30282 15992994

10 30164 15994661

11 30107 15999891

12 29960 15999982

13 30581 15996221

14 30406 15993249

15 30560 15990919

16 30413 15996149

17 30396 16006966

18 30173 16015242

19 30204 16011185

20 30266 16006917

21 30318 16012330

22 30456 16012260

23 30021 16010862

24 30142 16016318

25 30302 16015229

26 30362 16009093

27 30212 16010988

28 30463 16019433

29 30210 16028382

30 30413 16031237

31 30115 16030199

32 45766 16035759

Games Played 1000000

Edited by PVRoot
Link to comment
Share on other sites

  • 0

I'm a newbie


#==================================================================

# Program:      	   Roulette Walk

# Programmer:   Phillip Von Root

# Date:         	   May 26, 2010

# Abstract:     We start with a roulette wheel that is numbered from 0 to 32

#in order, clockwise around the wheel. The ball starts in the 0 slot. The

#ball has paint on it that won't dry, so it leaves a mark whenever it visits

#a slot on the wheel. We flip a fair coin to determine the ball's movements.

#If it comes up heads, the ball moves one spot clockwise. If we flip 

#tails, it moves one spot counter-clockwise. We will continue flipping, until

#every slot gets marked with some paint. You have two tasks:

# 1. Determine which numbers, if any, are more likely than the others to be

#the last slot to get marked with paint (the 0 is out of the running as the

#wet ball starts there)

#2. Support your answer with logic and simple English, no fancy formulas 


import random                                       #input random module

COIN_FLIP = 2


def main():                                         #define main

    print "This should determine what last position on the wheel"

    print "gets painted most or least often"


    count_max = raw_input("Enter total number of games to play: ")

    count_max = count_max.strip()            #i hate white spaces

    while str(count_max).isdigit() == False: #while not a valid counter

            count_max = raw_input("Enter the number of games to play: ")

            count_max = count_max.strip()    #more needless white spaces

    count_max = int(count_max)               #converting input to int

    games_played = count_max                 #saving games_played


    total_slot_land = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

                       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] #initialized list to

                                         #number of times it lands on any slot

    total_slot_ending = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

                         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]#initialized list to

                                #count how many times it ends on each slot

    total_total_land = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

                        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]#initialized list to

                        #count how many total times it lands on any slot

    current_slot = 0   #it starts at zero

    hit_all = False    #it hasn't hit_all yet


    while count_max > 0:  #while not end of user's defined iterrations

        while hit_all == False:   #countinue while haven't hit_all yet

            if current_slot == -1:#simulating a circle

                current_slot = 32 #because 1 less then zero is 32

            elif current_slot == 33:#simulating a circle

                current_slot = 0#because 1 more then 32 is zero

            total_slot_land[current_slot] += 1#accumulate which slot it's on

            total_total_land[current_slot] +=1#total accumulations

            slots_hit = 0  #initializing test if slots_hit

            for slot in total_slot_land:#test each slot in total_slot_land

                if slot > 0:#if it's ever landed on it or not

                    slots_hit += 1#then it's hit this slot

                if slots_hit == 33:#if it's hit all 33 slots

                    total_slot_ending[current_slot] += 1#accumulate for this slot

                    hit_all = True#it's hit all slots

                    total_slot_land = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

                                       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

                                                #reinitialize total_slot_land

            current_slot += coin_flip() #move ball up 1 or down 1

        hit_all = False#reset hit_all to do that again

        count_max -= 1#decrement counter for user defined iterrations

    index = 0  #used to print lists

    print "Slot              Ends                        Total Lands"

    for slots in total_slot_land:

        print "%2.01i" % index , "               %2.01i" %\

              total_slot_ending[index], "                             %2.01i" %\

              total_total_land[index]

        index += 1

    index = 0

    total_total_ending = 0

    for slots in total_slot_land:#make sure ends up total = games_played

        total_total_ending += total_slot_ending[index]

        index +=1

    print "Games Played      %2.01i" % total_total_ending


def coin_flip():                              #defines flipping a coin

    choice = (random.randint(1,2))               #flips a coin

    if choice < COIN_FLIP:

        move = 1

    else:

        move = -1


    return (move)        #returns which way to move


main()
Results of 1,000,000 games This should determine what last position on the wheel gets painted most or least often Enter total number of games to play: 1000000

Slot              Ends                             Total Lands

 0                 0                                 16040142

 1                45460                              16028853

 2                29994                              16015356

 3                30396                              16019813

 4                30257                              16031610

 5                30348                              16027410

 6                30253                              16019402

 7                30529                              16008836

 8                30471                              15996387

 9                30282                              15992994

10                30164                              15994661

11                30107                              15999891

12                29960                              15999982

13                30581                              15996221

14                30406                              15993249

15                30560                              15990919

16                30413                              15996149

17                30396                              16006966

18                30173                              16015242

19                30204                              16011185

20                30266                              16006917

21                30318                              16012330

22                30456                              16012260

23                30021                              16010862

24                30142                              16016318

25                30302                              16015229

26                30362                              16009093

27                30212                              16010988

28                30463                              16019433

29                30210                              16028382

30                30413                              16031237

31                30115                              16030199

32                45766                              16035759

Games Played      1000000

Link to comment
Share on other sites

  • 0

#==================================================================

# Program:      	   Roulette Walk

# Programmer:   Phillip Von Root

# Date:         	   May 26, 2010

# Abstract:     We start with a roulette wheel that is numbered from 0 to 32

#in order, clockwise around the wheel. The ball starts in the 0 slot. The

#ball has paint on it that won't dry, so it leaves a mark whenever it visits

#a slot on the wheel. We flip a fair coin to determine the ball's movements.

#If it comes up heads, the ball moves one spot clockwise. If we flip 

#tails, it moves one spot counter-clockwise. We will continue flipping, until

#every slot gets marked with some paint. You have two tasks:

# 1. Determine which numbers, if any, are more likely than the others to be

#the last slot to get marked with paint (the 0 is out of the running as the

#wet ball starts there)

#2. Support your answer with logic and simple English, no fancy formulas 


import random                                       #input random module

COIN_FLIP = 2


def main():                                         #define main

    print "This should determine what last position on the wheel"

    print "gets painted most or least often"


    count_max = raw_input("Enter total number of games to play: ")

    count_max = count_max.strip()            #i hate white spaces

    while str(count_max).isdigit() == False: #while not a valid counter

            count_max = raw_input("Enter the number of games to play: ")

            count_max = count_max.strip()    #more needless white spaces

    count_max = int(count_max)               #converting input to int

    games_played = count_max                 #saving games_played


    total_slot_land = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

                       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] #initialized list to

                                         #number of times it lands on any slot

    total_slot_ending = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

                         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]#initialized list to

                                #count how many times it ends on each slot

    total_total_land = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

                        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]#initialized list to

                        #count how many total times it lands on any slot

    current_slot = 0   #it starts at zero

    hit_all = False    #it hasn't hit_all yet


    while count_max > 0:  #while not end of user's defined iterrations

        while hit_all == False:   #countinue while haven't hit_all yet

            if current_slot == -1:#simulating a circle

                current_slot = 32 #because 1 less then zero is 32

            elif current_slot == 33:#simulating a circle

                current_slot = 0#because 1 more then 32 is zero

            total_slot_land[current_slot] += 1#accumulate which slot it's on

            total_total_land[current_slot] +=1#total accumulations

            slots_hit = 0  #initializing test if slots_hit

            for slot in total_slot_land:#test each slot in total_slot_land

                if slot > 0:#if it's ever landed on it or not

                    slots_hit += 1#then it's hit this slot

                if slots_hit == 33:#if it's hit all 33 slots

                    total_slot_ending[current_slot] += 1#accumulate for this slot

                    hit_all = True#it's hit all slots

                    total_slot_land = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\

                                       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

                                                  #reinitialize total_slot_land

            current_slot += coin_flip() #move ball up 1 or down 1

        hit_all = False#reset hit_all to do that again

        current_slot = 0 #initialize current_slot back to zero

        count_max -= 1#decrement counter for user defined iterrations

    index = 0  #used to print lists

    print "Slot              Ends                        Total Lands"

    for slots in total_slot_land:

        print "%2.01i" % index , "               %2.01i" %\

              total_slot_ending[index], "                             %2.01i" %\

              total_total_land[index]

        index += 1

    index = 0

    total_total_ending = 0

    for slots in total_slot_land:#make sure ends up total = games_played

        total_total_ending += total_slot_ending[index]

        index +=1

    print "Games Played      %2.01i" % total_total_ending


def coin_flip():                              #defines flipping a coin

    choice = (random.randint(1,2))               #flips a coin

    if choice < COIN_FLIP:

        move = 1

    else:

        move = -1


    return (move)        #returns which way to move


main()

Edited by PVRoot
Link to comment
Share on other sites

  • 0

This should determine what last position on the wheel

gets painted most or least often

Enter total number of games to play: 1000000


Slot              Ends                             Total Lands

 0                 0                                 21683344

 1                31421                              20710745

 2                31283                              19771335

 3                31236                              18902613

 4                31068                              18086129

 5                31096                              17326829

 6                31608                              16638696

 7                31316                              16016340

 8                31169                              15464044

 9                31203                              14968915

10                31124                              14524226

11                30973                              14150582

12                31168                              13841061

13                31455                              13584716

14                31549                              13390473

15                31245                              13267225

16                31234                              13203960

17                31365                              13205023

18                31392                              13272959

19                31304                              13405643

20                31194                              13600551

21                30880                              13859726

22                31326                              14178563

23                31160                              14550441

24                31346                              14986671

25                31540                              15473622

26                31426                              16022728

27                31159                              16651818

28                30943                              17343240

29                31182                              18092996

30                31314                              18902574

31                30956                              19781265

32                31365                              20719263

Games Played      1000000

What's funny though is the curve of total lands per slot but the total ends are all the same ... there could be a function that's graphable as opposed to a program and mass trials.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...