-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Secret Handshake approach #1636
Secret Handshake approach #1636
Conversation
… exercises/practice/secret-handshake/.approaches/iterate-once/snippet.txt
@ErikSchierboom: Rust approach for Secret Handshake ready for review. |
pub fn actions(n: u8) -> Vec<&'static str> { | ||
let (mut action, action_incr, end) = match n & REVERSE_SIGNS { | ||
0 => (0, 1, 4), | ||
_ => (3, -1, -1), | ||
}; | ||
let mut output: Vec<&'static str> = Vec::new(); | ||
|
||
loop { | ||
if action == end { | ||
break; | ||
} | ||
if (n & (1 << action)) != 0 { | ||
output.push(SIGNS[action as usize]) | ||
} | ||
action += action_incr | ||
} | ||
output | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must admit that I'm not well-versed in Rust, but to me this is very hard to read. It seems to almost obscure the logic. Is this an idiomatic way to solve the exercise in Rust? What about something simple like: https://exercism.org/tracks/rust/exercises/secret-handshake/solutions/aciba90?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are simpler approaches which don't offer as much in pedagogic value. Since I only did one approach, I used one which is not exactly unidiomatic, but which afforded more in the way of explanation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Okay!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is an interesting approach
Add approach to `secret-handshake`
Add approach to `secret-handshake`
An approach for Secret Handshake.