<jupyter_start><jupyter_text>Result on Dataset A<jupyter_code>n1 = len(data_small1['quizzes'])
cnt = 0
for i in range(n1):
    s = solver(data_small1['quizzes'][i])
    if s == data_small1['solutions'][i]:
        cnt += 1

n2 = len(data_small2['quizzes'])
for i in range(n2):
    s = solver(data_small2['quizzes'][i])
    if s == data_small2['solutions'][i]:
        cnt += 1
print('success rate of Dataset A is {}' .format(100*cnt/(n1+n2)),'%')<jupyter_output>success rate of Dataset A is 33.71980676328502 %<jupyter_text>Result on Dataset B<jupyter_code>random_seed = 42
np.random.seed(random_seed)
dataB1 = pd.read_csv('large1.csv')
n1 = len(dataB1['quizzes'])
cnt = 0
sample1 = np.random.choice(n1, 1000)
for i in sample1:
    s = solver(dataB1['quizzes'][i])
    if s == dataB1['solutions'][i]:
        cnt += 1
dataB2 = pd.read_csv('large2.csv')
n2 = len(dataB2['quizzes'])
sample2 = np.random.choice(n2, 1000)
for i in sample2:
    s = solver(dataB2['quizzes'][i])
    if s == dataB2['solutions'][i]:
        cnt += 1
print('success rate of Dataset B is {}'.format(100*cnt/2000),'%')<jupyter_output>success rate of Dataset B is 90.9 %<jupyter_text>Result on Dataset CDear professor,You can copy the above codes in 'Result on Dataset B' and change the dataset to test dataset C  Additonal Codes  We know that the solution may not be unique in the sudoku problem, so the method which we use in the above codes is not valid enough.  Thus, our group creates a check function to find out whether the solution is valid but it is not shown in the soultions part of dataset.  Dataset A<jupyter_code>def check(sol):
    # Input type: a 81 length long string that represents the solved sukudo prolem.
    solution=np.reshape([int(c) for c in sol], (9,9)) # trun into 9 by 9 np.array matrix.
    for i in range(9): 
        # Check every row has exact one number i for i=1:9
        if [0,1,2,3,4,5,6,7,8]!=np.where(solution==(i+1))[0].tolist():
            return False
    for i in range(9): # This step make sure every column has exact 1 number for i in 1=1:9
        solution_T=solution.T # transpose the matrix 
        # Check every row has exact one number i for i=1:9
        if [0,1,2,3,4,5,6,7,8]!=np.where(solution_T==(i+1))[0].tolist():
            return False
        k=i%3
        h=i//3
        block=solution[h*3:h*3+3,k*3:k*3+3]
        for j in range(9):
            [a,b]=np.shape(np.where(block==(j+1)))
            if b!=1:
                return False
        return True
# For Dataset A

n1 = len(data_small1['quizzes'])
cnt = 0
for i in range(n1):
    s = solver(data_small1['quizzes'][i])
    if check(s) == 1:
        cnt += 1

n2 = len(data_small2['quizzes'])
for i in range(n2):
    s = solver(data_small2['quizzes'][i])
    if check(s) == 1:
        cnt += 1
print('success rate of Dataset A is {}' .format(100*cnt/(n1+n2)),'%')<jupyter_output>success rate of Dataset A is 33.71980676328502 %<jupyter_text>We can check small1 and small2 files seperately.<jupyter_code># For small1 file

data1=data_small1
n = len(data1['quizzes'])
k=0;
for i in range(n):
    s = solver(data1['quizzes'][i])
    if check(s):
        k+=1
    
print('success rate on small1 is', 100*k/n,'% ')
# For small2 file
data2=data_small2
n = len(data2['quizzes'])
k=0;
for i in range(n):
    s = solver(data2['quizzes'][i])
    if check(s):
        k+=1
    
print('success rate on small2 is', 100*k/n,'% ')<jupyter_output>success rate on small2 is 32.146389713155294 %<jupyter_text>Dataset B<jupyter_code># For Dataset B

random_seed = 42
np.random.seed(random_seed)
n1 = len(data_large1['quizzes'])
cnt = 0
sample1 = np.random.choice(n1, 1000)
for i in sample1:
    s = solver(data_large1['quizzes'][i])
    if check(s) == 1:
        cnt += 1

n2 = len(data_large2['quizzes'])
sample2 = np.random.choice(n2, 1000)
for i in sample2:
    s = solver(data_large2['quizzes'][i])
    if check(s) == 1:
        cnt += 1
print('success rate of Dataset B is {}'.format(100*cnt/2000),'%')<jupyter_output>success rate of Dataset B is 90.9 %<jupyter_text>We can check large1 and large2 files seperately.<jupyter_code># For large1 file

np.random.seed(random_seed)
random_seed = 42
n1 = len(data_large1['quizzes'])
k=0;
sample1 = np.random.choice(n1, 1000)
for i in sample1:
    s = solver(data_large1['quizzes'][i])
    if check(s) == 1:
        k+=1
    
print('success rate on large1 is', 100*k/1000,'% ')
# For large2 file

np.random.seed(random_seed)
random_seed = 42
n2 = len(data_large2['quizzes'])
k=0;
sample2 = np.random.choice(n2, 1000)
for i in sample2:
    s = solver(data_large2['quizzes'][i])
    if check(s) == 1:
        k+=1
    
print('success rate on large2 is', 100*k/1000,'% ')<jupyter_output>success rate on large2 is 100.0 %<jupyter_text>We find that the success rate on dataset A and dataset B using check function is same with the easy comparision method in the above part. Why?<jupyter_code># Use some simple codes to find out the explanation
# Take small2 as an example
n = len(data_small2['quizzes'])
for i in range(n):
    s = solver(data_small2['quizzes'][i])
    if s != data_small2['solutions'][i] and check(s) == 1:
        print('The', i,' th problem has at least two solutions' )
print('end')<jupyter_output>end<jupyter_text>Thus the result tell us that the False solution we calculated of small2 file is not due to the Diversity in Sudoku solutions.  Future Work We observe that the success rate of data_small2 is obviously smaller than other three datasets, so we want to solve this problem and optimize our function. Thus we write two new functions to do some pre-steps work and make the original sudoku easier to work. The main idea of this function is to fill in some box based on human logic firstly, and then it will switch to a easier sudoku problem to be solved in solver function.We met two problems in the coding. The first one is how can we switch output into an appropriate type and use it as the input of solver function. The second problem which we are confused is how to get the correct pre-steps result each time. We hope professor may help us!<jupyter_code>def preprocess(x):
    # Input: 9 by 9 matrx form x
    # output 9 by 9 matrix with filling the grid with determined value
    k=0
    for i in range(9):
        for j in range(9):
            if x[i][j]==0:
                b=set([1,2,3,4,5,6,7,8,9])
                row_set=set(x[i])
                col_set=set(x[j])
                idx=i*9+j
                r=idx//9//3
                c=idx%9//3
                box_set=set(x[r*3:r*3+3,c*3:c*3+3].reshape(1,9).tolist()[0])
                remaining_set=b-row_set-col_set-box_set-set([0])
                if len(remaining_set)==1:
                    x[i][j]=[int(c) for c in remaining_set][0]
                    k+=1
    if k==0:
        return x,False # means time to stop preprocess and use the x we get now
    else:
        return x,1 # means can continue process the matrix x
def do_easy_steps(x):
    x=np.reshape([int(c) for c in x], (9,9)) # turn into np.array matrix
    k=0
    result=preprocess(x) # a is the precessed matrix, b is boolean logic value
    while result[-1]==True:
        result=preprocess(result[0])
        k+=1
    result=result[0]
    
    return ''.join([str(i) for i in result.flatten()])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1283876266082672, 'fraction_numerical': 0.046947714207500685, 'mean_word_length': 3.3236686390532544, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '451603', 'license': 'MIT', 'n_tokens_mistral': 2760, 'n_tokens_neox': 2611, 'n_words': 829, 'path': 'sudoku_solver.ipynb', 'repo_name': 'junyus1/Math110B-project1', 'size': '7306'}