Skip to content

Instantly share code, notes, and snippets.

@vishalsodani
Created May 20, 2016 04:33
Show Gist options
  • Save vishalsodani/08b26b5a60e8b75a44728a58f4db7d05 to your computer and use it in GitHub Desktop.
Save vishalsodani/08b26b5a60e8b75a44728a58f4db7d05 to your computer and use it in GitHub Desktop.
Daily programmer May 16th Easy => 1st Version in Rust
fn print_non_wining_places(won_place: i32) {
let mut display = String::new() ;
for x in 0..500 {
if x != won_place && x != 0 {
let string_number = x.to_string() ;
let mut copy_string_number = x.to_string() ;
let last_char = copy_string_number.pop();
let penultimate_char = copy_string_number.pop();
match last_char {
Some(x) => if x == '2' {
match penultimate_char {
Some(y) => if y == '1' {
display = display + &string_number + "th " ;
}
else {
display = display + &string_number + "nd " ;
},
None => display = display + &string_number + "nd " ,
}
}
else if x == '3' {
match penultimate_char {
Some(y) => if y == '1' {
display = display + &string_number + "th " ;
}
else {
display = display + &string_number + "rd " ;
},
None => display = display + &string_number + "rd ",
}
}
else if x == '1' {
match penultimate_char {
Some(y) => if y == '1' {
display = display + &string_number + "th " ;
}
else {
display = display + &string_number + "st " ;
},
None => display = display + &string_number + "st ",
}
}
else {
display = display + &string_number + "th ";
},
None => (),
}
}
}
println!("{}", display);
}
@vishalsodani
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment