Nonogram solver: Difference between revisions

Content added Content deleted
Line 160: Line 160:
</lang>
</lang>
===Bonus GCHQ Xmas Puzzle===
===Bonus GCHQ Xmas Puzzle===
[[https://www.gchq.gov.uk/news-article/christmas-card-cryptographic-twist-charity GCHQ Xmas Puzzle]] is a Nonogram. They say "We pre-shaded a few cells to help people get started. Without this, the puzzle would have been slightly ambiguous, though the error correction used in QR codes means that the URL would have been recovered anyway. As a small Easter egg, the pre-shaded cells spell out “GCHQ” in Morse code."
<lang cpp>
<lang cpp>
int main(){
const std::vector<std::vector<int>> Ngchq={{ 7,3,1, 1,7},
{ 1,1,2,2, 1,1},
{ 1,3,1,3,1,1, 3,1},
{ 1,3,1,1,6,1, 3,1},
{ 1,3,1,5,2,1, 3,1},
{ 1,1,2, 1,1},
{ 7,1,1,1,1, 1,7},
{ 3,3},
{1,2,3,1,1,3,1, 1,2},
{ 1,1,3,2, 1,1},
{ 4,1,4,2, 1,2},
{ 1,1,1,1,1,4, 1,3},
{ 2,1,1,1, 2,5},
{ 3,2,2,6, 3,1},
{ 1,9,1,1, 2,1},
{ 2,1,2,2, 3,1},
{ 3,1,1,1,1, 5,1},
{ 1,2, 2,5},
{ 7,1,2,1,1, 1,3},
{ 1,1,2,1,2, 2,1},
{ 1,3,1,4, 5,1},
{ 1,3,1,3,10,2},
{ 1,3,1,1, 6,6},
{ 1,1,2,1, 1,2},
{ 7,2,1, 2,5}};
const std::vector<std::vector<int>> Ggchq={{ 7,2,1,1,7},
{ 1,1,2,2,1,1},
{1,3,1,3,1,3,1,3,1},
{ 1,3,1,1,5,1,3,1},
{ 1,3,1,1,4,1,3,1},
{ 1,1,1,2,1,1},
{ 7,1,1,1,1,1,7},
{ 1,1,3},
{ 2,1,2,1,8,2,1},
{ 2,2,1,2,1,1,1,2},
{ 1,7,3,2,1},
{ 1,2,3,1,1,1,1,1},
{ 4,1,1,2,6},
{ 3,3,1,1,1,3,1},
{ 1,2,5,2,2},
{2,2,1,1,1,1,1,2,1},
{ 1,3,3,2,1,8,1},
{ 6,2,1},
{ 7,1,4,1,1,3},
{ 1,1,1,1,4},
{ 1,3,1,3,7,1},
{1,3,1,1,1,2,1,1,4},
{ 1,3,1,4,3,3},
{ 1,1,2,2,2,6,1},
{ 7,1,3,2,1,1}};

std::vector<std::string> n = {"",
"",
"",
"...##.......##.......#",
"",
"",
"",
"",
"......##..#...##..#",
"",
"",
"",
"",
"",
"",
"",
"......#....#....#...#",
"",
"",
"",
"",
"...##....##....#....##"};
Nonogram<25,25> myN(Ngchq,Ggchq,n);
if (!myN.solve()) std::cout << "I don't believe that this is a nonogram!" << std::endl;
std::cout << "\n" << myN.toStr() << std::endl;
}
</lang>
</lang>