-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 68dda73
Showing
95 changed files
with
5,109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"files.associations": { | ||
"array": "cpp", | ||
"atomic": "cpp", | ||
"*.tcc": "cpp", | ||
"bitset": "cpp", | ||
"cctype": "cpp", | ||
"cfenv": "cpp", | ||
"chrono": "cpp", | ||
"cinttypes": "cpp", | ||
"clocale": "cpp", | ||
"cmath": "cpp", | ||
"codecvt": "cpp", | ||
"complex": "cpp", | ||
"condition_variable": "cpp", | ||
"csetjmp": "cpp", | ||
"csignal": "cpp", | ||
"cstdarg": "cpp", | ||
"cstddef": "cpp", | ||
"cstdint": "cpp", | ||
"cstdio": "cpp", | ||
"cstdlib": "cpp", | ||
"cstring": "cpp", | ||
"ctime": "cpp", | ||
"cuchar": "cpp", | ||
"cwchar": "cpp", | ||
"cwctype": "cpp", | ||
"deque": "cpp", | ||
"forward_list": "cpp", | ||
"list": "cpp", | ||
"unordered_map": "cpp", | ||
"unordered_set": "cpp", | ||
"vector": "cpp", | ||
"exception": "cpp", | ||
"algorithm": "cpp", | ||
"functional": "cpp", | ||
"iterator": "cpp", | ||
"map": "cpp", | ||
"memory": "cpp", | ||
"memory_resource": "cpp", | ||
"numeric": "cpp", | ||
"optional": "cpp", | ||
"random": "cpp", | ||
"ratio": "cpp", | ||
"regex": "cpp", | ||
"set": "cpp", | ||
"string": "cpp", | ||
"string_view": "cpp", | ||
"system_error": "cpp", | ||
"tuple": "cpp", | ||
"type_traits": "cpp", | ||
"utility": "cpp", | ||
"fstream": "cpp", | ||
"future": "cpp", | ||
"initializer_list": "cpp", | ||
"iomanip": "cpp", | ||
"iosfwd": "cpp", | ||
"iostream": "cpp", | ||
"istream": "cpp", | ||
"limits": "cpp", | ||
"mutex": "cpp", | ||
"new": "cpp", | ||
"ostream": "cpp", | ||
"scoped_allocator": "cpp", | ||
"shared_mutex": "cpp", | ||
"sstream": "cpp", | ||
"stdexcept": "cpp", | ||
"streambuf": "cpp", | ||
"thread": "cpp", | ||
"typeindex": "cpp", | ||
"typeinfo": "cpp", | ||
"valarray": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"type": "shell", | ||
"label": "C/C++: g++ build active file", | ||
"command": "/usr/bin/g++", | ||
"args": [ | ||
"-g", | ||
"${file}", | ||
"-o", | ||
"${fileDirname}/${fileBasenameNoExtension}" | ||
], | ||
"options": { | ||
"cwd": "${workspaceFolder}" | ||
}, | ||
"problemMatcher": [ | ||
"$gcc" | ||
], | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
} | ||
} | ||
] | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
#include <bits/stdc++.h> | ||
|
||
|
||
std::vector<std::vector<int>> map; | ||
std::array<std::array<std::set<int>, 6>, 6> possibles; | ||
std::map<std::pair<int, int>, std::vector<std::set<int>>> impTable({ | ||
{{1, 1}, {{ 1, 2, 3, 4, 5, 6, }, { 1, 2, 3, 4, 5, 6, }, { 1, 2, 3, 4, 5, 6, }, { 1, 2, 3, 4, 5, 6, }, { 1, 2, 3, 4, 5, 6, }, { 1, 2, 3, 4, 5, 6, }, }}, | ||
{{1, 2}, {{ 1, 2, 3, 4, 5, }, { 5, 6, }, { 5, 6, }, { 5, 6, }, { 5, 6, }, { 1, 2, 3, 4, 6, }, }}, | ||
{{1, 3}, {{ 1, 2, 3, 4, 5, }, { 6, }, { 6, }, { 6, }, { 4, 6, }, { 5, 6, }, }}, | ||
{{1, 4}, {{ 1, 2, 3, 4, 5, }, { 6, }, { 6, }, { 6, }, { 5, 6, }, { 4, 5, 6, }, }}, | ||
{{1, 5}, {{ 1, 2, 3, 4, 5, }, { 6, }, { 6, }, { 5, 6, }, { 4, 5, 6, }, { 3, 4, 5, 6, }, }}, | ||
{{1, 6}, {{ 1, 2, 3, 4, 5, }, { 1, 2, 3, 4, 6, }, { 1, 2, 3, 5, 6, }, { 1, 2, 4, 5, 6, }, { 1, 3, 4, 5, 6, }, { 2, 3, 4, 5, 6, }, }}, | ||
{{2, 1}, {{ 1, 2, 3, 4, 6, }, { 5, 6, }, { 5, 6, }, { 5, 6, }, { 5, 6, }, { 1, 2, 3, 4, 5, }, }}, | ||
{{2, 2}, {{ 6, }, { 5, }, { 5, }, { 5, }, { 5, }, { 6, }, }}, | ||
{{2, 3}, {{ 6, }, { 5, }, { }, { }, { 6, }, { 5, 6, }, }}, | ||
{{2, 4}, {{ 6, }, { 5, }, { }, { 6, }, { 5, 6, }, { 4, 5, 6, }, }}, | ||
{{2, 5}, {{ 6, }, { 1, 2, 3, 4, 5, }, { 1, 2, 3, 6, }, { 1, 2, 5, 6, }, { 1, 4, 5, 6, }, { 3, 4, 5, 6, }, }}, | ||
{{3, 1}, {{ 5, 6, }, { 4, 6, }, { 6, }, { 6, }, { 6, }, { 1, 2, 3, 4, 5, }, }}, | ||
{{3, 2}, {{ 5, 6, }, { 6, }, { }, { }, { 5, }, { 6, }, }}, | ||
{{3, 3}, {{ 5, 6, }, { 6, }, { }, { }, { 6, }, { 5, 6, }, }}, | ||
{{3, 4}, {{ 5, 6, }, { 1, 6, }, { 1, 2, 3, 4, 5, }, { 1, 2, 6, }, { 1, 5, 6, }, { 4, 5, 6, }, }}, | ||
{{4, 1}, {{ 4, 5, 6, }, { 5, 6, }, { 6, }, { 6, }, { 6, }, { 1, 2, 3, 4, 5, }, }}, | ||
{{4, 2}, {{ 4, 5, 6, }, { 5, 6, }, { 6, }, { }, { 5, }, { 6, }, }}, | ||
{{4, 3}, {{ 4, 5, 6, }, { 1, 5, 6, }, { 1, 2, 6, }, { 1, 2, 3, 4, 5, }, { 1, 6, }, { 5, 6, }, }}, | ||
{{5, 1}, {{ 3, 4, 5, 6, }, { 4, 5, 6, }, { 5, 6, }, { 6, }, { 6, }, { 1, 2, 3, 4, 5, }, }}, | ||
{{5, 2}, {{ 3, 4, 5, 6, }, { 1, 4, 5, 6, }, { 1, 2, 5, 6, }, { 1, 2, 3, 6, }, { 1, 2, 3, 4, 5, }, { 6, }, }}, | ||
{{6, 1}, {{ 2, 3, 4, 5, 6, }, { 1, 3, 4, 5, 6, }, { 1, 2, 4, 5, 6, }, { 1, 2, 3, 5, 6, }, { 1, 2, 3, 4, 6, }, { 1, 2, 3, 4, 5, }, }}, | ||
}); | ||
std::vector<int> clues; | ||
std::queue<std::pair<int, int>> checkQueue; | ||
|
||
void reset(){ | ||
std::vector<int> r(6); | ||
map = std::vector<std::vector<int>>(6, r); | ||
std::array<std::set<int>, 6> row; | ||
row.fill({1, 2, 3, 4, 5, 6}); | ||
possibles.fill(row); | ||
} | ||
|
||
void removePossible(int i, int j, int value){ | ||
if (possibles[i][j].count(value)){ | ||
possibles[i][j].erase(value); | ||
if (possibles[i][j].size() == 1){ | ||
checkQueue.push(std::make_pair(i, j)); | ||
} | ||
} | ||
} | ||
|
||
void fillMapValue(int i, int j, int value){ | ||
map[i][j] = value; | ||
for (int k = 0; k < 6; k++){ | ||
removePossible(k, j, value); | ||
removePossible(i, k, value); | ||
} | ||
} | ||
|
||
void impossiblesPass1(){ | ||
// for each row | ||
for (int i = 0; i < 6; i++){ | ||
int c1 = clues[23-i], c2 = clues[6+i]; | ||
std::pair<int, int> key = std::make_pair(c1, c2); | ||
for (int j = 0; j < 6; j++){ | ||
for (const int imp : impTable[key][j]){ | ||
removePossible(i, j, imp); | ||
} | ||
} | ||
} | ||
|
||
// for each column | ||
for (int i = 0; i < 6; i++){ | ||
int c1 = clues[i], c2 = clues[17-i]; | ||
std::pair<int, int> key = std::make_pair(c1, c2); | ||
for (int j = 0; j < 6; j++){ | ||
for (const int imp : impTable[key][j]){ | ||
removePossible(j, i, imp); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void lastResortPass(){ | ||
// for each row | ||
for (int i = 0; i < 6; i++){ | ||
// for each number | ||
for (int n = 1; n <= 6; n++){ | ||
int possiblePosition = 6; | ||
for (int j = 0; j < 6; j++){ | ||
if (possibles[i][j].count(n)){ | ||
if (possiblePosition == 6) possiblePosition = j; | ||
else { possiblePosition = 6; break; } | ||
} | ||
} | ||
if (possiblePosition != 6){ | ||
printf("Filling (%d, %d) with %d\n", i, possiblePosition, n); | ||
fillMapValue(i, possiblePosition, n); | ||
} | ||
} | ||
} | ||
// for each column | ||
for (int j = 0; j < 6; j++){ | ||
// for each number | ||
for (int n = 1; n <= 6; n++){ | ||
int possiblePosition = 6; | ||
for (int i = 0; i < 6; i++){ | ||
if (possibles[i][j].count(n)){ | ||
if (possiblePosition == 6) possiblePosition = i; | ||
else { possiblePosition = 6; break; } | ||
} | ||
} | ||
if (possiblePosition != 6){ | ||
printf("Filling (%d, %d) with %d\n", possiblePosition, j, n); | ||
fillMapValue(possiblePosition, j, n); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void processQueue(){ | ||
while (!checkQueue.empty()){ | ||
std::pair<int, int> key = checkQueue.front(); | ||
checkQueue.pop(); | ||
fillMapValue(key.first, key.second, *possibles[key.first][key.second].begin()); | ||
} | ||
} | ||
|
||
void printPossibles(){ | ||
for (int i = 0; i < 6; i++){ | ||
for (int j = 0; j < 6; j++){ | ||
std::cout << possibles[i][j].size() << " "; | ||
} | ||
printf("\n"); | ||
} | ||
} | ||
|
||
void printPossiblesDetailed(){ | ||
for (int i = 0; i < 6; i++){ | ||
for (int j = 0; j < 6; j++){ | ||
for (const int p : possibles[i][j]){ | ||
printf("%d ", p); | ||
} | ||
printf("\n"); | ||
} | ||
} | ||
} | ||
|
||
std::vector<std::vector<int>> SolvePuzzle(const std::vector<int> &_c){ | ||
reset(); | ||
clues = _c; | ||
impossiblesPass1(); | ||
processQueue(); | ||
lastResortPass(); | ||
processQueue(); | ||
lastResortPass(); | ||
return map; | ||
} | ||
|
||
std::vector<std::vector<int>> queries = { | ||
{ 3, 2, 2, 3, 2, 1, | ||
1, 2, 3, 3, 2, 2, | ||
5, 1, 2, 2, 4, 3, | ||
3, 2, 1, 2, 2, 4 }, | ||
{ 0, 0, 0, 2, 2, 0, | ||
0, 0, 0, 6, 3, 0, | ||
0, 4, 0, 0, 0, 0, | ||
4, 4, 0, 3, 0, 0 }, | ||
{ 0, 3, 0, 5, 3, 4, | ||
0, 0, 0, 0, 0, 1, | ||
0, 3, 0, 3, 2, 3, | ||
3, 2, 0, 3, 1, 0} | ||
}; | ||
|
||
int main(){ | ||
std::vector<std::vector<int>> answer = SolvePuzzle(queries[0]); | ||
|
||
for (const auto r : answer){ | ||
for (const int val : r){ | ||
printf("%d ", val); | ||
} | ||
printf("\n"); | ||
} | ||
} | ||
|
||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#include <bits/stdc++.h> | ||
|
||
bool checkRow(const std::array<int, 6> &row, int c1, int c2){ | ||
int s1 = 0; int s2 = 0; | ||
int max1 = 0; int max2 = 0; | ||
for (int i = 0; i < row.size(); i++){ | ||
if (row[i] > max1){ | ||
s1++; | ||
max1 = row[i]; | ||
} | ||
if (row[row.size()-1-i] > max2){ | ||
s2++; | ||
max2 = row[row.size()-1-i]; | ||
} | ||
} | ||
return c1==s1 && c2==s2; | ||
} | ||
|
||
void addToPossibles(const std::array<int, 6> &row, std::vector<std::set<int>> &possibles){ | ||
for (int i = 0; i < row.size(); i++){ | ||
possibles[i].insert(row[i]); | ||
} | ||
} | ||
|
||
void permute(std::array<int, 6> &row, std::vector<std::set<int>> &possibles, int l, int r, int c1, int c2){ | ||
if (l==r){ | ||
if (checkRow(row, c1, c2)){ | ||
addToPossibles(row, possibles); | ||
//printRow(row); | ||
} | ||
} | ||
else{ | ||
for (int i = l; i <= r; i++){ | ||
std::swap(row[l], row[i]); | ||
permute(row, possibles, l+1, r, c1, c2); | ||
std::swap(row[l], row[i]); | ||
} | ||
} | ||
} | ||
|
||
void printPossibles(const std::vector<std::set<int>> &possibles){ | ||
for (int i = 1; i <= 6; i++){ | ||
for (int j = 0; j < 6; j++){ | ||
if (possibles[j].count(i)){ | ||
printf("%d ", i); | ||
} | ||
else{ | ||
printf(" "); | ||
} | ||
} | ||
std::cout << std::endl; | ||
} | ||
} | ||
|
||
void convPoss2Imposs(const std::vector<std::set<int>> &possibles, std::vector<std::set<int>> &impossibles){ | ||
for (int i = 0; i < 6; i++){ | ||
for (int j = 1; j <= 6; j++){ | ||
if (!possibles[i].count(j)) impossibles[i].insert(j); | ||
} | ||
} | ||
} | ||
|
||
std::vector<std::set<int>> calcImpossibles(int c1, int c2){ | ||
std::vector<std::set<int>> possibles(6, std::set<int>()); | ||
std::array<int, 6> row = {1, 2, 3, 4, 5, 6}; | ||
permute(row, possibles, 0, 5, c1, c2); | ||
|
||
std::vector<std::set<int>> impossibles(6, std::set<int>()); | ||
convPoss2Imposs(possibles, impossibles); | ||
|
||
//printPossibles(impossibles); | ||
return impossibles; | ||
} | ||
|
||
void printVectorSet(const std::vector<std::set<int>> &vs){ | ||
for (const auto p : vs){ | ||
printf("{ "); | ||
for (const auto i : p){ | ||
printf("%d, ", i); | ||
} | ||
printf("}, "); | ||
} | ||
} | ||
|
||
void printTable(const std::map<std::pair<int, int>, std::vector<std::set<int>>> table){ | ||
printf("{\n"); | ||
for (const auto p : table){ | ||
printf("{{%d, %d}, {", p.first.first, p.first.second); | ||
printVectorSet(p.second); | ||
printf("}},\n"); | ||
} | ||
printf("}\n"); | ||
} | ||
|
||
int main(){ | ||
std::map<std::pair<int, int>, std::vector<std::set<int>>> impTable; | ||
for (int c1 = 1; c1 <= 6; c1++){ | ||
for (int c2 = 1; c2 <= 6; c2++){ | ||
if (c1+c2 > 7) continue; | ||
std::pair<int, int> key = std::make_pair(c1, c2); | ||
impTable[key] = calcImpossibles(c1, c2); | ||
} | ||
} | ||
|
||
printTable(impTable); | ||
} |
Binary file not shown.
Oops, something went wrong.