2019 Day 12 Complete

This commit is contained in:
2019-12-12 08:24:43 -06:00
parent 0362762d6f
commit 1400400fe0
5 changed files with 207 additions and 0 deletions

View File

@@ -27,6 +27,23 @@ const (
MIN_INT = -MAX_INT - 1
)
// Find the greatest common denominator
func Gcd(x, y int) int {
for y != 0 {
x, y = y, x%y
}
return x
}
// Find the least common multiple, using gcd
func Lcm(a, b int, integers ...int) int {
result := a * b / Gcd(a, b)
for i := 0; i < len(integers); i++ {
result = Lcm(result, integers[i])
}
return result
}
func AbsInt(i int) int {
if i < 0 {
return i * -1