gabhijit
BAN USERWondering why this works - (Though must admit this works perfectly well). The key here is to get up to n^2 eg. for the given input case of 5 and 7. I tried 4*a + b (expecting to give random numbers in the range 0 to 16 - that didn't work). Tried a more general solution -- below .. Is there a way of getting this to work when m > n^2?
#### Given a random number generator from 1 to n, generate a random number
#### from 1 to m (m > n)
import random
def randN(n):
return random.randint(1,n)
def randM(m,n):
a = randN(n) - 1
b = randN(n) - 1
r = n*a + b
if r > max :
return None
return r
m = 15
n = 5
a = [0] * m
max = n * n
max = max - max % m
print max
max = max - 1
for i in range(100000):
r = randM(m,n)
while r is None:
r = randM(m,n)
r = r % m
a[r] = a[r] + 1
print a
As usual - proper indentation is left as an exercise!
- gabhijit November 04, 2012
This is where a question is not clear to me ---
- gabhijit November 06, 2012in a string aaaabccdddd - b is the first non-repeating character
in a string abaaaaaaabb - b isthe first non-repeating character.
The question was not quite clear. My solution assumes the above is the question.. you've to remember first and keep xoring with that.