Exemplo n.º 1
0
    # Find the number of non black unique colours
    black = solver_utils.get_colour_code('black')
    colours = grid_in_np[grid_in_np != black]
    n = len(np.unique(colours))

    n_rows, n_cols = grid_in_np.shape  # This is always 3 x 3
    grid_out_np = np.zeros((n_rows * n, n_cols * n), dtype='int64')

    for i in range(n_rows):
        for j in range(n_cols):
            colour = grid_in_np[i, j]  # Colour of pixel (i, j)
            grid_out_np[i * n:(i * n) + n, j * n:(j * n) + n] = colour

    # Convert back to list of lists
    grid_out = grid_out_np.tolist()

    return grid_out


if __name__ == '__main__':
    # Get the data for the associated JSON file
    data = solver_utils.parse_json_file()

    # Iterate through training grids and test grids
    for data_train in data['train']:
        solver_utils.solve_wrapper(data_train['input'], solve)

    for data_test in data['test']:
        solver_utils.solve_wrapper(data_test['input'], solve)
Exemplo n.º 2
0
    The solution requires the rows to be ordered such that the row with m coloured squares is row n, the row 
    with m-1 coloured squares is row n-1, etc. Another stipulation is that the coloured squares start from the 
    right such that in row n-1, column 0 is coloured black and in row n-2, column 0 and 1 are coloured black, etc.
    
    Input: input_grid - A python list of lists containing the unsolved grid
    
    Output: out_grid - A python list of lists containing the solved grid
    
    """
    # Change grid to NumPy array
    np_grid = np.array(input_grid)
    
    
    # Sort rows relative to eachother based on how many zeros they contain
    # Source: https://stackoverflow.com/questions/28518568/numpy-sort-matrix-rows-by-number-of-non-zero-entries
    # Accessed 23/11/2019
    np_grid = np_grid[(np_grid != 0).sum(axis=1).argsort()]
    # Sort entries in each row
    np_grid.sort(axis=1)
        
    return np_grid.tolist()
    
    
if __name__ == "__main__":
    data = solver_utils.parse_json_file()
    
    for training in data['train']:
        solver_utils.solve_wrapper(training['input'], solve)
        
    for testing in data['test']:
        solver_utils.solve_wrapper(testing['input'], solve)