about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBen Harris <ben@tilde.team>2021-12-01 14:58:23 -0500
committerBen Harris <ben@tilde.team>2021-12-01 14:58:23 -0500
commitb4828d32589534e7038942e32b72137b3b17be8a (patch)
tree47847f7b2ed86d52481541006a8e211c68f26ac3
parentd56f59b19b137d068d2d89a7f680ff7dca4f0757 (diff)
move lcm and gcf to Util HEAD master
-rw-r--r--aoc2019/Day12.cs15
-rw-r--r--aoc2019/Util.cs17
2 files changed, 18 insertions, 14 deletions
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