<commit_before>#include <iostream>
#include <utility>
#include <algorithm>

#include "magic_square.h"
#include "main.h"

Magic_Square::Magic_Square(const int size) : order(size), board(order, slice_t(order)) {
    if (order % 2 == 0) {
        throw std::logic_error("Order cannot be even.");
    }
    if (order > 15) {
        throw std::logic_error("Order cannot be above 15.");
    }
    if (order < 3) {
        throw std::logic_error("Order cannot be below 3.");
    }

    construct();
}

void Magic_Square::print() {
    for (slice_t slice : board) {
        for (auto element : slice) {
            if (element < 10) {
                std::cout << "  " << element << " ";
            } else if(element < 100) {
                std::cout << " " << element << " ";
            } else {
                std::cout << element << " ";
            }
        }
        std::cout << "\n";
    }
}

// Checks if all of the sums of the array are equal
slice_t check_sum(const slice_t sums) {
    for (unsigned int i = 0; i < sums.size() - 1; i++) {
        if (sums[i] != sums[i + 1]) {
            throw std::logic_error("Not a magic square!");
        }
    }
    return sums;
}

// Get the sum of an array
int get_sum(const slice_t slice) {
    int sum = 0;

    for (auto element : slice) {
        sum += element;
    }

    return sum;
}

slice_t Magic_Square::get_row(const int row) {
    return board[row];
}

slice_t Magic_Square::sum_row() {
    slice_t sums;
    for (int i = 0; i != order; i++) {
        sums.push_back(get_sum(get_row(i)));
    }
    return check_sum(sums);
}

slice_t Magic_Square::get_col(const int col) {
    slice_t out_col;
    for (slice_t slice : board) {
        out_col.push_back((slice)[col]);
    }
    return out_col;
}

slice_t Magic_Square::sum_col() {
    slice_t sums;
    for (int i = 0; i != order; i++) {
        sums.push_back(get_sum(get_col(i)));
    }
    return check_sum(sums);
}

slice_t Magic_Square::get_diag_left_right() {
    slice_t diag;
    for (int row = 0, col = 0; row != order || col != order; row++, col++) {
        diag.push_back(board[row][col]);
    }
    return diag;
}

slice_t Magic_Square::get_diag_right_left() {
    slice_t diag;
    for (int row = order - 1, col = order - 1; row >= 0 || col >= 0; row--, col--) {
        diag.push_back(board[row][col]);
    }
    return diag;
}

slice_t Magic_Square::sum_diag() {
    slice_t sums;
    sums.push_back(get_sum(get_diag_left_right()));
    sums.push_back(get_sum(get_diag_right_left()));
    return sums;
}

// Generates the magic square
void Magic_Square::construct() {
    // Start in middle top of the square
    std::unique_ptr<point_t> point_ptr(new point_t(0, order / 2));

    for (int i = 1; i <= order*order; i++) {
        write(*point_ptr, i);
        point_ptr.reset(new point_t(move(*point_ptr)));<commit_msg>labeled sections of source code<commit_after>#include <iostream>
#include <utility>
#include <algorithm>

#include "magic_square.h"
#include "main.h"

Magic_Square::Magic_Square(const int size) : order(size), board(order, slice_t(order)) {
    if (order % 2 == 0) {
        throw std::logic_error("Order cannot be even.");
    }
    if (order > 15) {
        throw std::logic_error("Order cannot be above 15.");
    }
    if (order < 3) {
        throw std::logic_error("Order cannot be below 3.");
    }

    construct();
}

void Magic_Square::print() {
    for (slice_t slice : board) {
        for (auto element : slice) {
            if (element < 10) {
                std::cout << "  " << element << " ";
            } else if(element < 100) {
                std::cout << " " << element << " ";
            } else {
                std::cout << element << " ";
            }
        }
        std::cout << "\n";
    }
}

// Summing

// Checks if all of the sums of the array are equal
slice_t check_sum(const slice_t sums) {
    for (unsigned int i = 0; i < sums.size() - 1; i++) {
        if (sums[i] != sums[i + 1]) {
            throw std::logic_error("Not a magic square!");
        }
    }
    return sums;
}

// Get the sum of an array
int get_sum(const slice_t slice) {
    int sum = 0;

    for (auto element : slice) {
        sum += element;
    }

    return sum;
}

slice_t Magic_Square::get_row(const int row) {
    return board[row];
}

slice_t Magic_Square::sum_row() {
    slice_t sums;
    for (int i = 0; i != order; i++) {
        sums.push_back(get_sum(get_row(i)));
    }
    return check_sum(sums);
}

slice_t Magic_Square::get_col(const int col) {
    slice_t out_col;
    for (slice_t slice : board) {
        out_col.push_back((slice)[col]);
    }
    return out_col;
}

slice_t Magic_Square::sum_col() {
    slice_t sums;
    for (int i = 0; i != order; i++) {
        sums.push_back(get_sum(get_col(i)));
    }
    return check_sum(sums);
}

slice_t Magic_Square::get_diag_left_right() {
    slice_t diag;
    for (int row = 0, col = 0; row != order || col != order; row++, col++) {
        diag.push_back(board[row][col]);
    }
    return diag;
}

slice_t Magic_Square::get_diag_right_left() {
    slice_t diag;
    for (int row = order - 1, col = order - 1; row >= 0 || col >= 0; row--, col--) {
        diag.push_back(board[row][col]);
    }
    return diag;
}

slice_t Magic_Square::sum_diag() {
    slice_t sums;
    sums.push_back(get_sum(get_diag_left_right()));
    sums.push_back(get_sum(get_diag_right_left()));
    return sums;
}

// Creating the magic square

// Generates the magic square
void Magic_Square::construct() {
    // Start in middle top of the square
    std::unique_ptr<point_t> point_ptr(new point_t(0, order / 2));

    for (int i = 1; i <= order*order; i++) {
        write(*point_ptr, i);
        point_ptr.reset(new point_t(move(*point_ptr)));
{'fraction_non_alphanumeric': 0.1528308440430705, 'fraction_numerical': 0.009725599166377214, 'mean_word_length': 2.4526378896882495, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6389482', 'n_tokens_mistral': 2133, 'n_tokens_neox': 2018, 'n_words': 512}