/*** Sudoku Given a partially filled 9×9 2D array ‘grid[9][9]‘, the goal is to assign digits (from 1 to 9) to the empty cells so that every row, column, and subgrid of size 3×3 contains exactly one instance of the digits from 1 to 9. Backtracking Algorithm Like all other Backtracking problems, we can solve Sudoku by one by one assigning numbers to empty cells. Before assigning a number, we check whether it is safe to assign. We basically check that the same number is not present in current row, current column and current 3X3 subgrid. After checking for safety, we assign the number, and recursively check whether this assignment leads to a solution or not. If the assignment doesn’t lead to a solution, then we try next number for current empty cell. And if none of number (1 to 9) lead to solution, we return false. ***/ #include <iostream> using namespace std; class Sudoku { public : ...
declare a list
ReplyDeletelist = []
declare a dictionary
dic = {}
Regular Expressions in Python
ReplyDeleteAn example regex is r"^(From|To|Cc).*?python-list@python.org"
- the caret ^ matches text at the beginning of a line.
- the part with (From|To|Cc) means that the line has to start with one of the words that are separated by the pipe |
- The .*? means to un-greedily match any number of characters, except the newline \n character. The un-greedy part means to match as few repetitions as possible. The . character means any non-newline character, the * means to repeat 0 or more times, and the ? character makes it un-greedy.