Skip to content

onokonem/silly-sudoku

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

silly-sudoku Build Status Coverage Status

How it works

  1. You are requesting the sudoku to solve, providing size and difficulty level.

    1. You are getting:

      1. The field with empty cells set to 0.

      2. The encrypted original field, the solution.

  2. As soon as you’ve solved the sudoku you are sending your solution and the original field you’ve got on the step 1 back to the server to check.

    1. Server will validate your solution and return your one of the answers:

      1. Solved

      2. Solved and matched to the original but solution is different from the original

      3. Solution is invalid

      4. Provided solution does not match to the original sudoku.

      5. Original field could not be decrypted (see Encryption)

Rules

As described in WiKi.

Note: the generated sudoku does not necessary meet the "single solution" requirement.

Encryption

The encryption key will be generated on each server restart.

As a result you will not be able to validate any solution were generated before the last server restart: the encryption key will not match.

Protocol

Described in the swagger.yml.

Generate code from spec

Install go-swagger and generate the code:

swagger generate server -f swagger.yml -t ./internal/oapi --main-package=../../../cmd/server --strict-responders

How to compile

go build ./cmd/server

How to play

Disclamer

I’m not a frontend nor fullstack guy, so I did not create a client, sorry.

So let’s do it in old school manner.

Compile and start the server

go build ./cmd/server
./server --scheme=http --host 0.0.0.0 --port 8080

Get the sudoku

curl -v -o sudoku.json http://127.0.0.1:8080/get

Your sudoku will be in the sudoku.json file. The file will be something like this:

{"field":[[9,0,0,0,4,0,0,0,5],[8,0,0,0,0,9,0,0,4],[0,4,0,0,0,0,9,0,3],[0,0,0,0,8,0,6,0,0],[0,0,0,0,0,0,0,0,0],[0,0,8,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,1,7,0,0,0,0],[0,0,0,0,0,0,0,0,0]],"original":"{\"Secure\":{\"IV\":\"UrHOfhoFSg/Z3v6pmYAt8A==\",\"Payload\":\"aXXA8ZXzQAVZ06Yk8miPGflv6dXI6suLjo5TL25BNw8oz6nER7NlbuJtj7yTexGp0jd8/Kar6UXfBBqSL+NtXmYl/aPZUmJ7ocd0JVnvtEMT/9Rfya12H4KAdwwI9LpNAz+juc5lgcDQWOKIDX6iHeIl9jy/JZmk5nughfFf6guXzNraMm7r8eOf/V58fiqpJh4YK0EehBSROgKcZsPt2HnMMeQD768z+F5YRRHCRfV9Ye8KqWmkSjFAfp8Ffx2Vlk8Y1R9gw6zDUPbCTCoMEF34pVLe+hYINfilWJ4F+9LRZE5WtIGBL7lvVb2iBmZkGfCu0r75QcTia+1fazUM0VyL2iFOb1y15IvdgofxyY724ZPRWH6A8uR+YbTpy+IkbtaJvW6B39uMsG4T30oV68OHRp5XwLNMkZGPIpkSeCYxBMEaS58qR/l/K66L4tPb7RHQnJq+KLLGZQnObSu++swb0q22469sCYtjBGzp/dO0hdTb2OINUR0afVWYplE0iObeTmfBs7BOwaNwM8rbWXt6dYvkpUEzFLf3LwpvYX3QqKlNWrtu+6lRkLKUljxiun3Osd9V5SiedPkFKE9vP258jXe0r7yWfZstxxrlm6Vcs35KuubPZCAIqdI0wXRrDUCxXWNAQrldGO6POu0nTQ==\"}}"}

Solve the sudoku

To make it easier we can reformat the file like this:

{"field":[
  [9,0,0,0,4,0,0,0,5],
  [8,0,0,0,0,9,0,0,4],
  [0,4,0,0,0,0,9,0,3],
  [0,0,0,0,8,0,6,0,0],
  [0,0,0,0,0,0,0,0,0],
  [0,0,8,0,0,0,0,0,0],
  [0,0,0,0,0,0,0,0,0],
  [0,0,0,1,7,0,0,0,0],
  [0,0,0,0,0,0,0,0,0]
],"original":"{\"Secure\":{\"IV\":\"UrHOfhoFSg/Z3v6pmYAt8A==\",\"Payload\":\"aXXA8ZXzQAVZ06Yk8miPGflv6dXI6suLjo5TL25BNw8oz6nER7NlbuJtj7yTexGp0jd8/Kar6UXfBBqSL+NtXmYl/aPZUmJ7ocd0JVnvtEMT/9Rfya12H4KAdwwI9LpNAz+juc5lgcDQWOKIDX6iHeIl9jy/JZmk5nughfFf6guXzNraMm7r8eOf/V58fiqpJh4YK0EehBSROgKcZsPt2HnMMeQD768z+F5YRRHCRfV9Ye8KqWmkSjFAfp8Ffx2Vlk8Y1R9gw6zDUPbCTCoMEF34pVLe+hYINfilWJ4F+9LRZE5WtIGBL7lvVb2iBmZkGfCu0r75QcTia+1fazUM0VyL2iFOb1y15IvdgofxyY724ZPRWH6A8uR+YbTpy+IkbtaJvW6B39uMsG4T30oV68OHRp5XwLNMkZGPIpkSeCYxBMEaS58qR/l/K66L4tPb7RHQnJq+KLLGZQnObSu++swb0q22469sCYtjBGzp/dO0hdTb2OINUR0afVWYplE0iObeTmfBs7BOwaNwM8rbWXt6dYvkpUEzFLf3LwpvYX3QqKlNWrtu+6lRkLKUljxiun3Osd9V5SiedPkFKE9vP258jXe0r7yWfZstxxrlm6Vcs35KuubPZCAIqdI0wXRrDUCxXWNAQrldGO6POu0nTQ==\"}}"}

Looks like a real sudoku field, huh? Keep the original part intact!

You have to replace all the 0 to the proper numbers.

Check the solution

Send the solution back to the server:

curl -v -H "Content-Type: application/json" -d @sudoku.json http://127.0.0.1:8080/check

and…​

I’ve got

> POST /check HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 954
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 422 Unprocessable Entity
< Content-Type: application/json
< Date: Thu, 07 Jul 2022 16:10:18 GMT
< Content-Length: 43
<
{"code":702,"message":"validation failed"}

Looks like I did not solve the sudoku properly, there is

HTTP/1.1 422 Unprocessable Entity

For the proper solution there will be 200 OK.

Good luck!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages