Exemple #1
0
    def __init__(self, regions, totals, N=9):
        ok = False
        try:
            iter(regions)
            if len(regions) == N**2:
                ok = True
        except TypeError:
            ok = False
        if not ok:
            msg = "Regions should be an iterable of length %d for N=%d" 
            raise ValueError(msg % (N**2, N))
        if set(regions) != set(totals.keys()):
            raise ValueError('Each region should have a total provided')

        self.regions = regions
        self.totals = totals
        # todo: check totals are ints?

        Problem.__init__(self, entries="."*(N**2), N=N)
    def __init__(self, regions, totals, N=9):
        ok = False
        try:
            iter(regions)
            if len(regions) == N**2:
                ok = True
        except TypeError:
            ok = False
        if not ok:
            msg = "Regions should be an iterable of length %d for N=%d"
            raise ValueError(msg % (N**2, N))
        if set(regions) != set(totals.keys()):
            raise ValueError('Each region should have a total provided')

        self.regions = regions
        self.totals = totals
        # todo: check totals are ints?

        Problem.__init__(self, entries="." * (N**2), N=N)