Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
make util.Lcm a tad easier to understand
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieterbe committed Feb 17, 2017
1 parent 6dc62be commit a7775e3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ func MaxInt(a, b int) int {
func Lcm(vals []uint32) uint32 {
out := vals[0]
for i := 1; i < len(vals); i++ {
a := Max(uint32(vals[i]), out)
b := Min(uint32(vals[i]), out)
r := a % b
max := Max(uint32(vals[i]), out)
min := Min(uint32(vals[i]), out)
r := max % min
if r != 0 {
for j := uint32(2); j <= b; j++ {
if (j*a)%b == 0 {
out = j * a
for j := uint32(2); j <= min; j++ {
if (j*max)%min == 0 {
out = j * max
break
}
}
} else {
out = a
out = max
}
}
return out
Expand Down

0 comments on commit a7775e3

Please sign in to comment.