-
You are requesting the sudoku to solve, providing size and difficulty level.
-
You are getting:
-
The field with empty cells set to 0.
-
The encrypted original field, the solution.
-
-
-
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.
-
Server will validate your solution and return your one of the answers:
-
Solved
-
Solved and matched to the original but solution is different from the original
-
Solution is invalid
-
Provided solution does not match to the original sudoku.
-
Original field could not be decrypted (see Encryption)
-
-
As described in WiKi.
Note: the generated sudoku does not necessary meet the "single solution" requirement.
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.
Described in the swagger.yml.
Install go-swagger and generate the code:
swagger generate server -f swagger.yml -t ./internal/oapi --main-package=../../../cmd/server --strict-responders
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.
go build ./cmd/server
./server --scheme=http --host 0.0.0.0 --port 8080
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==\"}}"}
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.
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!