Last active
December 4, 2019 20:15
-
-
Save svantelidman/67d146adea716ccbdbe26deb8980a922 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let range = 235741..=706948; | |
let n_matches = range.into_iter().filter(|n| match_criteria(*n)).count(); | |
println!("Number of matches: {}", n_matches) | |
} | |
fn match_criteria(candidate: i32) -> bool { | |
let n1 = candidate % 10; | |
let n2 = (candidate / 10) % 10; | |
let n3 = (candidate / 100) % 10; | |
let n4 = (candidate / 1000) % 10; | |
let n5 = (candidate / 10000) % 10; | |
let n6 = (candidate / 100000) % 10; | |
let p = vec!(n6, n5, n4, n3, n2, n1); | |
let mut double = false; | |
for i in 1..6 { | |
if p[i] < p[i-1] { | |
return false | |
} | |
let d_cand = (p[i] == p[i-1]) && !((i > 1 && p[i-2] == p[i-1]) || (i < 5 && p[i] == p[i+1])); | |
double = double || d_cand | |
} | |
double | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment