From b4828d32589534e7038942e32b72137b3b17be8a Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Wed, 1 Dec 2021 14:58:23 -0500 Subject: move lcm and gcf to Util --- aoc2019/Day12.cs | 15 +-------------- aoc2019/Util.cs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 aoc2019/Util.cs diff --git a/aoc2019/Day12.cs b/aoc2019/Day12.cs index 86d1981..1a36520 100644 --- a/aoc2019/Day12.cs +++ b/aoc2019/Day12.cs @@ -22,19 +22,6 @@ public sealed class Day12 : Day moon.SetSiblings(moons); } - private static long Lcm(long a, long b) => a * b / Gcd(a, b); - - private static long Gcd(long a, long b) - { - while (true) - { - if (b == 0) return a; - var a1 = a; - a = b; - b = a1 % b; - } - } - private void Step() { foreach (var moon in moons) @@ -66,7 +53,7 @@ public sealed class Day12 : Day if (cycleZ == 0 && moons.All(m => m.Dz == 0)) cycleZ = step * 2; } - return $"{Lcm(cycleX, Lcm(cycleY, cycleZ))}"; + return $"{Util.Lcm(cycleX, Util.Lcm(cycleY, cycleZ))}"; } public class Position diff --git a/aoc2019/Util.cs b/aoc2019/Util.cs new file mode 100644 index 0000000..28991e1 --- /dev/null +++ b/aoc2019/Util.cs @@ -0,0 +1,17 @@ +namespace aoc2019; + +internal static class Util +{ + public static long Lcm(long a, long b) => a * b / Gcd(a, b); + + private static long Gcd(long a, long b) + { + while (true) + { + if (b == 0) return a; + var a1 = a; + a = b; + b = a1 % b; + } + } +} \ No newline at end of file -- cgit 1.4.1