2019 Day 12 Complete
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user