Permutations, as might be expected, have the same basic structure as factorial. This implementation was inspired by the (paraphrased) statement that APL is a language in which one can "simulate shuffling a deck of cards and dealing a poker hand in four characters, none of which are alphabetic", and (perhaps not so coincidentally?) uses the Iverson Bracket (cf weave).

Invoke "python deal.py" to simulate dropping your deck on the floor, and "python deal.py | sort -tL +1" to reorder a dropped deck.

-Dave

from random import randint #L0 #L1 # sorted(deal(100)) == range (100) #L2 deal = lambda n : weave(randint(0,n-1),deal(n-1)) if n else [] #L3 weave = lambda i,js : [i]+[j+(j>=i) for j in js] #L4 shuffle = lambda xs : [xs[j] for j in deal(len (xs))] #L5 #L6 if __name__ == "__main__": #L7 #### floor sort! #### #L8 print ''.join(shuffle(open(__file__).readlines ())) #L9

--
To unsubscribe: http://lists.canonical.org/mailman/listinfo/kragen-discuss

Reply via email to