Exemple #1
0
def groupsizes(numpieces):
    r = []
    numcoms = len(probstat.Combination(range(numpieces), 3))
    numofeachletter = float(numcoms * 3) / numpieces
    for numgroups in range(2, numcoms):
        comspergroup = float(numcoms) / numgroups
        eachletterpergroup = numofeachletter / numgroups
        if whole(comspergroup) and whole(eachletterpergroup):
            r.append(numcoms / numgroups)
    return r
Exemple #2
0
def firstNode(numpieces, groupsize):

    pieces = [chr(65 + i) for i in range(numpieces)]
    coms = [''.join(triad) for triad in probstat.Combination(pieces, 3)]
    numcoms = len(coms)
    numgroups = numcoms / groupsize
    groups = [[coms[j] for j in range(i, numcoms, numgroups)] \
        for i in range(0, numgroups)]
    used = [[j for j in ''.join(i)] for i in groups]
    distrib = [[len([i for i in u if i == piece]) \
        for piece in pieces] for u in used]

    return Node(groups, distrib)
Exemple #3
0
import probstat

c = probstat.Combination(range(1, 5), 3)
should_be = [[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]

cp = []
for (i) in c:
    cp.append(i)

if (should_be != cp):
    raise 'Output isnt what it should be'

if (len(cp) != len(c)):
    print len(cp), len(c)
    raise 'Len of output does not match len of object'

slice_cp = cp[0:1]
slice = c[0:1]

slice_list = []
for (i) in slice:
    slice_list.append(i)
if (slice_list != slice_cp):
    raise "slice doesn't equal real output"

if (len(slice) != len(slice_cp)):
    raise 'len of slice doesnt match len of real slice'

if (c[0] != cp[0] or c[-1] != c[-1]):
    raise 'first or last elements not equal'
 def __str__(self):
     return '%s routers, %s links' % (len(
         self.routers), len(probstat.Combination(self.routers.keys(), 2)))