Changed ratio to golang

This commit is contained in:
2018-04-07 00:14:45 +08:00
parent 5cec0a4ae7
commit ea69e01b9e
7 changed files with 22 additions and 171 deletions

22
ratio/ratio.go Normal file
View File

@@ -0,0 +1,22 @@
package main
import "github.com/alecthomas/kingpin"
import "fmt"
import "math"
func main() {
var (
x = kingpin.Arg("x", "X value of the ratio").Required().Int64()
y = kingpin.Arg("y", "Y value of the ratio").Required().Int64()
)
kingpin.Parse()
for i:=int64(2); i<=int64(math.Max(float64(*x), float64(*y))); i++ {
if (*x % i ==0) && (*y % i ==0) {
*x = *x / i
*y = *y / i
i = 1
}
}
fmt.Println(*x,*y)
}