From 937c63a985b937831c81bd87436a62804ff62fdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= Date: Sun, 24 Mar 2019 18:07:14 +0100 Subject: [PATCH] errr --- src/main.rs | 69 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5fb0ff5..3ca803f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,13 +3,70 @@ extern crate num_bigint; use num_bigint::BigUint; +struct Counter { + length: u64, + prefix: u8, + last: BigUint, + total: BigUint +} -fn main() -{ +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 { + 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; + // num = num + 277777788888899u128; + let mut max: u8 = 0; - println!("{:?}", test(num)); + 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 { @@ -17,7 +74,7 @@ fn test(input: BigUint) -> u8 { let mut counter = 1; while (n.to_str_radix(10).chars().count() > 1) { n = factorize(n); - println!("n: {:?}", n); + // println!("n: {:?}", n); counter += 1; } return counter; @@ -27,4 +84,4 @@ fn factorize(input: BigUint) -> BigUint { let string = input.to_str_radix(10); let numbers: Vec = string.chars().map(|x| x as u8 - 48).collect(); numbers.into_iter().product::() -} \ No newline at end of file +}