Skip to content

Commit f7efecf

Browse files
Boaz KaufmanBoaz Kaufman
Boaz Kaufman
authored and
Boaz Kaufman
committed
Added latin squares puzzle, need implementation and cleaning
1 parent 079c43e commit f7efecf

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

puzzles/Latin_Square/latin

46.1 KB
Binary file not shown.

puzzles/Latin_Square/latin.cpp

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//a Latin square is an n × n array filled with n different symbols,
2+
//each occurring exactly once in each row and exactly once in each column
3+
4+
#include <iostream>
5+
#include <array>
6+
#include <vector>
7+
#include <sstream>
8+
9+
using namespace std;
10+
11+
bool check_rows();
12+
bool check_cols();
13+
14+
int main()
15+
{
16+
int numToAdd = 0;
17+
int row; //row to change from user input
18+
int col; //column to change from user input
19+
string hold = "";
20+
int size;
21+
22+
//get difficulty (n for how large the square is)
23+
while (size >= 2)
24+
{
25+
cout << "Welcome to Latin Squares! How big do you want the square?" << endl;
26+
cin >> hold;
27+
stringstream conv(hold);
28+
conv >> size;
29+
}
30+
const int SQUARE_SIZE = size;
31+
int square[SQUARE_SIZE][SQUARE_SIZE];
32+
33+
for (int c = 0; c < SQUARE_SIZE; c++)
34+
{
35+
for (int r = 0; r < SQUARE_SIZE; r++)
36+
{
37+
square[r][c] = 0;
38+
}
39+
}
40+
41+
while (!check_rows() || !check_cols())
42+
{
43+
for (int c = 0; c < SQUARE_SIZE; c++)
44+
{
45+
for (int r = 0; r < SQUARE_SIZE; r++)
46+
{
47+
cout << square[r][c] << "\t";
48+
}
49+
cout << endl;
50+
}
51+
52+
while (numToAdd > 0 && numToAdd <= SQUARE_SIZE) //make sure the input is within range
53+
{
54+
cout << "Enter a number to add to the square:" << endl;
55+
cin >> hold;
56+
stringstream conv(hold);
57+
conv >> numToAdd;
58+
}
59+
60+
while (row > 0 && row <= SQUARE_SIZE)
61+
{
62+
cout << "Enter the row you want to put it in (first row is 1, second is 2, etc)" << endl;
63+
cin >> hold;
64+
stringstream conv(hold);
65+
conv >> row;
66+
}
67+
68+
while (col > 0 && col <= SQUARE_SIZE)
69+
{
70+
cout << "Enter the column you want to put it in (first column is 1, second is 2, etc)" << endl;
71+
cin >> hold;
72+
stringstream conv(hold);
73+
conv >> col;
74+
}
75+
76+
square[row][col] = numToAdd;
77+
}
78+
79+
cout << "Congrats! You've solved the square!" << endl;
80+
return 0;
81+
}
82+
83+
bool check_rows()
84+
{
85+
bool allGood = false;
86+
87+
return allGood;
88+
}
89+
90+
bool check_cols()
91+
{
92+
bool allGood = false;
93+
//to be implemented
94+
return allGood;
95+
}

0 commit comments

Comments
 (0)