Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <array>
- #include <numeric>
- #include <algorithm>
- #include <utility>
- template<typename T, int N, std::size_t... I>
- constexpr std::array<T, N> istoarr(std::index_sequence<I...>) {
- return std::array<T, N>{ {I...} };
- }
- template<typename T, int N>
- constexpr std::array<T, N> create_array() {
- return istoarr<T, N>(std::make_index_sequence<N>{});
- }
- template<int N>
- constexpr int determinant(const std::array<std::array<int, N>, N>& a) {
- int det = 0;
- std::array<int, N> perm = create_array<int, N>();
- int sign = 1;
- do {
- int det_perm = sign;
- for (int i = 0; i < N; ++i) {
- det_perm *= a[i][perm[i]];
- }
- det += det_perm;
- sign *= -1;
- } while (std::next_permutation(perm.begin(), perm.end()));
- return det;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement