diff options
author | Justin Wernick <justin@worthe-it.co.za> | 2022-04-19 20:24:37 +0200 |
---|---|---|
committer | Justin Wernick <justin@worthe-it.co.za> | 2022-04-19 20:24:37 +0200 |
commit | c99848b907d2d63577ffdc81fc11a77e4d328a92 (patch) | |
tree | a8a0f1880c624572bf502cd33087c4ecdc9edbc7 /2017/src/bin/day_15.rs | |
parent | 24fb5e0204a4d69286473b660fd64a8d4a254eaf (diff) |
Refile for merging repos
Diffstat (limited to '2017/src/bin/day_15.rs')
-rw-r--r-- | 2017/src/bin/day_15.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/2017/src/bin/day_15.rs b/2017/src/bin/day_15.rs new file mode 100644 index 0000000..29b63ad --- /dev/null +++ b/2017/src/bin/day_15.rs @@ -0,0 +1,40 @@ +extern crate advent_of_code_2017; +use advent_of_code_2017::*; + +fn main() { + let args = AdventArgs::init(); + + let mut a: u64 = 591; + let mut b: u64 = 393; + + let mut matches: u64 = 0; + + let comparisons = if args.part == 1 { + 40_000_000 + } else { + 5_000_000 + }; + + for _ in 0..comparisons { + a = (a * 16807) % 2147483647; + b = (b * 48271) % 2147483647; + + while args.part != 1 && a % 4 != 0 { + a = (a * 16807) % 2147483647; + } + while args.part != 1 && b % 8 != 0 { + b = (b * 48271) % 2147483647; + } + + if lower_16_match(a, b) { + matches += 1; + } + } + + println!("There were {} matches", matches); +} + +fn lower_16_match(a: u64, b: u64) -> bool { + let mask = 65535; //2^16-1, ie 16 ones + (a & mask) == (b & mask) +} |