Created
April 11, 2015 22:10
-
-
Save thekarel/5e4027a74655f72c481b to your computer and use it in GitHub Desktop.
GCD in go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
func gcd(a, b int) int { | |
for b != 0 { | |
rem := math.Mod(float64(a), float64(b)) | |
a = b | |
b = int(rem) | |
} | |
return a | |
} | |
func main() { | |
fmt.Println(gcd(30, 8)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why
math.Mod
and conversion betweenint
andfloat64
when there's%
?