diff --git a/src/bin/parkerrust.rs b/src/bin/parkerrust.rs index b03549a..f05cd03 100644 --- a/src/bin/parkerrust.rs +++ b/src/bin/parkerrust.rs @@ -79,8 +79,8 @@ fn findwords( if totalbits & w != 0 { 0usize } else { - let idx: usize = bits_to_index[&w]; - let mut newwords: [usize; 5] = words.clone(); + let idx: usize = bits_to_index[w]; + let mut newwords: [usize; 5] = *words; newwords[numwords] = idx; findwords( lettermask, @@ -96,40 +96,38 @@ fn findwords( } }) .sum::() - } else { - if numwords == 4 && skipped >= 0 { - let candidate = !(totalbits | lettermask[skipped as usize]) & 0x3FFFFFF; - if let Some(last_index) = bits_to_index.get(&candidate) { - words[numwords] = *last_index; + } else if numwords == 4 && skipped >= 0 { + let candidate = !(totalbits | lettermask[skipped as usize]) & 0x3FFFFFF; + if let Some(last_index) = bits_to_index.get(&candidate) { + words[numwords] = *last_index; - output(index_to_word, words); - numsolutions += 1 + output(index_to_word, words); + numsolutions += 1 + } + } else { + for w in letter_to_words_bits[i].iter() { + if totalbits & w != 0 { + continue; } - } else { - for w in letter_to_words_bits[i].iter() { - if totalbits & w != 0 { - continue; - } - let idx: usize = bits_to_index[&w]; - words[numwords] = idx; + let idx: usize = bits_to_index[w]; + words[numwords] = idx; - if numwords == 4 { - output(index_to_word, words); - numsolutions += 1 - } else { - numsolutions += findwords( - lettermask, - letter_to_words_bits, - bits_to_index, - index_to_word, - totalbits | w, - numwords + 1, - words, - i + 1, - skipped, - ) - } + if numwords == 4 { + output(index_to_word, words); + numsolutions += 1 + } else { + numsolutions += findwords( + lettermask, + letter_to_words_bits, + bits_to_index, + index_to_word, + totalbits | w, + numwords + 1, + words, + i + 1, + skipped, + ) } } } @@ -143,8 +141,7 @@ fn findwords( numsolutions } -fn output(index_to_word: &Vec<&[u8]>, words: &[usize; 5]) -> () { - // return; +fn output(index_to_word: &[&[u8]], words: &[usize; 5]) { let str = format!( "{} {} {} {} {}", unsafe { std::str::from_utf8_unchecked(index_to_word[words[0]]) }, diff --git a/src/lib.rs b/src/lib.rs index 9c5f03b..5f4ef12 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,7 +29,7 @@ pub fn readwords<'a>( let char = *char; // _technically_ this loop will not work for the last word // In practice the last word has a duplicate letter so we don't care - if char != '\n' as u8 { + if char != b'\n' { bits |= 1 << (char as u32 - 'a' as u32); continue; } @@ -73,7 +73,7 @@ pub fn readwords<'a>( let mut reverseletterorder: [usize; 26] = [0; 26]; for i in 0..26 { - lettermask[i] = (1 as u32) << freq[i].letter; + lettermask[i] = 1_u32 << freq[i].letter; reverseletterorder[freq[i].letter as usize] = i; }