DEV Community

Discussion on: Daily Challenge #54 - What century is it?

Collapse
 
brightone profile image
Oleksii Filonenko

A reasonably short and reasonably Rusty solution:

pub fn century(year: u32) -> String {
    let century = year / 100 + 1;
    let suffix = match century % 100 {
        11 | 12 | 13 => "th",
        _ => match century % 10 {
            1 => "st",
            2 => "nd",
            3 => "rd",
            _ => "th",
        },
    };
    format!("{}{}", century, suffix)
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
olekria profile image
Olek Ria

Garna robota!
Good job!

Collapse
 
brightone profile image
Oleksii Filonenko

Diakuyu :)
Thanks :)