<commit_before>pub fn is_valid<S: Into<String>>(digits: S) -> bool {
    let s: String = digits.into();
    if s.chars().all(|c| c.is_digit(10) || c.is_whitespace()) {
        let cs = s.chars().filter(|c| c.is_digit(10)).collect::<Vec<_>>();
        cs.len() > 1
            && cs.into_iter()
                .rev()
                .enumerate()
                .map(|(i, c)| transmogrify(i, c))
                .sum::<u32>() % 10 == 0
    } else {
        false
    }
}

fn transmogrify(i: usize, c: char) -> u32 {
    let x = c.to_digit(10).unwrap();
    if i & 1 == 0 {
        x
    } else if x > 4 {
        x + x - 9
    } else {
        x + x
    }
}<commit_msg>better<commit_after>pub fn is_valid<S: Into<String>>(digits: S) -> bool {
    let (nums, others): (Vec<_>, Vec<_>) =
        digits.into().chars().partition(|&c| c.is_digit(10));
    if others.iter().any(|&c| !c.is_whitespace()) || nums.len() < 2 {
        false
    } else {
        nums.iter()
            .rev()
            .enumerate()
            .map(|(i, &c)| transmogrify(i, c))
            .sum::<u32>() % 10 == 0
    }
}

fn transmogrify(i: usize, c: char) -> u32 {
    let x = c.to_digit(10).unwrap();
    if i & 1 == 0 {
        x
    } else if x > 4 {
        x + x - 9
    } else {
        x + x
    }
}
{'fraction_non_alphanumeric': 0.19906687402799378, 'fraction_numerical': 0.026438569206842923, 'mean_word_length': 1.5791583166332666, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 20, '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': '2241844', 'n_tokens_mistral': 523, 'n_tokens_neox': 493, 'n_words': 110}