Name:
Anonymous
2010-09-13 8:38
Create a sequence of random integers with the following given: max, average, length
Example, with m = 7, a = 4, l = 5, you get [ 5, 2, 2, 4, 7 ].
Name:
Anonymous
2010-09-20 7:20
Just a reminder: a solution has already been presented
[1] yet none of you fucktards are intelligent enough to understand it.
[1]:
http://pastebin.com/UQgGuJpm
Name:
Anonymous
2010-09-21 4:55
import random
def memoized(f):
d = {}
def wrapper(*args):
if args not in d:
d[args] = f(*args)
return d[args]
return wrapper
@memoized
def cnt(ncnt, nsum, nmax):
if ncnt == 1:
return 1 if nsum <= nmax else 0
if nsum == 0:
return 1
return sum(cnt(ncnt - 1, nsum - cur, nmax)
for cur in range(min(nsum, nmax) + 1))
def select(ncnt, nsum, nmax, n):
if ncnt == 1:
assert n == 0
assert nsum <= nmax
return [nsum]
for cur in range(nmax + 1):
c = cnt(ncnt - 1, nsum - cur, nmax)
if n < c:
return [cur] + select(ncnt - 1, nsum - cur, nmax, n)
n -= c
assert False, 'overflow, %d remaining' % n
def select_random(ncnt, nsum, nmax):
total = cnt(ncnt, nsum, nmax)
n = random.randrange(0, total)
r = select(ncnt, nsum, nmax, n)
# print '%d of %d' % (n, total)
return r
if __name__ == '__main__':
try:
for i in range(28):
print '%3d' % i, select(3, 7, 5, i)
except AssertionError as err:
print err
for i in range(10):
print select_random(20, 200, 20)
print select_random(1, 15, 20)
for i in range(20):
print select_random(2, 1, 1)
Name:
Anonymous
2010-09-21 11:15
>>50
I can't help it if it's true.
Name:
Anonymous
2010-12-06 9:40
Back to /b/, ``GNAA Faggot''
Name:
Anonymous
2010-12-13 14:50
>>58
>>59
>>60
>>61
>>62
You are severely diminishing the quality of this thread, consider leaving
/prog/ or consider stop posting, thank you.
Name:
Anonymous
2010-12-13 16:26
>>63
l2quote faggot || gb2/b/ xD
lmao enjoy ban
Name:
Anonymous
2010-12-13 16:30
>>-,,,,,,-,--,,,-,,-
Go back to /b/, ``please''.