Sha256: e8452b4de5251d4dd246909938cd417c13f73d01c9257899452f65f271ecf23e

Contents?: true

Size: 434 Bytes

Versions: 24

Compression:

Stored size: 434 Bytes

Contents

pub fn is_valid(candidate: &str) -> bool {
    if candidate.chars().any(|c| c.is_alphabetic()) || candidate.chars().count() == 1 {
        return false;
    }

    candidate.chars()
        .filter_map(|c| c.to_digit(10))
        .rev()
        .enumerate()
        .map(|(index, digit)| if index % 2 == 0 { digit } else { digit * 2 })
        .map(|digit| if digit > 9 { digit - 9 } else { digit })
        .sum::<u32>() % 10 == 0
}

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
trackler-2.0.6.35 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.34 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.33 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.32 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.31 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.30 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.29 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.28 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.27 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.26 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.25 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.24 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.23 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.22 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.21 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.20 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.19 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.18 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.17 tracks/rust/exercises/luhn/example.rs
trackler-2.0.6.16 tracks/rust/exercises/luhn/example.rs