Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

prog challenge

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-16 12:10

>>37
Eat shit.

Name: Anonymous 2010-09-20 1:37

>>41
``faggot"

Name: Anonymous 2010-09-20 7:14

toggaf

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-20 11:59

>>38

def stupid_prague_challenge(m, a, l):
    from random import randint
    while True:
        r = [randint(1, m) for k in range(l)]
        if (sum(r) / l) == a:
            return r


EXPERT ENTERPRISE PROGRAMMER

Name: Anonymous 2010-09-20 13:29

Amphetamines

Name: Anonymous 2010-09-20 14:52

>>49
Eat shit.

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: SAGEFAULT 2010-09-22 18:36

SAGEFAULT

Name: TEST !DPcnVwI3us 2010-09-22 18:52

ddddeeer

Name: TEST !0whFZxVQXI 2010-09-22 18:53

?

Name: Anonymous 2010-12-06 9:40

Back to /b/, ``GNAA Faggot''

Name: Fuck off, !Ep8pui8Vw2 2010-12-13 0:07

>>57
Fuck off, ``faggot''.

Name: Fuck off, !Ep8pui8Vw2 2010-12-13 13:02

>>58
Fuck off, ``faggot''.

Name: Fuck off, !Ep8pui8Vw2 2010-12-13 13:02

>>59
Fuck off, ``faggot''.

Name: Anonymous 2010-12-13 13:09

Fag off, ``fuckkot''

Name: Anonymous 2010-12-13 14:22

Fag ott, ``fuckoff''

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: Fuck off, !Ep8pui8Vw2 2010-12-13 15:07

>>63
Fuck off, ``faggot''.

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''.

Name: Anonymous 2010-12-13 16:50

>>66
u first

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List