From 1463b36617505a4c3ae7de46fe03793a620d5639 Mon Sep 17 00:00:00 2001 From: "Dr. Matthias Ratajczak" Date: Tue, 16 Aug 2022 20:17:31 +0200 Subject: [PATCH] fix commented out code --- src/euler51/src/main.rs | 53 +++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/src/euler51/src/main.rs b/src/euler51/src/main.rs index 9ec19cf..3d1c381 100644 --- a/src/euler51/src/main.rs +++ b/src/euler51/src/main.rs @@ -9,34 +9,41 @@ use primes::Primes; type Int = u64; // EXAMPLE 1 -// const MIN_VALUE: Int = 10; -// const MAX_VALUE: Int = 99; -// const LENGTH: usize = 2; -// const MIN_LENGTH: usize = 1; +// const SEARCH_MIN: Int = 10; +// const SEARCH_MAX: Int = 99; +// const AMOUNT_OF_DIGITS_IN_NUMBER: usize = 2; +// const MIN_PATTERN_LENGTH: usize = 1; +// const FAMILY_SIZE: usize = 6; // EXAMPLE 2 -// const MIN_VALUE: Int = 10_000; -// const MAX_VALUE: Int = 99_999; -// const LENGTH: usize = 5; -// const MIN_LENGTH: usize = 2; +// const SEARCH_MIN: Int = 10_000; +// const SEARCH_MAX: Int = 99_999; +// const AMOUNT_OF_DIGITS_IN_NUMBER: usize = 5; +// const MIN_PATTERN_LENGTH: usize = 1; +// const FAMILY_SIZE: usize = 7; // FINAL -const MIN_VALUE: Int = 100_000; -const MAX_VALUE: Int = 999_999; -const LENGTH: usize = 6; -const MIN_LENGTH: usize = 2; -const TARGET_LENGTH: usize = 8; +const SEARCH_MIN: Int = 100_000; +const SEARCH_MAX: Int = 999_999; +const AMOUNT_OF_DIGITS_IN_NUMBER: usize = 6; +const MIN_PATTERN_LENGTH: usize = 2; +const FAMILY_SIZE: usize = 8; -const MAX_LENGTH: usize = LENGTH - 1; -const DIGITS: [u8; 10] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; +const MAX_PATTERN_LENGTH: usize = AMOUNT_OF_DIGITS_IN_NUMBER - 1; +const NUMBER_OF_DIGITS: usize = 10; +const DIGITS: [u8; NUMBER_OF_DIGITS] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; fn main() { - let all_primes = Primes::get_between(MIN_VALUE, MAX_VALUE); - let mut processed_cases = HashSet::with_capacity(MIN_VALUE as usize); - let mut primes_matching_pattern = Vec::with_capacity(TARGET_LENGTH); - let mut case_buf = String::with_capacity(LENGTH); + let all_primes = Primes::get_between(SEARCH_MIN, SEARCH_MAX); + let mut processed_cases = HashSet::with_capacity(SEARCH_MIN as usize); + let mut primes_matching_pattern = Vec::with_capacity(FAMILY_SIZE); + let mut case_buf = String::with_capacity(AMOUNT_OF_DIGITS_IN_NUMBER); - for pattern in PositionCombinations::new(MIN_LENGTH, MAX_LENGTH, LENGTH) { + for pattern in PositionCombinations::new( + MIN_PATTERN_LENGTH, + MAX_PATTERN_LENGTH, + AMOUNT_OF_DIGITS_IN_NUMBER, + ) { for prime in &all_primes.vector { primes_matching_pattern.clear(); @@ -59,7 +66,7 @@ fn main() { primes_matching_pattern.push(could_be_prime); } } - if primes_matching_pattern.len() == TARGET_LENGTH { + if primes_matching_pattern.len() == FAMILY_SIZE { println!("{primes_matching_pattern:#?}"); exit(0); } @@ -68,8 +75,8 @@ fn main() { } fn enough_digits_left(i: usize, primes_len: usize) -> bool { - // are there enough digits left in the loop to achieve the required TARGET_LENGTH? - i - primes_len + TARGET_LENGTH <= 10 + // are there enough digits left in the loop to achieve the required FAMILY_SIZE? + i - primes_len + FAMILY_SIZE <= NUMBER_OF_DIGITS } fn get_case_string(digits: &[u8], pattern: &[bool], buf: &mut String) {