88 lines
2.2 KiB
Rust
88 lines
2.2 KiB
Rust
extern crate num_bigint;
|
|
// extern crate num_traits;
|
|
|
|
use num_bigint::BigUint;
|
|
|
|
struct Counter {
|
|
length: u64,
|
|
prefix: u8,
|
|
last: BigUint,
|
|
total: BigUint
|
|
}
|
|
|
|
impl Counter {
|
|
fn new() -> Counter {
|
|
Counter {length: 1, prefix: 0, last: BigUint::from(0u8), total: BigUint::from(0u8)}
|
|
}
|
|
}
|
|
|
|
impl Iterator for Counter {
|
|
type Item = BigUint;
|
|
|
|
fn next(&mut self) -> Option<BigUint> {
|
|
let old = self.last;
|
|
let old_str = old.to_str_radix(10);
|
|
let mut new_str = old_str;
|
|
|
|
let mut carry = true;
|
|
let mut index = 0;
|
|
|
|
while carry != true {
|
|
match old_str[old_str.chars().count() - 1 - index] {
|
|
'5' => {carry = false; new_str[new_str.chars().count() - 1 - index] = '7'},
|
|
'7' => {carry = false; new_str[new_str.chars().count() - 1 - index] = '8'},
|
|
'8' => {carry = false; new_str[new_str.chars().count() - 1 - index] = '9'},
|
|
'9' => {carry = true; index += 1; new_str[new_str.chars().count() - 1 - index + 1] = '5'}
|
|
}
|
|
}
|
|
if carry == true {
|
|
self.prefix += 1;
|
|
}
|
|
|
|
let new_string = String::new();
|
|
new_string.push_str(match self.prefix {
|
|
0 => "",
|
|
1 => "2",
|
|
2 => "3",
|
|
3 => "4",
|
|
4 => "6",
|
|
5 => "26"
|
|
});
|
|
new_string.push_str(new_str);
|
|
return BigUint::from_str(new_string);
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let mut num = BigUint::from(0 as u8);
|
|
// num = num + 277777788888899u128;
|
|
let mut max: u8 = 0;
|
|
|
|
let mut n = test(num.clone());
|
|
while n < 10 {
|
|
n = test(num.clone());
|
|
if (n > max) {
|
|
max = n;
|
|
println!("{}: {}", n, num);
|
|
}
|
|
num += 1u8;
|
|
}
|
|
}
|
|
|
|
fn test(input: BigUint) -> u8 {
|
|
let mut n = factorize(input);
|
|
let mut counter = 1;
|
|
while (n.to_str_radix(10).chars().count() > 1) {
|
|
n = factorize(n);
|
|
// println!("n: {:?}", n);
|
|
counter += 1;
|
|
}
|
|
return counter;
|
|
}
|
|
|
|
fn factorize(input: BigUint) -> BigUint {
|
|
let string = input.to_str_radix(10);
|
|
let numbers: Vec<u8> = string.chars().map(|x| x as u8 - 48).collect();
|
|
numbers.into_iter().product::<BigUint>()
|
|
}
|