From 44c2536b720637854302ca52acbee6af54d9e875 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Fri, 25 Dec 2020 22:13:57 +0100 Subject: [PATCH] 2020: day25: pick smallest loop size --- aoc2020/src/day25.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/aoc2020/src/day25.rs b/aoc2020/src/day25.rs index 81539d8..bf8ac25 100644 --- a/aoc2020/src/day25.rs +++ b/aoc2020/src/day25.rs @@ -48,10 +48,17 @@ fn part1(input: &str) -> Result { .parse()?; let card_loop_size = find_loop_size(card_pub_key); + let door_loop_size = find_loop_size(door_pub_key); + + let (loop_size, pub_key) = if card_loop_size < door_loop_size { + (card_loop_size, door_pub_key) + } else { + (door_loop_size, card_pub_key) + }; let mut encryption_key = 1; - for _ in 0..card_loop_size { - encryption_key = transform(encryption_key, door_pub_key); + for _ in 0..loop_size { + encryption_key = transform(encryption_key, pub_key); } Ok(encryption_key)