<commit_before>use std::bigint::{ BigUint };

use common::problem::{ Problem };

pub static problem: Problem<'static> = Problem {
    id: 56,
    answer: "972",
    solver: solve
};

fn digit_sum(n: uint) -> uint {
    let mut sum = 0;
    let mut d = n;
    while d > 0 {
        sum += d % 10;
        d = d / 10;
    }
    return sum;
}

fn solve() -> ~str {
    let ten = BigUint::from_uint(1000000000);

    let mut max = 0u;
    for uint::range(1, 100) |a| {
        let mut n = BigUint::from_uint(a);
        for 100.times {
            n = n * BigUint::from_uint(a);
            let mut sum = 0;
            let mut (d, m) = n.divmod(&ten);
            sum += digit_sum(m.to_uint());
            while !d.is_zero() {
                let (d0, m) = d.divmod(&ten);
                sum += digit_sum(m.to_uint());
                d = d0;
            }
            // following core causes core dumps...
            // let s = n.to_str();
            // for str::each_char(s) |c| {
            //     let d = char::to_digit(c, 10);
            //     sum += d.get();
            // }
            max = uint::max(max, sum);
        }
    }

    return max.to_str();
}
<commit_msg>Follow bigint's method name change (divmod => div_mod)<commit_after>use std::bigint::{ BigUint };

use common::problem::{ Problem };

pub static problem: Problem<'static> = Problem {
    id: 56,
    answer: "972",
    solver: solve
};

fn digit_sum(n: uint) -> uint {
    let mut sum = 0;
    let mut d = n;
    while d > 0 {
        sum += d % 10;
        d = d / 10;
    }
    return sum;
}

fn solve() -> ~str {
    let ten = BigUint::from_uint(1000000000);

    let mut max = 0u;
    for uint::range(1, 100) |a| {
        let mut n = BigUint::from_uint(a);
        for 100.times {
            n = n * BigUint::from_uint(a);
            let mut sum = 0;
            let mut (d, m) = n.div_mod(&ten);
            sum += digit_sum(m.to_uint());
            while !d.is_zero() {
                let (d0, m) = d.div_mod(&ten);
                sum += digit_sum(m.to_uint());
                d = d0;
            }
            // following core causes core dumps...
            // let s = n.to_str();
            // for str::each_char(s) |c| {
            //     let d = char::to_digit(c, 10);
            //     sum += d.get();
            // }
            max = uint::max(max, sum);
        }
    }

    return max.to_str();
}

{'fraction_non_alphanumeric': 0.1599501454092231, 'fraction_numerical': 0.028250934773577065, 'mean_word_length': 1.4274193548387097, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '4195272', 'n_tokens_mistral': 884, 'n_tokens_neox': 821, 'n_words': 218}