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.47 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.46 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.45 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.44 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.43 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.42 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.41 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.40 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.39 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.38 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.37 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.36 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.35 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.34 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.33 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.32 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.31 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.30 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.29 tracks/rust/exercises/largest-series-product/example.rs
trackler-2.2.1.28 tracks/rust/exercises/largest-series-product/example.rs