+3
-1
day2/shortinput.txt
+3
-1
day2/shortinput.txt
+19
-14
day2/src/main.rs
+19
-14
day2/src/main.rs
···
31
31
// n = 121212, i = 1, mod = 2, ldigits = 1
32
32
// n = 121212, i = 2, mod = 12, ldigits = 12
33
33
// -> n = 1212, i = 2, mod = 12, ldigits = 12 !!!
34
+
//
35
+
// 101 -> 1) 10,1 ; 0 != 1
36
+
// 101 -> 2) 1,1 1 < 10 !!
34
37
35
38
fn is_invalid_id_hard(id: u64) -> bool {
36
-
println!("=== Checking ID: {} ===", id);
39
+
// println!("=== Checking ID: {} ===", id);
37
40
let mut c_id = id;
38
-
let mut parts_equal = true;
39
-
let mut cur_part = c_id % 10;
41
+
let mut cur_part;
40
42
// i is the log value, ie the window size we are checking
41
43
for i in 1..(id as f64).log10() as u32 + 1 {
42
44
// trim off end of number
43
45
// we saved the current part above
44
46
let pow_10 = (10u32.pow(i) as u64);
47
+
cur_part = c_id % pow_10;
48
+
45
49
// println!("n = {}, i = {}, pow_10 = {}", id, i, pow_10);
46
50
// repeat until the value drops below the target log
47
-
while c_id > pow_10 {
51
+
while c_id > 10 {
48
52
// remove last n digits from c_id
49
53
c_id = c_id / pow_10;
50
54
// last i digits of c_id
51
55
let last_digits = c_id % pow_10;
52
56
if last_digits == cur_part {
53
-
if c_id < pow_10 {
57
+
// println!(
58
+
// "For exponent {}, digits {} and {} matched in {}, id slice {}",
59
+
// i, last_digits, cur_part, id, c_id
60
+
// );
61
+
if last_digits >= (10u32.pow(i - 1) as u64) && c_id == last_digits {
54
62
return true;
55
63
}
56
-
println!(
57
-
"For window {}, digits {} and {} matched in {}, id slice {}",
58
-
i, last_digits, cur_part, id, c_id
59
-
);
60
-
cur_part = c_id / pow_10 % (10u32.pow(i + 1) as u64);
64
+
// set cur_part to last i+1 digits
65
+
// cur_part = c_id / pow_10 % (10u32.pow(i + 1) as u64);
61
66
} else {
62
-
println!(
63
-
"For window {}, digits {} and {} matched in {}, id slice {}",
64
-
i, last_digits, cur_part, id, c_id
65
-
);
67
+
// println!(
68
+
// "For exponent {}, digits {} and {} DO NOT MATCH in {}, id slice {}",
69
+
// i, last_digits, cur_part, id, c_id
70
+
// );
66
71
break;
67
72
}
68
73
}