Sha256: 887b1a288c311b32b53dbcc9d887fd7bb53f64341d686da8f3ff114860a8b1a4

Contents?: true

Size: 486 Bytes

Versions: 304

Compression:

Stored size: 486 Bytes

Contents

pub fn is_valid(candidate: &str) -> bool {
    if candidate.chars().filter(|c| c.is_digit(10)).take(2).count() <= 1 ||
       candidate.chars().any(|c| !c.is_digit(10) && c != ' ') {
        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

304 entries across 304 versions & 1 rubygems

Version Path
trackler-2.2.1.138 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.137 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.136 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.135 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.134 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.133 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.132 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.131 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.130 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.129 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.128 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.127 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.126 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.125 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.124 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.123 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.122 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.121 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.120 tracks/rust/exercises/luhn/example.rs
trackler-2.2.1.119 tracks/rust/exercises/luhn/example.rs