• sodoku

    I need help adapting this script for inputting the numbers from a picture of sudoku and insert the starting numbers into a console script, it does not work good for recognizing ones and sevens???

    Example of sudoku solver

    In my version I want to make the board is all zeros and when you take a picture it will add the numbers than solve, this combines the two programs (sudoku solver) & (ocr text recognition)

    board=[
       [5,8,4,1,0,0,0,0,0],
       [0,0,6,8,0,0,5,1,0],
       [0,0,0,0,5,4,7,0,6],
       [0,5,3,0,1,0,0,6,7],
       [0,0,0,0,2,0,0,0,0],
       [4,6,0,0,9,0,8,3,0],
       [7,0,8,5,4,0,0,0,0],
       [0,2,9,0,0,3,4,0,0],
       [0,0,0,0,0,1,3,7,9]
       ]
    
    
    
    def solve(bo):
    
       find = find_empty(bo)
       if not find:
           return True
       else:
           row,col = find
    
       for i in range(1,10):
           if valid(bo,i,(row,col)):
               bo[row][col] = i
    
               if solve(bo):
                   return True
    
               bo[row][col] = 0
    
       return False
    
    
    
    def valid(bo,num,pos):
       #check row
       for i in range(len(bo[0])):
           if bo[pos[0]][i] == num and pos[1] != i:
               return False
       #check column
       for i in range(len(bo[0])):
           if bo[i][pos[1]] == num and pos[0] != i:
               return False
       #check quadrant
       box_x = pos[1] // 3
       box_y = pos[0] // 3
    
       for i in range(box_y * 3, box_y * 3 + 3):
           for j in range(box_x * 3, box_x * 3 + 3):
               if bo[i][j] == num and (i,j) != pos:
                   return False
    
       return True
    
    
    
    def print_board(bo):
       for i in range(len(bo)):
           if i % 3 == 0 and i != 0:
               print('------+-------+------')
    
           for j in range(len(bo[0])):
               if j % 3 == 0 and j != 0:
                   print('|',end=' ')
               if j == 8:
                   print(bo[i][j])
               else:
                   print(str(bo[i][j])+ ' ', end='')
    
    def find_empty(bo):
       for i in range(len(bo)):
           for j in range(len(bo[0])):
               if bo[i][j] == 0:
                   return (i,j) # row, col
       return None
    
    
    
    print_board(board)
    solve(board)
    print('=====================')
    print_board(board)
    
    language_preference = ['fi','en','se']
    
    import photos, ui, dialogs
    import io
    from objc_util import *
    
    load_framework('Vision')
    VNRecognizeTextRequest = ObjCClass('VNRecognizeTextRequest')
    VNImageRequestHandler = ObjCClass('VNImageRequestHandler')
    
    def pil2ui(pil_image):
       buffer = io.BytesIO()
       pil_image.save(buffer, format='PNG')
       return ui.Image.from_data(buffer.getvalue())
    
    selection = dialogs.alert('Get pic', button1='Camera', button2='Photos')
    
    ui_image = None
    
    if selection == 1:
       pil_image = photos.capture_image()
       if pil_image is not None:
           ui_image = pil2ui(pil_image)
    elif selection == 2:
       ui_image = photos.pick_asset().get_ui_image()
    
    if ui_image is not None:
       print('Recognizing...\n')
    
       req = VNRecognizeTextRequest.alloc().init().autorelease()
       req.setRecognitionLanguages_(language_preference)
       handler = VNImageRequestHandler.alloc().initWithData_options_(ui_image.to_png(), None).autorelease()
    
       success = handler.performRequests_error_([req], None)
       if success:
           for result in req.results():
               print(result.text())
       else:
           print('Problem recognizing anything') ```

    posted in Pythonista read more
  • sodoku

    I will test it for sudoku in the console, well I will try to convert it to use in console for the sudoku solver if need help I’ll post a message

    posted in Pythonista read more
  • sodoku

    So there are a few edits in this thread I don’t know how to piece together to have the best edited version of this???

    posted in Pythonista read more
  • sodoku

    Also what’s the updated code posted by Mikael on GitHub used for is it same as this one posted here or not because it’s so much longer and bigger then this code posted on the forum, is it a better version then this one on the forum

    posted in Pythonista read more
  • sodoku

    So good news I got an iPhone 11 and I’m testing this on it, for sudoku, do the pictures taken save anywhere when used, just curious if I have to delete them because after I use it the pictures don’t show up in my pictures app

    posted in Pythonista read more
  • sodoku

    The thing is i understand the problem I’m encountering, and the main objective and goal I want to achieve, I just have no clue how to code the solution or if it’s even possible to code a solution, at this level of of coding it’s to easy to make a mistake and not code the proper order of operations

    I just know how to ask the smarter people the question, is it possible to fix this problem

    posted in Pythonista read more
  • sodoku

    The only work around I can think of is limiting only page 1 to have the add emoji input, and undo, and redo while removing those three actions from page 2 to kinda make it idiot/fool proof so the functions undo and redo doesn’t glitch, and users won’t get confused and ruin the order of operations
    So basically add emoji, undo and redo would only be available on page 1 and then page 2 would just be a viewable screen to observe then you would have to go back to page 1 to add, undo or redo

    Except that would kinda hinder the game play by adding to much unnecessary steps to manually back track, and it would ruin the experience and point of being an app that saves time

    I hope this could be fixed that would make this app seem more professional

    posted in Pythonista read more
  • sodoku

    I don’t know if my next question I got for you can be solved, okay so I have added @cvp’s code to mine and it works perfectly, except for the undo and redo functions have now become a little glitchy (not working perfectly), I was wondering if it’s possible to fix this or not??

    posted in Pythonista read more
  • sodoku

    Did @ccc add a suggestion to improve the coding that @cvp suggested just asking because I know how to add @cvp’s idea to my module I just don’t know where to add the code suggested by @ccc to my module

    posted in Pythonista read more
  • sodoku

    I think that solves my question thank you @cvp that will be the finishing touch to my first prototype app I’m developing I just need to buy a iPhone so I can add text recognition to my sudoku app

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!