rewriting ex1 in go

This commit is contained in:
christalib 2019-02-19 00:48:31 +01:00
parent ef5c4ab647
commit 87b91deb36
2 changed files with 15 additions and 1 deletions

13
euler_go/ex1/ex1.go Normal file
View file

@ -0,0 +1,13 @@
package main
import "fmt"
func main() {
sum := 0
for i := 0; i < 1000; i++ {
if i%3 == 0 || i%5 == 0 {
sum += i
}
}
fmt.Print(sum)
}

View file

@ -1,4 +1,5 @@
# Solution for the sum of all number multiple of 3 or 5 between 1 and 999
sum = (1..999).select {|n| n % 5 == 0 || n % 3 == 0}
sum.inject(:+)
result = sum.inject(:+)
print result