2020 PD2 Project 1

sudoku

If you don't know what is "sudoku"...

  • fill rows with 1-9
  • fill columns with 1-9
  • fill sub-grids with 1-9

Your mission

  • Write code to solve sudoku problem
  • Write code to generate sudoku problem
  • Learn to use Makefile && follow coding style

How to solve

I don't know ¯\_(ツ)_/¯

How to generate

  • fill number randomly
  • remove some number from solved problem
  • transform an existing problem

Transforming

Rotate the grid 90, 180, or 270 degrees.

• Flip the board horizontally or vertically

• Permute the rows 1-3, 4-6, or 7-9.

• Permute the columns 1-3, 4-6, or 7-9.

• Permute the 3x9 blocks of rows.

• Permute the 9x3 blocks of columns.

• Permute the digits.

Scoring

  • Build with Makefile (5%)
  • Generate problem (10%)
  • Can transform (10%)
  • Solve Correctness (40%)
  • Solve Speed (20%)
  • Finished normally (10%)
  • Coding style (5%)

Build with Makefile (5%)

  • Use Makefile to generate 3 executable files
    • solve / transform / generate
  • You may need to add some cpp files by yourself.
  • To prevent rewriting code, you can write your sudoku code in sudoku.h / sudoku.cpp
  • Each file has its own input/output rules

Sudoku board format

3 0 2 0 0 5 6 9 0
0 4 0 0 9 6 0 3 0
0 5 0 0 0 8 0 0 0
1 9 0 0 8 0 7 0 3
0 0 0 0 0 0 0 0 0
5 0 7 0 3 0 0 6 1
0 0 0 8 0 0 0 2 0
0 8 0 9 6 0 0 7 0
0 6 5 7 0 0 3 0 9
  • digit is split with single space (' ')
  • each line end with newline ('\n')
  • no trailing space !
  • read from stdin (cin/scanf/...)
  • print to stdout (cout/printf/...)

Generate problem (10%)

  • Generate a solvable sudoku problem and print it out
$ ./generate
3 0 2 0 0 5 6 9 0
0 4 0 0 9 6 0 3 0
0 5 0 0 0 8 0 0 0
1 9 0 0 8 0 7 0 3
0 0 0 0 0 0 0 0 0
5 0 7 0 3 0 0 6 1
0 0 0 8 0 0 0 2 0
0 8 0 9 6 0 0 7 0
0 6 5 7 0 0 3 0 9

Can transform (10%)

  • Read problem, transform by instruction, print it out
  • instruction format:
    • 0 (finish, print it out)
    • 1 x y (changeNum, {x,y = 1~9})
    • 2 x y (changeRow, {x,y = 0,1,2})
    • 3 x y (changeCol, {x,y = 0,1,2})
    • 4 x (clockwise rotate 90 degree x times)
    • 5 x (0 is up-down flip, 1 is left-right flip)

Transform example (1)

3 0 2 0 0 5 6 9 0
0 4 0 0 9 6 0 3 0
0 5 0 0 0 8 0 0 0
1 9 0 0 8 0 7 0 3
0 0 0 0 0 0 0 0 0
5 0 7 0 3 0 0 6 1
0 0 0 8 0 0 0 2 0
0 8 0 9 6 0 0 7 0
0 6 5 7 0 0 3 0 9
1 1 9
0
3 0 2 0 0 5 6 1 0
0 4 0 0 1 6 0 3 0
0 5 0 0 0 8 0 0 0
9 1 0 0 8 0 7 0 3
0 0 0 0 0 0 0 0 0
5 0 7 0 3 0 0 6 9
0 0 0 8 0 0 0 2 0
0 8 0 1 6 0 0 7 0
0 6 5 7 0 0 3 0 1

Input                                              Output

Transform example (2)

3 0 2 0 0 5 6 9 0
0 4 0 0 9 6 0 3 0
0 5 0 0 0 8 0 0 0
1 9 0 0 8 0 7 0 3
0 0 0 0 0 0 0 0 0
5 0 7 0 3 0 0 6 1
0 0 0 8 0 0 0 2 0
0 8 0 9 6 0 0 7 0
0 6 5 7 0 0 3 0 9
2 0 1
0
1 9 0 0 8 0 7 0 3
0 0 0 0 0 0 0 0 0
5 0 7 0 3 0 0 6 1
3 0 2 0 0 5 6 9 0
0 4 0 0 9 6 0 3 0
0 5 0 0 0 8 0 0 0
0 0 0 8 0 0 0 2 0
0 8 0 9 6 0 0 7 0
0 6 5 7 0 0 3 0 9

Input                                              Output

Transform example (3)

3 0 2 0 0 5 6 9 0
0 4 0 0 9 6 0 3 0
0 5 0 0 0 8 0 0 0
1 9 0 0 8 0 7 0 3
0 0 0 0 0 0 0 0 0
5 0 7 0 3 0 0 6 1
0 0 0 8 0 0 0 2 0
0 8 0 9 6 0 0 7 0
0 6 5 7 0 0 3 0 9
3 1 2
0
3 0 2 6 9 0 0 0 5
0 4 0 0 3 0 0 9 6
0 5 0 0 0 0 0 0 8
1 9 0 7 0 3 0 8 0
0 0 0 0 0 0 0 0 0
5 0 7 0 6 1 0 3 0
0 0 0 0 2 0 8 0 0
0 8 0 0 7 0 9 6 0
0 6 5 3 0 9 7 0 0

Input                                              Output

Transform example (4)

3 0 2 0 0 5 6 9 0
0 4 0 0 9 6 0 3 0
0 5 0 0 0 8 0 0 0
1 9 0 0 8 0 7 0 3
0 0 0 0 0 0 0 0 0
5 0 7 0 3 0 0 6 1
0 0 0 8 0 0 0 2 0
0 8 0 9 6 0 0 7 0
0 6 5 7 0 0 3 0 9
4 9
0
0 0 0 5 0 1 0 0 3
6 8 0 0 0 9 5 4 0
5 0 0 7 0 0 0 0 2
7 9 8 0 0 0 0 0 0
0 6 0 3 0 8 0 9 0
0 0 0 0 0 0 8 6 5
3 0 0 0 0 7 0 0 6
0 7 2 6 0 0 0 3 9
9 0 0 1 0 3 0 0 0

Input                                              Output

Transform example (5)

0 0 0 5 0 1 0 0 3
6 8 0 0 0 9 5 4 0
5 0 0 7 0 0 0 0 2
7 9 8 0 0 0 0 0 0
0 6 0 3 0 8 0 9 0
0 0 0 0 0 0 8 6 5
3 0 0 0 0 7 0 0 6
0 7 2 6 0 0 0 3 9
9 0 0 1 0 3 0 0 0
5 1
0
3 0 0 1 0 5 0 0 0
0 4 5 9 0 0 0 8 6
2 0 0 0 0 7 0 0 5
0 0 0 0 0 0 8 9 7
0 9 0 8 0 3 0 6 0
5 6 8 0 0 0 0 0 0
6 0 0 7 0 0 0 0 3
9 3 0 0 0 6 2 7 0
0 0 0 3 0 1 0 0 9

Input                                              Output

Transform example (6)

0 0 0 5 0 1 0 0 3
6 8 0 0 0 9 5 4 0
5 0 0 7 0 0 0 0 2
7 9 8 0 0 0 0 0 0
0 6 0 3 0 8 0 9 0
0 0 0 0 0 0 8 6 5
3 0 0 0 0 7 0 0 6
0 7 2 6 0 0 0 3 9
9 0 0 1 0 3 0 0 0
1 1 3
2 0 2
5 1
0
6 0 0 7 0 0 0 0 1
9 1 0 0 0 6 2 7 0
0 0 0 1 0 3 0 0 9
0 0 0 0 0 0 8 9 7
0 9 0 8 0 1 0 6 0
5 6 8 0 0 0 0 0 0
1 0 0 3 0 5 0 0 0
0 4 5 9 0 0 0 8 6
2 0 0 0 0 7 0 0 5

Input                                              Output

Solve (60%)

  • Input
    • A sudoku problem
  • Output
    • Problem status
      • 0 for no solution
      • 1 for unique solution
      • 2 for multiple solution
    • solution (if is unique)

Example output

// Has unique solution
1
3 7 2 1 4 5 6 9 8
8 4 1 2 9 6 5 3 7
9 5 6 3 7 8 2 1 4
1 9 4 6 8 2 7 5 3
6 3 8 5 1 7 9 4 2
5 2 7 4 3 9 8 6 1
7 1 9 8 5 3 4 2 6
2 8 3 9 6 4 1 7 5
4 6 5 7 2 1 3 8 9

// No solution
0

// Has multiple solution
2

Solve judge detail

  • Correctness
    • >25% correct (20%)
    • >50% correct (10%)
    • 100% correct (10%)
  • Speed
    • avg <10s (10%)
    • avg < 5s (5%)
    • avg < 1s (5%)

Finished normally (10%)

  • Your program should not crash during tests.

Coding style (5%)

  • Your code should follow Google's C++ Style
  • You can install astyle to format your code
    • sudo apt install -y astyle
  • astyle command:
  • astyle --style=google --indent=spaces=4 --suffix=none <file>

How to use judge platform

Before doing homework

  1. Please goto gitlab
  2. fork the project TA provide

About platform

website url

Announce part: TA will announce message about platform and project 1

1

2

3

  1. Menu
  2. Announce page (default page)
  3. Resource page

WARNING

DO NOT MODIFY THESE FILES

OR YOU WILL GET 0 POINTS

WARNING

DO NOT ATTACK SERVER

(SCRIPT, WEB, ...ETC)

DEMO

2020 PD2 project1 Tutorial

By Liang Yu-Cheng

2020 PD2 project1 Tutorial

2019 pd2 project 1 platform tutorial

  • 2,810