<commit_before>use core::hashmap::linear::{ LinearMap };

use std::sort::{ quick_sort3 };

use common::calc::{ num_to_digits };
use common::problem::{ Problem };

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

fn solve() -> ~str {
    let mut map = LinearMap::new::<~[uint], ~[uint]>();
    let mut n = 0;
    loop {
        n += 1;
        let cube = n * n * n;
        let mut ds = num_to_digits(cube, 10);
        quick_sort3(ds);

        let v = match map.pop(&ds) {
            Some(nums) => nums + ~[ cube ],
            None       => ~[cube]
        };
        if v.len() == 5 {
            return v[0].to_str();
        }
        map.insert(ds, v);
    }
}
<commit_msg>Improve problem #62<commit_after>use core::hashmap::linear::{ LinearMap, LinearSet };

use std::sort::{ quick_sort3 };

use common::calc::{ num_to_digits };
use common::problem::{ Problem };

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

fn solve() -> ~str {
    let mut map = LinearMap::new::<~[uint], ~[uint]>();
    let mut set = LinearSet::new::<uint>();
    let mut n     = 0;
    let mut limit = 10;
    loop {
        n += 1;
        if n >= limit {
            if !set.is_empty() {
                break;
            }
            limit *= 10;
        }

        let cube = n * n * n;
        let mut ds = num_to_digits(cube, 10);
        quick_sort3(ds);

        let v = match map.pop(&ds) {
            Some(nums) => nums + ~[ cube ],
            None       => ~[cube]
        };
        if v.len() == 5 {
            set.insert(v[0]);
        }
        if v.len() == 6 {
            set.remove(&v[0]);
        }
        map.insert(ds, v);
    }

    let mut answer = uint::max_value;
    for set.each |&n| {
        if n < answer { answer = n; }
    }
    return answer.to_str();
}

{'fraction_non_alphanumeric': 0.1699105733824303, 'fraction_numerical': 0.027354024197790636, 'mean_word_length': 1.7645348837209303, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '5492766', 'n_tokens_mistral': 699, 'n_tokens_neox': 661, 'n_words': 166}