Example #1
0
 def do_GET(self):
     if self.path != '/':
         self.send_error(404)
         return
     s = SuDoKu()
     t0 = time.time()
     generated = s.generate()
     t1 = time.time()
     resolved = s.resolve()[0]
     t2 = time.time()
     difficulty = s.estimate()[0]
     substitutions = {
         'gen': s.to_string('html', generated),
         'gen_t': (t1 - t0) * 1000,
         'res': s.to_string('html', resolved),
         'res_t': (t2 - t1) * 1000,
         'dif': difficulty,
         'year': datetime.date.today().year,
     }
     html = (TEMPLATE % substitutions).encode('utf-8')
     self.send_response(200)
     self.send_header('Content-Type', 'application/xhtml+xml')
     self.send_header('Content-Length', len(html))
     self.end_headers()
     self.wfile.write(html)
Example #2
0
def decodeAndSolve(image, showSolution=False):
    d = Decoder(image)
    d.decode()
    s = SuDoKu(d.puzzle)
    solution = s.solution()
    if showSolution:
        img = copy(d.puzzleImage)
        img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
        for q, p in ((x, y) for x in (i * 100 + 30 for i in range(9))
                     for y in (i * 100 + 70 for i in range(9))):
            if ((q - 30) / 100, (p - 70) / 100) not in d.numberLocations:
                cv2.putText(img,
                            str(solution[(q - 30) / 100][(p - 70) / 100]),
                            (q, p),
                            cv2.FONT_HERSHEY_PLAIN,
                            4, (0, 150, 0),
                            thickness=6)
        cv2.imshow('Solution - Press any key to exit.', img)
        cv2.waitKey(0)
Example #3
0
def decodeAndSolve(image, showSolution=False):
    d = Decoder(image)
    d.decode()
    s = SuDoKu(d.puzzle)
    solution = s.solution()
    if showSolution:
        img = copy(d.puzzleImage)
        img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
        for q, p in ((x, y) for x in (i * 100 + 30 for i in range(9)) for y in (i * 100 + 70 for i in range(9))):
            if ((q - 30) / 100, (p - 70) / 100) not in d.numberLocations:
                cv2.putText(
                    img,
                    str(solution[(q - 30) / 100][(p - 70) / 100]),
                    (q, p),
                    cv2.FONT_HERSHEY_PLAIN,
                    4,
                    (0, 150, 0),
                    thickness=6,
                )
        cv2.imshow("Solution - Press any key to exit.", img)
        cv2.waitKey(0)
Example #4
0
def run_tests():
    hpy().heapu()  # pre-heating
    print('\n========   begin    ========\n')
    print(hpy().heapu())
    print('\n========    init    ========\n')
    s = SuDoKu()
    print(hpy().heapu())
    print('\n========    read    ========\n')
    s.from_string(problem)
    print(hpy().heapu())
    print('\n========  resolve   ========\n')
    s.resolve()
    print(hpy().heapu())
    print('\n========  generate  ========\n')
    s.generate()
    print(hpy().heapu())
    print('\n========    end     ========\n')
Example #5
0
def run_tests():
    hpy().heapu() # pre-heating
    print('\n========   begin    ========\n')
    print(hpy().heapu())
    print('\n========    init    ========\n')
    s = SuDoKu()
    print(hpy().heapu())
    print('\n========    read    ========\n')
    s.from_string(problem)
    print(hpy().heapu())
    print('\n========  resolve   ========\n')
    s.resolve()
    print(hpy().heapu())
    print('\n========  generate  ========\n')
    s.generate()
    print(hpy().heapu())
    print('\n========    end     ========\n')