<commit_before>#import <string>
#import <iostream>
#include <cassert>
using namespace std;

int num_safe_tiles(string inp, int rows) {
    int num_safe = 0;
    bool *curr = new bool[inp.length()];
    for(int i = 0; i < inp.length(); i++){
        curr[i] = inp[i] == '^';
        if(inp[i] != '^') {
            num_safe ++;
        }
    }
    for(int r = 0; r < rows - 1; r++) {
        bool *n_row = new bool[inp.length()];
        for(int i = 0; i < inp.length(); i++){
            if((i > 0 && curr[i-1]) ^ (i+1 < inp.length() && curr[i+1])) {
                n_row[i] = true;
            }
            else {
                n_row[i] = false;
                num_safe ++;
            }
        }
        delete[] curr;
        curr = n_row;
    }
    delete[] curr;
    return num_safe;
}

int main() {
    assert(num_safe_tiles("..^^.", 3) == 6);
    assert(num_safe_tiles(".^^.^.^^^^", 10) == 38);
    string input = "^.^^^.^..^....^^....^^^^.^^.^...^^.^.^^.^^.^^..^.^...^.^..^.^^.^..^.....^^^.^.^^^..^^...^^^...^...^.";
    cout << "Part 1: " << num_safe_tiles(input, 40) << endl;
    cout << "Part 2: " << num_safe_tiles(input, 400000) << endl;

}<commit_msg>Slight speedup on C++ solution<commit_after>#import <string>
#import <iostream>
#include <cassert>
using namespace std;

int num_safe_tiles(string inp, int rows) {
    int num_safe = 0;
    bool *curr = new bool[inp.length()];
    for(int i = 0; i < inp.length(); i++){
        curr[i] = inp[i] == '^';
        if(inp[i] != '^') {
            num_safe ++;
        }
    }
    bool *n_row = new bool[inp.length()];
    for(int r = 0; r < rows - 1; r++) {
        for(int i = 0; i < inp.length(); i++){
            if((i > 0 && curr[i-1]) ^ (i+1 < inp.length() && curr[i+1])) {
                n_row[i] = true;
            }
            else {
                n_row[i] = false;
                num_safe ++;
            }
        }
        bool *temp = curr;
        curr = n_row;
        n_row = temp;
    }
    delete[] curr;
    delete[] n_row;
    return num_safe;
}

int main() {
    assert(num_safe_tiles("..^^.", 3) == 6);
    assert(num_safe_tiles(".^^.^.^^^^", 10) == 38);
    string input = "^.^^^.^..^....^^....^^^^.^^.^...^^.^.^^.^^.^^..^.^...^.^..^.^^.^..^.....^^^.^.^^^..^^...^^^...^...^.";
    cout << "Part 1: " << num_safe_tiles(input, 40) << endl;
    cout << "Part 2: " << num_safe_tiles(input, 400000) << endl;

}
{'fraction_non_alphanumeric': 0.2644731361932528, 'fraction_numerical': 0.02082465639316951, 'mean_word_length': 1.7110609480812642, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 11, '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': '3166240', 'n_tokens_mistral': 994, 'n_tokens_neox': 934, 'n_words': 189}