Sha256: cb15c22b9949d14ec3dc2b9e8bddc4a32664df8043738f51f53cd31a38df2173

Contents?: true

Size: 600 Bytes

Versions: 311

Compression:

Stored size: 600 Bytes

Contents

pub fn lsp(string_digits: &str, span: usize) -> Result<u64, String> {
    if span == 0 {
        return Ok(1);
    }

    if string_digits.chars().any(|c| !c.is_digit(10)) {
        return Err(String::from("All characters must be numbers"));
    }

    let products: Vec<u64> = string_digits.chars()
        .map(|c| c.to_digit(10).unwrap() as u64)
        .collect::<Vec<u64>>()
        .windows(span)
        .map(|w| w.into_iter().product())
        .collect();

    if let Some(&x) = products.iter().max() {
        Ok(x)
    } else {
        Err(String::from("Span longer than string"))
    }
}

Version data entries

311 entries across 311 versions & 1 rubygems

Version Path
trackler-2.2.1.128 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.127 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.126 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.125 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.124 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.123 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.122 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.121 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.120 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.119 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.118 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.117 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.116 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.115 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.114 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.113 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.111 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.110 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.109 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.108 tracks/rust/exercises/largest-series-product/example.rs