Problem 1
Ruby
1sum = 0;
2i = 0;
3loop do
4 if i == 1000
5 break
6 end
7 if i % 3 == 0 || i % 5 == 0
8 sum += i
9 end
10 i += 1
11end
12puts "#{sum}"
Clojure
1(ns problem1.core)
2
3(defn mod3or5?
4 [x]
5 (cond
6 (= (mod x 3) 0) x
7 (= (mod x 5) 0) x
8 :else 0))
9
10(defn -main
11 []
12 (println (reduce + (map mod3or5? (range 1 1000)) )))
Perl 6
1say [+] ( 1 .. ^ 1000 ).grep({ !($_ % ( 3 & 5 ))});
Java
1class SumMod3or5 {
2 public static void main(String args[]){
3 int UpperBound = 1000;
4 int sum = 0;
5 for(int i = 3; i < UpperBound; i++){
6 if(i % 3 == 0 || i % 5 == 0){
7 sum += i;
8 }
9 }
10 System.out.printf("%d\n", sum);
11 }
12}