I've been working on Project Euler, here was my solution for Problem #1. It gave me the proper answer, but it's egregiously slow. How can I implement this more efficiently? My math skills aren't top-notch, sorry.
package main
import (
"fmt"
)
// Problem1: find the sum of all the multiples of 3 or 5 below 1000.
// x,y: multiples
// z: upper limit
func Problem1(x, y, z int) int {
Multiples := make(map[int]struct{})
var Sum int
for i := 1; i < z; i++ {
XFactor := x * i
YFactor := y * i
if XFactor < z {
Multiples[XFactor] = struct{}{}
}
if YFactor < z {
Multiples[YFactor] = struct{}{}
}
}
for key, _ := range Multiples {
Sum = Sum + key
}
return Sum
}
func main() {
fmt.Println("The answer to problem 1 is: ", Problem1(3,5,1000))
}
answer to problem 2
?) \$\endgroup\$