Small speed note: Rust 1.7 just made custom hashing functions available. Rust uses a cryptographically secure hashing function by default, but for work like this, that's inappropriate. To use FNV instead:
1. add fnv to your Cargo.toml's dependencies section 2. The first few lines become:
extern crate fnv;
use std::collections::HashMap;
use std::hash::BuildHasherDefault;
use fnv::FnvHasher;
type MyHasher = BuildHasherDefault<FnvHasher>;
2. and the hash creation line becomes let mut last_digit_pair_counts: HashMap<String, u64, MyHasher> = HashMap::default();
This is 17% faster on my two runs of your code. :)Other notes:
format!("{}-{}", last_digit0, last_digit1).to_string();
The .to_string() is redundant here, format! already gives you a String. That should remove a bunch of allocations.