#!/usr/bin/env python3 #-*- coding: utf-8 -*- import math, sys from z3 import * # https://en.wikipedia.org/wiki/Rotation_matrix def rotate(pic, angle): WIDTH=len(pic[0]) HEIGHT=len(pic) #print WIDTH, HEIGHT assert WIDTH==HEIGHT ofs=int(WIDTH/2) out = [[0 for x in range(WIDTH)] for y in range(HEIGHT)] for x in range(-ofs,ofs): for y in range(-ofs,ofs): newX = int(round(math.cos(angle)*x - math.sin(angle)*y,3))+ofs newY = int(round(math.sin(angle)*x + math.cos(angle)*y,3))+ofs # clip at boundaries, hence min(..., HEIGHT-1) out[min(newX,HEIGHT-1)][min(newY,WIDTH-1)]=pic[x+ofs][y+ofs] return out vectors=[ [2, 2, 0, 3, 2, 2, 2, 2, 2, 4, 0] , [0, 0, 1, 2, 1, 2, 2, 4, 1, 1, 0] , [0, 0, 0, 0, 1, 9, 9, 2, 0, 0, 0] , [0, 0, 1, 2, 3, 3, 2, 0, 2, 1, 0]] WIDTH = HEIGHT = len(vectors[0]) s=Solver() cells=[[Int('cell_r=%d_c=%d' % (r,c)) for c in range(WIDTH)] for r in range(HEIGHT)] # monochrome picture, only 0's or 1's: for c in range(WIDTH): for r in range(HEIGHT): s.add(Or(cells[r][c]==0, cells[r][c]==1)) ANGLES=len(vectors) for a in range(ANGLES): angle=a*(math.pi/ANGLES) rows=rotate(cells, angle) r=0 for row in rows: # sum of row must be equal to the corresponding element of vector: s.add(Sum(*row)==vectors[a][r]) r=r+1 print (s.check()) m=s.model() for r in range(HEIGHT): for c in range(WIDTH): if str(m[cells[r][c]])=="1": sys.stdout.write("*") else: sys.stdout.write(" ") print ("")