All pastes #460222 Raw Edit

Miscellany

public text v1 · immutable
#460222 ·published 2007-04-26 22:47 UTC
rendered paste body
import os, sys
from random import *

def main(argv=None):
    sys.setrecursionlimit(10000)
    #print sys.getrecursionlimit()
    input = []
    for a in range(1,len(sys.argv)):
        for b in str.lower(sys.argv[a]):
            if ord(b) in range(97,122):
                input.append(b)
    high = 0
    solutions = 0
    for z in range(10000):
        check = korn(scramble(), input, input, 1)
        if check[0] > high:
            high = check[0]
            #offs = check[1]
            solutions = 0
        if check[0] == high:
            solutions = solutions+1
    #print offs
    print high
    print solutions
            
def korn(offset, scrambled, stop_word, count):
    rearranged = []
    for a in scrambled:
        rearranged.append(offset[a])
    if rearranged != list(stop_word):
        return korn(offset,rearranged,stop_word,count+1)
    else:
        return (count,offset)
        
def scramble():
    offset = list('abcdefghijklmnopqrstuvwxyz')
    shuffle(offset)
    return dict(zip(list('abcdefghijklmnopqrstuvwxyz'),offset))

if __name__ == "__main__":
    main()