DEV Community

Discussion on: Daily Challenge #201 - Complete the Pattern

Collapse
 
necrotechno profile image
NecroTechno

Rust :)

Playground link

fn pattern(input: f32) -> String {
    if input < 1.0 {
        return "".to_string();
    }
    let input_u32 = input.round() as u32;
    let mut response: String = "".to_string();
    for a in 0..input_u32 + 1 {
        for _b in 0..a {
            response.push_str(&a.to_string());
        }
        response.push_str("\n")
    }
    response
}

fn main() {
    println!("{}", pattern(4_f32));
    println!("{}", pattern(8_f32));
    println!("{}", pattern(0.5));
    println!("{}", pattern(2.5));
}