Skip to content

Conversation

@ChocolateLoverRaj
Copy link
Contributor

No description provided.

@jusexton
Copy link
Owner

jusexton commented Oct 20, 2025

Great solution; although there is a lot of math acrobatics and casting being done to calculate the distance from 'a' for each character. It also takes a bit of thinking to realize that is what the closure is doing, even with a simplified formula. In these logic/math heavy closures I love giving them a name for the extra readability.

What do you think of something like the below?

pub fn min_operations(s: String) -> i32 {
    let distance_from_a = |c| (26 - (c as i32 - 97)) % 26;
    s.chars().map(distance_from_a).max().unwrap()
}

@jusexton jusexton merged commit 069ba0d into jusexton:main Nov 5, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants