Commits

Shu Zong Chen  committed 2b7fb67

solved problem1

  • Participants

Comments (0)

Files changed (2)

+#!/bin/bash
+8g problem$1.go
+8l -o problem$1.out problem$1.8
+./problem$1.out
+/*
+Problem 1:
+If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
+
+Find the sum of all the multiples of 3 or 5 below 1000.
+*/
+package main
+
+import (
+	"fmt"
+)
+
+func run(limit int, multiples []int){
+	sum := 0
+	for i := 0; i < limit; i++ {
+		for _,v := range multiples {
+			if i % v == 0{
+				sum += i
+				break
+			}
+		}
+	}
+	fmt.Printf("%d\n", sum)
+}
+
+func main(){
+	run(1000, []int{3, 5})
+}
+