├── Lab2
├── data
│ ├── data.txt
│ ├── error.txt
│ ├── not_found.json
│ ├── error.json
│ └── data.json
├── static
│ ├── hello-world.txt
│ ├── styles.css
│ ├── data.json
│ ├── 502.html
│ ├── 403.html
│ ├── 404.html
│ ├── 501.html
│ ├── index.html
│ └── test
│ │ └── test.html
├── background.md
└── README.md
├── Lab1
├── src
│ ├── Sudoku
│ │ ├── test_group
│ │ ├── answer_group
│ │ ├── test1
│ │ ├── answer1
│ │ ├── README
│ │ ├── Makefile
│ │ ├── sudoku.h
│ │ ├── main.cc
│ │ ├── sudoku_min_arity.cc
│ │ ├── sudoku_basic.cc
│ │ ├── sudoku_min_arity_cache.cc
│ │ ├── neighbor.cc
│ │ ├── sudoku_dancing_links.cc
│ │ └── Lab1.sh
│ ├── 图2-1.png
│ ├── 图2-2.png
│ ├── 图2-3.png
│ ├── An_example.png
│ ├── Input_file.png
│ ├── test_group.png
│ ├── where_ext4.png
│ ├── ExampleInput.png
│ ├── Sudoku_answer.png
│ ├── Sudoku_puzzle.png
│ ├── Wrong_Example.png
│ └── answer_group.png
└── README.md
├── Lab4
├── assets
│ ├── basic.png
│ └── advanced.png
├── static
│ ├── img1.png
│ ├── img2.png
│ └── img3.png
├── README.md
└── data
│ ├── courses.txt
│ └── students.txt
├── Lab3
├── src
│ ├── KVStoreOverview.jpg
│ ├── KVStoreOverview.pptx
│ ├── two-phase-commit.png
│ ├── participant_sample.conf
│ └── coordinator_sample.conf
└── README.md
└── README.md
/Lab2/data/data.txt:
--------------------------------------------------------------------------------
1 | id=1&name=Foo
--------------------------------------------------------------------------------
/Lab2/static/hello-world.txt:
--------------------------------------------------------------------------------
1 | Hello world
--------------------------------------------------------------------------------
/Lab2/data/error.txt:
--------------------------------------------------------------------------------
1 | stauts: 403; message: Data format error;
--------------------------------------------------------------------------------
/Lab2/static/styles.css:
--------------------------------------------------------------------------------
1 | h1 {
2 | margin-left: 30px;
3 | }
--------------------------------------------------------------------------------
/Lab2/data/not_found.json:
--------------------------------------------------------------------------------
1 | {"status": "404","message": "Not found"}
2 |
--------------------------------------------------------------------------------
/Lab2/data/error.json:
--------------------------------------------------------------------------------
1 | {"status": "403","message": "Data format error."}
2 |
--------------------------------------------------------------------------------
/Lab1/src/Sudoku/test_group:
--------------------------------------------------------------------------------
1 | ./test1
2 | ./test1000
3 | ./test1000
4 | ./test10000
5 |
--------------------------------------------------------------------------------
/Lab1/src/Sudoku/answer_group:
--------------------------------------------------------------------------------
1 | ./answer1
2 | ./answer1000
3 | ./answer1000
4 | ./answer10000
5 |
--------------------------------------------------------------------------------
/Lab1/src/图2-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab1/src/图2-1.png
--------------------------------------------------------------------------------
/Lab1/src/图2-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab1/src/图2-2.png
--------------------------------------------------------------------------------
/Lab1/src/图2-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab1/src/图2-3.png
--------------------------------------------------------------------------------
/Lab1/src/Sudoku/test1:
--------------------------------------------------------------------------------
1 | 000000010400000000020000000000050407008000300001090000300400200050100000000806000
2 |
--------------------------------------------------------------------------------
/Lab2/data/data.json:
--------------------------------------------------------------------------------
1 | [{"id":1,"name":"Foo"},{"id":2,"name":"Bar"},{"id":3,"name":"Foo"},{"id":4,"name":"Bar"}]
--------------------------------------------------------------------------------
/Lab4/assets/basic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab4/assets/basic.png
--------------------------------------------------------------------------------
/Lab4/static/img1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab4/static/img1.png
--------------------------------------------------------------------------------
/Lab4/static/img2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab4/static/img2.png
--------------------------------------------------------------------------------
/Lab4/static/img3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab4/static/img3.png
--------------------------------------------------------------------------------
/Lab1/src/An_example.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab1/src/An_example.png
--------------------------------------------------------------------------------
/Lab1/src/Input_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab1/src/Input_file.png
--------------------------------------------------------------------------------
/Lab1/src/Sudoku/answer1:
--------------------------------------------------------------------------------
1 | 693784512487512936125963874932651487568247391741398625319475268856129743274836159
2 |
--------------------------------------------------------------------------------
/Lab1/src/test_group.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab1/src/test_group.png
--------------------------------------------------------------------------------
/Lab1/src/where_ext4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab1/src/where_ext4.png
--------------------------------------------------------------------------------
/Lab1/src/ExampleInput.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab1/src/ExampleInput.png
--------------------------------------------------------------------------------
/Lab1/src/Sudoku_answer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab1/src/Sudoku_answer.png
--------------------------------------------------------------------------------
/Lab1/src/Sudoku_puzzle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab1/src/Sudoku_puzzle.png
--------------------------------------------------------------------------------
/Lab1/src/Wrong_Example.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab1/src/Wrong_Example.png
--------------------------------------------------------------------------------
/Lab1/src/answer_group.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab1/src/answer_group.png
--------------------------------------------------------------------------------
/Lab4/assets/advanced.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab4/assets/advanced.png
--------------------------------------------------------------------------------
/Lab3/src/KVStoreOverview.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab3/src/KVStoreOverview.jpg
--------------------------------------------------------------------------------
/Lab3/src/KVStoreOverview.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab3/src/KVStoreOverview.pptx
--------------------------------------------------------------------------------
/Lab3/src/two-phase-commit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/1989chenguo/CloudComputingLabs/HEAD/Lab3/src/two-phase-commit.png
--------------------------------------------------------------------------------
/Lab2/static/data.json:
--------------------------------------------------------------------------------
1 | [{"id": "1","name": "Foo"},{"id": "2","name": "Bar"},{"id": "3","name": "Foo Bar"},{"id": "4","name": "Foo"}]
2 |
--------------------------------------------------------------------------------
/Lab1/src/Sudoku/README:
--------------------------------------------------------------------------------
1 | A backtracking sudoku solver, four algorithms are shown.
2 |
3 | test cases are from http://people.csse.uwa.edu.au/gordon/sudokumin.php
4 |
--------------------------------------------------------------------------------
/Lab1/src/Sudoku/Makefile:
--------------------------------------------------------------------------------
1 | CXXFLAGS+=-O2 -ggdb -DDEBUG
2 | CXXFLAGS+=-Wall -Wextra
3 |
4 | all: sudoku
5 |
6 | sudoku: main.cc neighbor.cc sudoku_basic.cc sudoku_min_arity.cc sudoku_min_arity_cache.cc sudoku_dancing_links.cc
7 | g++ -O2 -o $@ $^
8 |
--------------------------------------------------------------------------------
/Lab2/static/502.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Document
7 |
8 |
9 | 502 Bad Gateway
10 |
11 |
--------------------------------------------------------------------------------
/Lab2/static/403.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 403 Forbidden
7 |
8 |
9 | 403 Forbidden
10 |
11 |
--------------------------------------------------------------------------------
/Lab2/static/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 404 Not Found
7 |
8 |
9 |
10 | 404 Not Found
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Lab2/static/501.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 501 Not Implemented
7 |
8 |
9 |
10 | 501 Not Implemented
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Lab2/static/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Simple HTTP Server
7 |
8 |
9 |
10 | Simple HTTP Server
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Lab2/static/test/test.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Test File
7 |
8 |
9 |
10 | Test File should be in ./test/test.html
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Lab3/src/participant_sample.conf:
--------------------------------------------------------------------------------
1 | !
2 | ! Participant configuration
3 | ! 2020/05/07 11:25:33
4 | !
5 | ! The argument name and value are separated by whitespace in the configuration file.
6 | !
7 | ! Mode of process, coordinator OR participant
8 | mode participant
9 | !
10 | ! The address and port the participant process is listening on.
11 | participant_info 127.0.0.1:8002
12 | !
13 | ! The address and port the coordinator process is listening on.
14 | coordinator_info 127.0.0.1:8001
--------------------------------------------------------------------------------
/Lab3/src/coordinator_sample.conf:
--------------------------------------------------------------------------------
1 | !
2 | ! Coordinator configuration
3 | ! 2020/05/07 11:25:33
4 | !
5 | ! The argument name and value are separated by whitespace in the configuration file.
6 | !
7 | ! Mode of process, coordinator OR participant
8 | mode coordinator
9 | !
10 | ! The address and port the coordinator process is listening on.
11 | ! Note that the address and port are separated by character ':'.
12 | coordinator_info 127.0.0.1:8001
13 | !
14 | ! Address and port information of all participants.
15 | ! Three lines specifies three participants' addresses.
16 | participant_info 127.0.0.1:8002
17 | participant_info 127.0.0.1:8003
18 | participant_info 127.0.0.1:8004
--------------------------------------------------------------------------------
/Lab1/src/Sudoku/sudoku.h:
--------------------------------------------------------------------------------
1 | #ifndef SUDOKU_H
2 | #define SUDOKU_H
3 |
4 | const bool DEBUG_MODE = false;
5 | enum { ROW=9, COL=9, N = 81, NEIGHBOR = 20 };
6 | const int NUM = 9;
7 |
8 | extern int neighbors[N][NEIGHBOR];
9 | extern int board[N];
10 | extern int spaces[N];
11 | extern int nspaces;
12 | extern int (*chess)[COL];
13 |
14 | void init_neighbors();
15 | void input(const char in[N]);
16 | void init_cache();
17 |
18 | bool available(int guess, int cell);
19 |
20 | bool solve_sudoku_basic(int which_space);
21 | bool solve_sudoku_min_arity(int which_space);
22 | bool solve_sudoku_min_arity_cache(int which_space);
23 | bool solve_sudoku_dancing_links(int unused);
24 | bool solved();
25 | #endif
26 |
--------------------------------------------------------------------------------
/Lab1/src/Sudoku/main.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | #include "sudoku.h"
8 |
9 | int64_t now()
10 | {
11 | struct timeval tv;
12 | gettimeofday(&tv, NULL);
13 | return tv.tv_sec * 1000000 + tv.tv_usec;
14 | }
15 |
16 | int main(int argc, char* argv[])
17 | {
18 | init_neighbors();
19 |
20 | FILE* fp = fopen(argv[1], "r");
21 | char puzzle[128];
22 | int total_solved = 0;
23 | int total = 0;
24 | bool (*solve)(int) = solve_sudoku_basic;
25 | if (argv[2] != NULL)
26 | if (argv[2][0] == 'a')
27 | solve = solve_sudoku_min_arity;
28 | else if (argv[2][0] == 'c')
29 | solve = solve_sudoku_min_arity_cache;
30 | else if (argv[2][0] == 'd')
31 | solve = solve_sudoku_dancing_links;
32 | int64_t start = now();
33 | while (fgets(puzzle, sizeof puzzle, fp) != NULL) {
34 | if (strlen(puzzle) >= N) {
35 | ++total;
36 | input(puzzle);
37 | init_cache();
38 | //if (solve_sudoku_min_arity_cache(0)) {
39 | //if (solve_sudoku_min_arity(0))
40 | //if (solve_sudoku_basic(0)) {
41 | if (solve(0)) {
42 | ++total_solved;
43 | if (!solved())
44 | assert(0);
45 | }
46 | else {
47 | printf("No: %s", puzzle);
48 | }
49 | }
50 | }
51 | int64_t end = now();
52 | double sec = (end-start)/1000000.0;
53 | printf("%f sec %f ms each %d\n", sec, 1000*sec/total, total_solved);
54 |
55 | return 0;
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/Lab1/src/Sudoku/sudoku_min_arity.cc:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include
4 |
5 | #include "sudoku.h"
6 |
7 | static int arity(int cell)
8 | {
9 | bool occupied[10] = {false};
10 | for (int i = 0; i < NEIGHBOR; ++i) {
11 | int neighbor = neighbors[cell][i];
12 | occupied[board[neighbor]] = true;
13 | }
14 | return std::count(occupied+1, occupied+10, false);
15 | }
16 |
17 | static void find_min_arity(int space)
18 | {
19 | int cell = spaces[space];
20 | int min_space = space;
21 | int min_arity = arity(cell);
22 |
23 | for (int sp = space+1; sp < nspaces && min_arity > 1; ++sp) {
24 | int cur_arity = arity(spaces[sp]);
25 | if (cur_arity < min_arity) {
26 | min_arity = cur_arity;
27 | min_space = sp;
28 | }
29 | }
30 |
31 | if (space != min_space) {
32 | std::swap(spaces[min_space], spaces[space]);
33 | }
34 | }
35 |
36 | bool solve_sudoku_min_arity(int which_space)
37 | {
38 | if (which_space >= nspaces) {
39 | return true;
40 | }
41 |
42 | find_min_arity(which_space);
43 | int cell = spaces[which_space];
44 |
45 | for (int guess = 1; guess <= NUM; ++guess) {
46 | if (available(guess, cell)) {
47 | // hold
48 | assert(board[cell] == 0);
49 | board[cell] = guess;
50 |
51 | // try
52 | if (solve_sudoku_min_arity(which_space+1)) {
53 | return true;
54 | }
55 |
56 | // unhold
57 | assert(board[cell] == guess);
58 | board[cell] = 0;
59 | }
60 | }
61 | return false;
62 | }
63 |
--------------------------------------------------------------------------------
/Lab1/src/Sudoku/sudoku_basic.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include
5 |
6 | #include "sudoku.h"
7 |
8 | int board[N];
9 | int spaces[N];
10 | int nspaces;
11 | int (*chess)[COL] = (int (*)[COL])board;
12 |
13 | static void find_spaces()
14 | {
15 | nspaces = 0;
16 | for (int cell = 0; cell < N; ++cell) {
17 | if (board[cell] == 0)
18 | spaces[nspaces++] = cell;
19 | }
20 | }
21 |
22 | void input(const char in[N])
23 | {
24 | for (int cell = 0; cell < N; ++cell) {
25 | board[cell] = in[cell] - '0';
26 | assert(0 <= board[cell] && board[cell] <= NUM);
27 | }
28 | find_spaces();
29 | }
30 |
31 | bool available(int guess, int cell)
32 | {
33 | for (int i = 0; i < NEIGHBOR; ++i) {
34 | int neighbor = neighbors[cell][i];
35 | if (board[neighbor] == guess) {
36 | return false;
37 | }
38 | }
39 | return true;
40 | }
41 |
42 | bool solve_sudoku_basic(int which_space)
43 | {
44 | if (which_space >= nspaces) {
45 | return true;
46 | }
47 |
48 | // find_min_arity(which_space);
49 | int cell = spaces[which_space];
50 |
51 | for (int guess = 1; guess <= NUM; ++guess) {
52 | if (available(guess, cell)) {
53 | // hold
54 | assert(board[cell] == 0);
55 | board[cell] = guess;
56 |
57 | // try
58 | if (solve_sudoku_basic(which_space+1)) {
59 | return true;
60 | }
61 |
62 | // unhold
63 | assert(board[cell] == guess);
64 | board[cell] = 0;
65 | }
66 | }
67 | return false;
68 | }
69 |
--------------------------------------------------------------------------------
/Lab1/src/Sudoku/sudoku_min_arity_cache.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include
5 |
6 | #include "sudoku.h"
7 |
8 | static bool occupied[N][NUM+1];
9 | static int arity[N];
10 |
11 | static void find_min_arity(int space)
12 | {
13 | int cell = spaces[space];
14 | int min_space = space;
15 | int min_arity = arity[cell];
16 |
17 | for (int sp = space+1; sp < nspaces && min_arity > 1; ++sp) {
18 | int cur_arity = arity[spaces[sp]];
19 | if (cur_arity < min_arity) {
20 | min_arity = cur_arity;
21 | min_space = sp;
22 | }
23 | }
24 |
25 | if (space != min_space) {
26 | std::swap(spaces[min_space], spaces[space]);
27 | }
28 | }
29 |
30 | void init_cache()
31 | {
32 | bzero(occupied, sizeof(occupied));
33 | std::fill(arity, arity + N, NUM);
34 | for (int cell = 0; cell < N; ++cell) {
35 | occupied[cell][0] = true;
36 | int val = board[cell];
37 | if (val > 0) {
38 | occupied[cell][val] = true;
39 | for (int n = 0; n < NEIGHBOR; ++n) {
40 | int neighbor = neighbors[cell][n];
41 | if (!occupied[neighbor][val]) {
42 | occupied[neighbor][val] = true;
43 | --arity[neighbor];
44 | }
45 | }
46 | }
47 | }
48 | }
49 |
50 | bool solve_sudoku_min_arity_cache(int which_space)
51 | {
52 | if (which_space >= nspaces) {
53 | return true;
54 | }
55 |
56 | find_min_arity(which_space);
57 | int cell = spaces[which_space];
58 |
59 | for (int guess = 1; guess <= NUM; ++guess) {
60 | if (!occupied[cell][guess]) {
61 | // hold
62 | assert(board[cell] == 0);
63 | board[cell] = guess;
64 | occupied[cell][guess] = true;
65 |
66 | // remember changes
67 | int modified[NEIGHBOR];
68 | int nmodified = 0;
69 | for (int n = 0; n < NEIGHBOR; ++n) {
70 | int neighbor = neighbors[cell][n];
71 | if (!occupied[neighbor][guess]) {
72 | occupied[neighbor][guess] = true;
73 | --arity[neighbor];
74 | modified[nmodified++] = neighbor;
75 | }
76 | }
77 |
78 | // try
79 | if (solve_sudoku_min_arity_cache(which_space+1)) {
80 | return true;
81 | }
82 |
83 | // unhold
84 | occupied[cell][guess] = false;
85 | assert(board[cell] == guess);
86 | board[cell] = 0;
87 |
88 | // undo changes
89 | for (int i = 0; i < nmodified; ++i) {
90 | int neighbor = modified[i];
91 | assert(occupied[neighbor][guess]);
92 | occupied[neighbor][guess] = false;
93 | ++arity[neighbor];
94 | }
95 | }
96 | }
97 | return false;
98 | }
99 |
--------------------------------------------------------------------------------
/Lab1/src/Sudoku/neighbor.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "sudoku.h"
6 |
7 | #include
8 |
9 | int neighbors[N][NEIGHBOR];
10 |
11 | static void mark_adjacent(bool adjacent[ROW][COL], int row, int col)
12 | {
13 | for (int i = 0; i < NUM; ++i) {
14 | adjacent[row][i] = true;
15 | adjacent[i][col] = true;
16 | }
17 | int top = (row/3)*3;
18 | int left = (col/3)*3;
19 | adjacent[top][left] = true;
20 | adjacent[top][left+1] = true;
21 | adjacent[top][left+2] = true;
22 | adjacent[top+1][left] = true;
23 | adjacent[top+1][left+1] = true;
24 | adjacent[top+1][left+2] = true;
25 | adjacent[top+2][left] = true;
26 | adjacent[top+2][left+1] = true;
27 | adjacent[top+2][left+2] = true;
28 | }
29 |
30 | static void collect_neighbors(const bool adjacent[ROW][COL], int row, int col, int myneighbors[NEIGHBOR])
31 | {
32 | int n = 0;
33 | for (int y = 0; y < ROW; ++y) {
34 | for (int x = 0; x < COL; ++x) {
35 | if (adjacent[y][x] && !(y == row && x == col)) {
36 | assert(n < NEIGHBOR);
37 | myneighbors[n++] = y*COL + x;
38 | }
39 | }
40 | }
41 | assert(n == NEIGHBOR);
42 | }
43 |
44 | static void print_neighbors(const bool adjacent[ROW][COL], int row, int col, int myneighbors[NEIGHBOR])
45 | {
46 | for (int y = 0; y < ROW; ++y) {
47 | for (int x = 0; x < COL; ++x) {
48 | if (y == row && x == col)
49 | putchar('X');
50 | else
51 | putchar(adjacent[y][x] ? 'o' : '.');
52 | }
53 | printf("\n");
54 | }
55 | for (int i = 0; i < NEIGHBOR; ++i) {
56 | printf("%2d, ", myneighbors[i]);
57 | }
58 | puts("\n");
59 | }
60 |
61 | /*public*/ void init_neighbors()
62 | {
63 | for (int row = 0; row < ROW; ++row) {
64 | for (int col = 0; col < COL; ++col) {
65 | bool adjacent[ROW][COL];
66 | bzero(adjacent, sizeof adjacent);
67 | mark_adjacent(adjacent, row, col);
68 |
69 | int me = row*COL + col;
70 | collect_neighbors(adjacent, row, col, neighbors[me]);
71 |
72 | if (DEBUG_MODE)
73 | print_neighbors(adjacent, row, col, neighbors[me]);
74 | }
75 | }
76 | }
77 |
78 | bool solved()
79 | {
80 | for (int row = 0; row < ROW; ++row) {
81 | // check row
82 | int occurs[10] = { 0 };
83 | for (int col = 0; col < COL; ++col) {
84 | int val = chess[row][col];
85 | assert(1 <= val && val <= NUM);
86 | ++occurs[val];
87 | }
88 |
89 | if (std::count(occurs, occurs+10, 1) != NUM)
90 | return false;
91 | }
92 |
93 | for (int col = 0; col < COL; ++col) {
94 | int occurs[10] = { 0 };
95 | for (int row = 0; row < ROW; ++row) {
96 | int val = chess[row][col];
97 | // assert(1 <= val && val <= NUM);
98 | ++occurs[val];
99 | }
100 |
101 | if (std::count(occurs, occurs+10, 1) != NUM)
102 | return false;
103 | }
104 |
105 | for (int row = 0; row < ROW; row += 3) {
106 | for (int col = 0; col < COL; col += 3) {
107 | int occurs[10] = { 0 };
108 | ++occurs[chess[row ][col]];
109 | ++occurs[chess[row ][col+1]];
110 | ++occurs[chess[row ][col+2]];
111 | ++occurs[chess[row+1][col]];
112 | ++occurs[chess[row+1][col+1]];
113 | ++occurs[chess[row+1][col+2]];
114 | ++occurs[chess[row+2][col]];
115 | ++occurs[chess[row+2][col+1]];
116 | ++occurs[chess[row+2][col+2]];
117 |
118 | if (std::count(occurs, occurs+10, 1) != NUM)
119 | return false;
120 | }
121 | }
122 | return true;
123 | }
124 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Cloud Computing: Overall Lab Instruction
2 |
3 |
4 |
5 | ## 1. Overview
6 |
7 | There are **4 labs in total** in this course. All the materials of each lab are under folders Lab1-4 in this repo. Please clone the lab git repo onto your local computer,
8 |
9 | `git clone https://github.com/1989chenguo/CloudComputingLabs.git`
10 |
11 | and always track our latest lab materials using the following commands (should first enter the folder you have cloned from our lab repo)
12 |
13 | `git pull`
14 |
15 | You can find this overall lab instruction in `README.md` in the root folder.
16 |
17 | Please **carefully read the overall lab instruction before you do anything**.
18 |
19 | Also, please **carefully read each lab's instruction** ([Lab1](Lab1/README.md), [Lab2](Lab2/README.md), [Lab3](Lab3/README.md), [Lab4](Lab4/README.md)) to get each lab's task, background, requirements, etc.
20 |
21 | ## 2. Group collaboration
22 |
23 | Each student should register your own github account. Group members should use **git and github** to collaborate.
24 |
25 | All the labs are done in the unit of group, i.e., a group only needs to submit one piece of code for each lab. However, each group member should make enough contribution to the lab. Teaching assistants will check the **git commit history** to evaluate each one’s contribution.
26 |
27 | ## 3. Code submission
28 |
29 | Each group should create a code repo for our course (create your own group's repo, do not push onto my course lab repo!). The group leader should send an email to TA telling us your group's lab git repo address. For example, https://github.com/group1/CloudComputingLabs.git`
30 |
31 | **All the lab code should be submitted through pushing to your group's github code repo.** Teaching assistants will checkout your commit, and read and test your codes from the above repo address you provided us. The code of different lab should be in different folders, named Lab1/Lab2/Lab3/Lab4, respectively (following the same structure of this repo). Please note that your lab folder name should be exactly same as above (be careful about the first capital letter and no space before the number), otherwise your code may fail in our TAs' automatic testing scripts. All lab codes should be in the same course git repo of your group.
32 |
33 | Please write a README.md to each lab code folder, briefly introducing how to run your lab code (including how to set the environment, provide the input, and explain the output, etc.). Keep the README short and clear! Also, your code should be well commented so that other people can understand without asking you.
34 |
35 | ## 4. Environment requirement
36 |
37 | ### 4.1 OS requirement
38 |
39 | All the labs should be tested and runnable on UNIX-like operating systems, such as Linux distributions (e.g., Ubuntu, CentOS) and MacOS. We highly recommend you to use Linux distributions such as Ubuntu.
40 | If you only have windows PC or laptops, install a UNIX VM and do experiments on the VM.
41 |
42 | ### 4.2 Programming language
43 |
44 | Any programming languages are permitted in all labs, such as C/C++, Java, Go, Python, Perl. But for performance consideration, we highly recommend you to use C/C++ or Go !!!
45 |
46 | ### 4.3 Try to only use standard API
47 |
48 | To make your program portable, try your best to only use standard & widely available functions and normal libraries (such as `glibc`, `C++ STLs` and some typical math libraries). All the labs should only use standard system API defined by POSIX specification or Linux man page specification. We prefer to use standard POSIX API, so your code can be easily runnable on various kind of UNIX-like systems (instead of only on Linux).
49 |
50 | ## 5. Grading
51 |
52 | Grading details are specified in each lab's instruction document, please carefully read them [Lab1](Lab1/README.md), [Lab2](Lab2/README.md), [Lab3](Lab3/README.md), [Lab4](Lab4/README.md).
53 |
54 | Besides, we have the following 3 overall grading requirements applicable to all the 4 labs:
55 |
56 | 1. **DO NOT copy** others' code (either from the Internet or from your classmates), otherwise your group (every member and the leader) will got **zero point** in the lab. However, we encourage to communicate with other group and learn from each other. But do remember to write the code yourself and not copy.
57 | 2. **DO NOT miss the deadline**, otherwise your group (every member and the leader) points will be reduced accordingly.
58 | 3. Typically, your group (every member and the leader) will get same points in each lab, unless we find severely **unfair contribution** in the git commit history. In the overall grading, the leader will get some more points as bonus.
59 |
--------------------------------------------------------------------------------
/Lab1/src/Sudoku/sudoku_dancing_links.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include