move lcm and gcf to Util
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
d56f59b19b
commit
b4828d3258
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue