Skip to content

Commit

Permalink
fix: handle edge case in status calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
palerdot committed Feb 20, 2024
1 parent a1d4c45 commit 2640ccf
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/wordle/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,14 @@ pub fn check(wordle: String, guess: String) -> Vec<LetterStatus> {
} else {
// CASE 2: letter is present but not in the right position
// first let us find character occurences in the wordle
let wordle_occurences = wordle_letters
.clone()
.get(0..position + 1)
.unwrap()
.into_iter()
.fold(
0,
|acc, &letter| {
if letter == guess_letter {
acc + 1
} else {
acc
}
},
);
let wordle_occurences =
wordle_letters.clone().into_iter().fold(0, |acc, letter| {
if letter == guess_letter {
acc + 1
} else {
acc
}
});

let guess_occurences = guess_letters
.clone()
Expand Down Expand Up @@ -166,8 +159,6 @@ mod tests {
},
];

println!("{:?} --> ", output);

assert_eq!(output, expected);
}

Expand Down

0 comments on commit 2640ccf

Please sign in to comment.