<jupyter_start><jupyter_text>Board coding First, w start with coding a Sudoku board. Then, we'll code the necessary functions to solve the Sudoku. We'll record the puzzles in two ways — as a `string` and as a `dictionary`. 1. `string` will comprise all the rows from top top to bottom. Each digit is a box. If puzzle is not solve, we can use dot `.` as a placeholder for an empty box.An example of unsolved puzzle can look like:`..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82....26.95..8..2.3..9..5.1.3..`**All rows** of sudoku board will are concatenated into a long one (like above).And the solved puzzle at the above right, will be recorded as: `483921657967345821251876493548132976729564138136798245372689514814253769695417382`2. `dictionary` will be a pair of key-value, where the key is row-column entry intersection (A1, A2,..) and value is a digit (or `.` if puzze is not solved).<jupyter_code># start with recording rows and columns as string
rows = 'ABCDEFGHI'
cols = '123456789'<jupyter_output><empty_output><jupyter_text>We'll start by writing a helper function, `cross(a, b)`, which, given two strings — `a` and `b` — will return the list formed by all the possible concatenations of a letter `s` in string `a` with a letter `t` in string `b`.<jupyter_code>def cross(a,b):
    """Function returns all possible combinations of characters in strings"""
    return [s+t for s in a for t in b]
boxes = cross(rows, cols)
print('Example of boxes:',boxes[:10])<jupyter_output>Example of boxes: ['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'B1']<jupyter_text>Next we create `row`, `column` and `square` units.Recall, `units` are just rows, columns and squares.Since there are 9 rows, 9 columns and 9 boxes there are 27 units in total.<jupyter_code>row_units = [cross(r, cols) for r in rows]
row_units
column_units  = [cross(rows, c) for c in cols]
column_units
square_units = [cross(rs, cs) for rs in ('ABC','DEF','GHI') for cs in ('123','456','789')]
print('Top row is:', row_units[0])
print('Leftmost column is:', column_units[0])
print('Top left box is:', square_units[0])
unitlist = row_units + column_units + square_units
print('Number of units:', len(unitlist))<jupyter_output>Number of units: 27
{'fraction_non_alphanumeric': 0.13630229419703105, 'fraction_numerical': 0.07062528115159694, 'mean_word_length': 4.761658031088083, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '202119', 'license': 'MIT', 'n_tokens_mistral': 835, 'n_tokens_neox': 746, 'n_words': 297, 'path': 'sudoku-solver/solver.ipynb', 'repo_name': 'MakarovArtyom/AI-nanodegree', 'size': '2223'}