#number plate spotting
#to settle http://www.joyfeed.com/2011/09/the-mathematics-of-number-plate-spotting/

#assumptions are:
# - cars pass by with number plates uniformly distributed in the range 1..999.
# - game-player has no memory, or can't go back to previously-spotted cars.

from random import randrange

#consecutive number plate spotting
#start at 1. Have to see each number consecutively.
def cnps(limit):
	cars=0	#how many cars have gone by
	n=1
	while n<limit:
		cars+=1
		p=randrange(1,limit)	#a car goes by, with a random number plate
		if p==n:
			n+=1
	return cars

#non-consecutive number plate spotting
#need to see all numbers 1..limit in any order
def ncnps(limit):
	cars = 0	#how many cars have gone by
	spotted = [False for x in range(1,limit)]
	need=limit-1
	while need>0:
		cars+=1
		p=randrange(1,limit)	#a car goes by, with a random number plate
		if not spotted[p-1]:
			spotted[p-1] = True
			need -= 1
	return cars

if __name__ == '__main__':
	samples = 100
	limit = 1000

	carbar = sum([cnps(limit) for x in range(0,samples)])/samples
	print("Mean of %s goes of CNPS upto %s: %s cars" % (samples,limit,carbar))

	carbar = sum([ncnps(limit) for x in range(0,samples)])/samples
	print("Mean of %s goes of NCNPS upto %s: %s cars" % (samples,limit,carbar))
