Exemple #1
0
def auto_congruent_polyomino_split(figure, n):
    """
    Split given `figure` to congruent polyominos of size `n`.
    """
    ans = []
    for pol in pm.free(pm.generate(n)):
        ans.append(_solution_generator(figure, set(pol.transforms())))
    # print(zip(*ans)
    return itertools.chain(*ans)
Exemple #2
0
    def submit(self):
        # clear the canvas
        self.canvas.delete(ALL)

        ##        try:
        n = int(self.scale_size.get())
        ##        except ValueError:
        ##            self.canvas.create_text(100, 100,
        ##                                    text="Must input number", fill="red")
        ##            return
        sym = self.sym_value.get()
        symcolor = self.symcolor_value.get()

        if sym == 0:
            minos = sorted(_mino.free(_mino.generate(n)), key=_mino.mino_key)
        elif sym == 1:
            minos = sorted(_mino.one_sided(_mino.generate(n)),
                           key=_mino.mino_key)
        else:
            minos = sorted(_mino.generate(n), key=_mino.mino_key)

        text = ("There are {0} {1} polyominoes of order {2}".format(
            len(minos), SYM_OPTS[sym], n))
        self.canvas.create_text(CANVAS_WIDTH // 2, 25, text=text)

        # Determine sizes
        size = 5
        padding = 2
        margin = 40
        minos_per_line = (CANVAS_WIDTH - margin * 2) // ((n + padding) * size)
        ypos = margin

        scroll_height = 2 * margin + (n + padding) * size * (len(minos) //
                                                             minos_per_line)
        self.canvas.config(scrollregion=(0, 0, CANVAS_WIDTH, scroll_height))
        while minos:
            for i in range(minos_per_line):
                if not minos:
                    break
                xpos = margin + ((n + padding) * size) * i
                mino = minos.pop()
                draw_mino(
                    self.canvas,
                    mino,
                    xpos,
                    ypos,
                    size,
                    fill=(SYM_COLORS[mino.symmetry()] if symcolor else "gray"))
            ypos += (n + padding) * size
Exemple #3
0
 def test_generate(self):
     # Check sizes of the generation
     sizes_fixed = [0, 1, 2, 6, 19, 63, 216, 760, 2725, 9910]
     sizes_onesided = [0, 1, 1, 2, 7, 18, 60, 196, 704, 2500]
     sizes_free = [0, 1, 1, 2, 5, 12, 35, 108, 369, 1285]
     for i in range(10):
         minos = mino.generate(i)
         minos_onesided = mino.one_sided(minos)
         minos_free = mino.free(minos)
         self.assertEqual(sizes_fixed[i], len(minos),
                          msg="Wrong fixed size for n={0}".format(i))
         self.assertEqual(sizes_onesided[i], len(minos_onesided),
                          msg="Wrong onesided size for n={0}".format(i))
         self.assertEqual(sizes_free[i], len(minos_free),
                          msg="Wrong free size for n={0}".format(i))
Exemple #4
0
 def test_generate(self):
     # Check sizes of the generation
     sizes_fixed = [0, 1, 2, 6, 19, 63, 216, 760, 2725, 9910]
     sizes_onesided = [0, 1, 1, 2, 7, 18, 60, 196, 704, 2500]
     sizes_free = [0, 1, 1, 2, 5, 12, 35, 108, 369, 1285]
     for i in range(10):
         minos = mino.generate(i)
         minos_onesided = mino.one_sided(minos)
         minos_free = mino.free(minos)
         self.assertEqual(sizes_fixed[i],
                          len(minos),
                          msg="Wrong fixed size for n={0}".format(i))
         self.assertEqual(sizes_onesided[i],
                          len(minos_onesided),
                          msg="Wrong onesided size for n={0}".format(i))
         self.assertEqual(sizes_free[i],
                          len(minos_free),
                          msg="Wrong free size for n={0}".format(i))
Exemple #5
0
    def submit(self):
        # clear the canvas
        self.canvas.delete(ALL)

##        try:
        n = int(self.scale_size.get())
##        except ValueError:
##            self.canvas.create_text(100, 100,
##                                    text="Must input number", fill="red")
##            return
        sym = self.sym_value.get()
        symcolor = self.symcolor_value.get()
        
        if sym == 0:
            minos = sorted(_mino.free(_mino.generate(n)), key=_mino.mino_key)
        elif sym == 1:
            minos = sorted(_mino.one_sided(_mino.generate(n)), key=_mino.mino_key)
        else:
            minos = sorted(_mino.generate(n), key=_mino.mino_key)

        text = ("There are {0} {1} polyominoes of order {2}".format(
            len(minos), SYM_OPTS[sym], n))
        self.canvas.create_text(CANVAS_WIDTH//2, 25, text=text)

        # Determine sizes
        size = 5
        padding = 2
        margin = 40
        minos_per_line = (CANVAS_WIDTH - margin * 2) // ((n + padding) * size)
        ypos = margin

        scroll_height = 2*margin + (n+padding)*size*(len(minos)//minos_per_line)
        self.canvas.config(scrollregion=(0,0,CANVAS_WIDTH, scroll_height))
        while minos:
            for i in range(minos_per_line):
                if not minos:
                    break
                xpos = margin + ((n + padding) * size) * i
                mino = minos.pop()
                draw_mino(self.canvas, mino,
                          xpos, ypos, size,
                          fill=(SYM_COLORS[mino.symmetry()]
                                if symcolor else "gray"))
            ypos += (n+padding) * size