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.0.6.29 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.28 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.27 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.26 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.25 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.24 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.23 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.22 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.21 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.20 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.19 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.18 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.17 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.16 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.15 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.14 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.13 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.12 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.11 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.0.6.10 tracks/rust/exercises/largest-series-product/example.rs