-
-
Save vishalsodani/08b26b5a60e8b75a44728a58f4db7d05 to your computer and use it in GitHub Desktop.
Daily programmer May 16th Easy => 1st Version in Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Refactored new version https://gist.github.com/vishalsodani/f20c05bcf62b76cbf7951b541de30748