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