Skip to content

Instantly share code, notes, and snippets.

@arkadyark
Created November 4, 2020 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arkadyark/84cb62f8ea5a8a623b457ed3ff9f7c25 to your computer and use it in GitHub Desktop.
Save arkadyark/84cb62f8ea5a8a623b457ed3ff9f7c25 to your computer and use it in GitHub Desktop.
cassidoo_problem_2020_11_04
/*
You have a character who jumps forward n number of units at a time, and an array representing the road in front of them (where 0 is a flat piece of road, and 1 is an obstacle). Return true or false if your character can jump to the end without hitting an obstacle in front of them.
Trying it out in rust this time!
Example:
character_jump(3, [0,1,0,0,0,1,0]) -> true
character_jump(3, [0,1,0,1,0,1,0]) -> false
*/
fn character_jump(step_size: u32, road: &[u32]) -> bool {
let mut index: usize = 0;
while (index) < road.len() {
if road[index] == 1 {
return false;
}
index += step_size as usize;
}
true
}
fn main() {
if character_jump(3, &[0,1,0,0,0,1,0]) == true &&
character_jump(3, &[0,1,0,1,0,1,0]) == false &&
character_jump(4, &[0,1,1,0,1,0,0,0,0]) == false {
println!("All tests passed!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment