Iteration for Factorials

Anurag anuraguniyal at gmail.com
Tue Oct 30 04:12:27 EDT 2007


What about this no map, reduce, mutiplication or even addition
Its truly interative and You will need to interate till infinity if
you want correct answer ;)

def factorial(N):
    """
    Increase I ...and go on increasing...
    """
    import random

    myNumer = range(N)
    count = 0
    I = 10000 #10**(N+1)
    for i in range(I):
        bucket = range(N)
        number = []
        for i in range(N):
            k = bucket[ random.randrange(0,len(bucket))]
            bucket.remove(k)
            number.append(k)

        if number == myNumer:
            count+=1

    return int(I*1.0/count+.5)




More information about the Python-list mailing list