You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
542 B
25 lines
542 B
fn main() {
|
|
println!("{}", validate(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]));
|
|
}
|
|
|
|
fn validate(card: Vec<u8>) -> bool {
|
|
let mut card = card;
|
|
let given_check = card.pop().unwrap();
|
|
|
|
let mut check = 0;
|
|
for (i, n) in card.iter().rev().enumerate() {
|
|
check += match i & 1 == 0 {
|
|
true => {
|
|
if *n > 4 {
|
|
(*n * 2) - 9
|
|
} else {
|
|
*n * 2
|
|
}
|
|
}
|
|
false => *n,
|
|
};
|
|
}
|
|
|
|
10 - (check % 10) == given_check
|
|
}
|