mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 23:04:42 +01:00
20201216
This commit is contained in:
31
20201216/main.go
Normal file
31
20201216/main.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
|
||||
func process(n int) []string {
|
||||
m := make(map[string]struct{})
|
||||
for i := 2; i <= n; i++ {
|
||||
for j := 1; j < i; j++ {
|
||||
g := findGCD(i, j)
|
||||
m[fmt.Sprintf("%d/%d", j/g, i/g)] = struct{}{}
|
||||
}
|
||||
}
|
||||
var ret []string
|
||||
for k := range m {
|
||||
ret = append(ret, k)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func findGCD(a, b int) int {
|
||||
for a > 0 {
|
||||
t := a
|
||||
a = b % a
|
||||
b = t
|
||||
}
|
||||
return b
|
||||
}
|
||||
Reference in New Issue
Block a user