lunduniversity.lu.se

Computer Science

Faculty of Engineering, LTH

Denna sida på svenska This page in English

Assignment F2: Solve Sudoku

2024 version.

Summary

This assignment is your second task asking you to write a Haskell program which is somewhat larger than just toy examples. You will extend your solution to Assignment 1 with new functionalities, in the same time learning some new aspects of Haskell programming.

The purpose of this assignment is to let you write fully functioning code from scratch: you won't get any deeper comments about your solution regarding the programming style before it fullfills the functional requirements (i.e., it works). Use tests for that purpose. Build your own tests in case you need some: you do know now how Sudoku works.

Use Hlint if you can.

The assignment should be completed in pairs.

Introduction

This assignment will only deal with standard Sudoku, i.e., 9x9. You will be given a set of Sudoku to solve (that you need to read from a file), partially filled (as in assignment 1), and your code is expected to provide the user with several possibilities:

  • solving the Sudoku automatically, showing the final solution;
  • assisting the user in solving the Sudoku by herself/himself, just verifying each step taken towards the solution.

The second problem may be split into two, somewhat independent subtasks:

  1. interact with the user, maintaining and updating the state of currently solved Sudoku,
  2. verify the correctness of current partial solution.

In order to solve a Sudoku you may use the standard technique of constraint propagation (which will be introduced in Lab4).

Your Task

Write a Haskell program that reads a Sudoku from a file (possibly asking for the name of this file), presents it to the user and gives her/him the following choice:

  1. solve this Sudoku, show the result, and ask for next operation;
  2. solve all Sudokus from the file beginning with the current one;
  3. let the user assign a value to a square and ask for next operation; (intended for interactively supporting the user with solving a particular Sudoku).

As test cases use Sudokus from easy50.txt file (see previous assignment, extract some of them one by one to separate files for testing interactively), or create some of your own.

In order to create the read-eval-print loop you may use (and modify) your main function from lab 3.

Clarification

As it is demanded in Lab 4, the bind function (maybeBind, (=<<) or (>>=)) should be used in your solution for the recursive helper functions that assign and solve Soduku (possibly called assign', assignHelper or similarly). The motivation for this request is to let you show your understanding of the important monadic type class and improve the code quality of your Sudoku solver. I expected this to be apparent from lab 4 description, but apparently I failed to be sufficiently clear. (JM)

Submission

You are expected to file in one single file with the solver module. The file should contain in the very beginning instructions describing how to run the tests of your code. The submission should be done using the course canvas.

The deadline is 20th May 2024, 23:59 CET. You should receive a response within two weeks from the deadline, possibly faster.

Page Manager: Jacek Malec