parent
f3712555d5
commit
631472da41
@ -0,0 +1,9 @@
|
|||||||
|
package algs4
|
||||||
|
|
||||||
|
func Gcd(p, q uint64) uint64 {
|
||||||
|
if q == 0 {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
r := p % q
|
||||||
|
return Gcd(q, r)
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package algs4_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
import (
|
||||||
|
"meatballhat.com/algs4"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGcd(t *testing.T) {
|
||||||
|
d := algs4.Gcd(uint64(81), uint64(72))
|
||||||
|
if d != 9 {
|
||||||
|
t.Error("WRONG")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue