-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpandigital_multiples.rs
More file actions
25 lines (21 loc) · 940 Bytes
/
pandigital_multiples.rs
File metadata and controls
25 lines (21 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use crate::utils;
pub fn solve() -> i64 {
let mut pandigital_checker = utils::PandigitalChecker::new(1, 9);
// We have to find a concatenated product at least as much as 918273645
// (which is provided as an example). Hence, the most significant digit of
// the integer to search for must be 9. Further, to end up with 9 digits,
// said integer must have 4 non-repeated digits. This means only two
// consecutive products need be considered.
let num_to_find = (9123..=9876)
.rev()
.find(|&num| {
pandigital_checker.renew();
pandigital_checker.update(num) && pandigital_checker.update(num * 2) && pandigital_checker.check()
})
.unwrap();
// We have found the integer. Now find the pandigital concatenated product
// by sticking twice its value to its right.
let result = num_to_find * 100002;
assert_eq!(result, 932718654);
result
}