-
-
Save m-renaud/fdd92b0f36827ea1ec92 to your computer and use it in GitHub Desktop.
A simple problem in C++ and Haskell.
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
template <typename T> | |
bool f(const vector<vector<T>>& matrix) { | |
if (matrix.size() == 0) { | |
return true; | |
} | |
size_t m = matrix.size(); | |
size_t n = matrix[0].size(); | |
for (int r = 0; r < m; ++r) { | |
for (int c = 0; c < n; ++c) { | |
if (matrix[r][c] != matrix[m-r-1][n-c-1]) { | |
return false; | |
} | |
} | |
} | |
return true; | |
} |
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
f :: [[a]] -> Bool | |
f matrix = flattenedMatrix == (reverse flattenedMatrix) | |
where flattenedMatrix = concat matrix | |
-- Note that concat (defined in the default environment) simply flattens a list of lists into a list. | |
concat :: [[a]] -> [a] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment