AI | 代写assignment | python – Mini-Sudoku

Mini-Sudoku

AI | 代写assignment | python – 这道题目是利用AI进行的编程代写任务, 涉及了AI等代写方面, 这是值得参考的assignment代写的题目

ass代做 assignment代写 代写assignment

Universit dOttawa
Facult de gnie
cole de science
dinformatique
et de gnie lectrique

(^) University of Ottawa Faculty of Engineering School of Electrical Engineering and Computer Science

assignment 2

CSI2120 Programming Paradigms

8%

Mini-Sudoku

Un mini-sudoku est un tableau de 4×4 dans lequel chaque lment est lun de quatre nombres possibles 1, 2, 3, 4. Pour tre Sudoku valide, chacune de ses ranges, de ses colonnes et de ses quadrants doivent contenir des nombres diffrents. Un Sudoku valide est illustr ci-dessus.

Pour cette question, vous devez crire un programme prenant en entre un Sudoku (une matrice 4×4) et qui vrifie si ce Sudoku est valide ou non (la fonction retourne donc un boolen). Notez bien que le Sudoku donn est dj rempli, vous ne faites que vrifier sa validit.

Le Sudoku doit tre reprsent laide dune liste de 4 listes, chacune des sous-listes reprsentant une range du Sudoku.

sudoku([[2,1,4,3],[4,3,2,1],[1,2,3,4],[3,4,1,2]]).
sudoku([[2,1,4,3],[4,3,2,1],[1,2,3,3],[3,4,1,2]]).

A mini-sudoku is an array of 4×4 in which each entry is one of the four numbers 1,2,3,4. To be a valid Sudoku, each row, each column, and each of the four quadrants must contain different numbers (as shown in the figure above). Note that this Sudoku is already complete, you only have to check its validity.

We ask you to write a program that will take as input a completed Sudoku (a 4×4 matrix) and will check if this one is a valid Sudoku solution (true or false).

CSI 2120 page 2


The Sudoku must be represented with a list of 4 lists, each list element representing one row of the matrix.

sudoku([[2,1,4,3],[4,3,2,1],[1,2,3,4],[3,4,1,2]]).
sudoku([[2,1,4,3],[4,3,2,1],[1,2,3,3],[3,4,1,2]]).

Question 1: [1 pt]

Dfinir le prdicat different/1 qui est vr AI lorsque tous les nombres dune liste sont diffrents.

Write the predicate different/1 that is true if all numbers in a list are different.

?- different([1,3,6,4,8,0]).
yes
?- different([1,3,6,4,1,8,0]).
no

Question 2: [1.5 pt]

Dfinir le prdicat extract4Columns/2 qui extrait les 4 colonnes dun mini-Sudoku.

Write the predicate extract4Columns/2 that extracts the 4 columns of the 4×4 mini-Sudoku.

?- sudoku(M), extract4Columns(M,L).
L=[[2,4,1,3],[1,3,2,4],[4,2,3,1],[3,1,4,2]])

Question 3: [1.5 pt]

Dfinir le prdicat extract4Quadrants/2 qui extrait les 4 quadrants dun mini-Sudoku.

Write the predicate extract4Quadrants/2 that extracts the 4 quadrants of the 4×4 Sudoku.

?- sudoku(M), extract4Quadrant(M,L).
L=[[2,1,4,3],[4,3,2,1],[1,2,3,4],[3,4,1,2]])

CSI 2120 page 3


Question 4: [2 pts]

Dfinir le prdicat allDifferents / 1 qui vrifie si chacune des sous-listes dune liste de listes contient des nombres diffrents. Utiliser le prdicat different / 1 de la question a) dans la dfinition de ce prdicat.

Write the prdicate allDifferents/1 that checks if each sublist of a list of list contains different numbers. Use predicate different/1 from question a) to define this predicate.

?- different([[1,3,6,4,8,0],[1,3,6,4,1,8,0]]).
no

Question 5: [2 pts]

Afin de vrifier la validit dun Sudoku, vous avez simplement vrifier si toutes les sous-listes de la reprsentation du Sudoku sont toutes diffrentes (alldifferents)et si toutes les sous-listes obtenues partir de extract4Columns et extract4Quadrants sont aussi toutes diffrentes (alldifferents). Dfinir le prdicat checkSudoku/1 en vous basant sur cette stratgie.

In order to verify the validity of a Sudoku, you just have to check if each of the lists in the sudoku representation are alldifferents and if the lists from extract4Columns and extract4Quadrants are also alldifferents. Write the predicate checkSudoku/1 that uses this strategy.

?- sudoku(M),checkSudoku(M).
yes;
no.