DEV Community

Discussion on: Daily Challenge #71 - See you next Happy Year

Collapse
 
brightone profile image
Oleksii Filonenko

Rust:

fn next_happy_year(year: u32) -> u32 {
    let mut year = year + 1;
    while !happy(year) {
        year += 1;
    }
    year
}

fn happy(year: u32) -> bool {
    let mut chars = year.to_string().chars().collect::<Vec<_>>();
    chars.sort();
    let len = chars.len();
    chars.dedup();
    chars.len() == len
}

This was a strange exercise to do in Rust. Feels dirty to use conversion to string :(