<commit_before>pub struct PascalsTriangle {
    row_count: u32,
}

impl PascalsTriangle {
    pub fn new(row_count: u32) -> Self {
        PascalsTriangle { row_count: row_count }
    }

    pub fn rows(&self) -> Vec<Vec<u32>> {
        match self.row_count {
            0 => Vec::new(),
            _ => (1..self.row_count).fold(vec![vec![1]], |res, _| append_next_row(res)),
        }
    }
}

fn append_next_row(mut rows: Vec<Vec<u32>>) -> Vec<Vec<u32>> {
    let end_row = rows.last().unwrap().to_vec();
    let end_row_iter_left = end_row[0..end_row.len() - 1].iter();
    let end_row_iter_right = end_row[1..end_row.len()].iter();

    let mut next_row: Vec<u32> = end_row_iter_left.zip(end_row_iter_right)
        .fold(vec![1], |mut res, (x, y)| {
            res.push(x + y);
            res
        });
    next_row.push(1);

    rows.push(next_row);
    rows
}
<commit_msg>Way better solution for pascals-triangle<commit_after>pub struct PascalsTriangle {
    row_count: u32,
}

impl PascalsTriangle {
    pub fn new(row_count: u32) -> Self {
        PascalsTriangle { row_count: row_count }
    }

    pub fn rows(&self) -> Vec<Vec<u32>> {
        (0..self.row_count).map(|x| calc_row(x)).collect()
    }
}

fn calc_row(n: u32) -> Vec<u32> {
    let mut next_row: Vec<u32> = Vec::with_capacity(n as usize + 1);
    (1..n + 2).fold(1, |acc, x| {
        next_row.push(acc);
        acc * (n + 1 - x) / x
    });
    next_row
}

{'fraction_non_alphanumeric': 0.16678248783877692, 'fraction_numerical': 0.02640722724113968, 'mean_word_length': 2.5036496350364965, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 22, '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': '3921681', 'n_tokens_mistral': 585, 'n_tokens_neox': 564, 'n_words': 105}