Doing the same for every row, column, and box, gets all of the constraints for the Sudoku Puzzle. There are more clauses, but each one is just a conjunct of ors, so the formula is in CNF, which means it is Clean Code, which means it is SOLID. With this, the requirements in CNF are every pair of disjunctions, which is Clean Code. If the second column is a 3, then !311 and the clause is true. If the first element is a 3, then !312 and the clause is true. This is equivalent to saying “of any two elements of the top row, at least one is not a 3.” As an example, take (!311 | !312). The second clause is equivalent to “there is at most one three in the top row”. SEE ALSO: Top 22 Languages to learn in 2022 To make Clean Code, put the requirements in conjunctive normal form (CNF), with all the clauses written as ANDS of ORs. The very last clause is an AND inside of an OR inside of another AND. SOLID says that programmers should write Clean Code, and nested boolean expressions are not Clean Code. This is good, but it’s wrong: it’s not SOLID. Each number appears exactly once in every column.Īs programmer’s start with a simpler problem (rule 1): the requirement that there’s exactly one 3 in the top row of a Sudoku Puzzle.Each number appears exactly once in every row, column, and 3x3 box.Each number cell has exactly one number.The requirements of a Japanese Sudoku Puzzle are: Write the requirementsĪ program is data structure + requirements + algorithm. SEE ALSO: How to decide between Ruby vs Python for senior engineers 3. ![]() We will use this data structure with an algorithm to solve the Sudoku Puzzle. Senior engineers who use Ruby or Python, which have 3D arrays, will use arrays of arrays, for a 9x9x9 array of booleans. So the right data structure is one 9x9 array of booleans per number.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |