Last active
June 7, 2016 08:17
-
-
Save klang/88be106286dbd6c9c896f33f64902f5e to your computer and use it in GitHub Desktop.
Project Euler - Problem 1 - https://projecteuler.net/problem=1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Ocaml *) | |
let rec range ?(start=0) len = | |
if start >= len | |
then [] | |
else start :: (range len ~start:(start+1)) | |
List.fold_left (+) 0 (List.map (fun x -> if 0 = x mod 3 or 0 = x mod 5 then x else 0) (range 1000)) | |
List.fold_left (+) 0 (List.filter (fun x -> 0 = x mod 3 or 0 = x mod 5) (range 1000)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Clojure | |
(reduce + (map #(if (or (= 0 (mod % 5)) (= 0 (mod % 3))) % 0) (range 1000))) | |
(reduce + (filter #(or (= 0 (mod % 5)) (= 0 (mod % 3))) (range 1000))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Haskell | |
foldr (+) 0 (map (\x -> if 0==mod x 3 || 0 == mod x 5 then x else 0) [0..1000]) | |
foldr (+) 0 (filter (\x -> 0==mod x 3 || 0 == mod x 5) [0..1000]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.stream.IntStream; | |
public class Problem001 { | |
public static void main(String[] args) { | |
final int s = IntStream.range(0,1000).filter(x -> x%3==0 || x%5==0 ).reduce(0,(acc,x)->acc+x); | |
System.out.println(s); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use List::Util qw(reduce); | |
$a = reduce {$a + $b} grep { $_ % 3 == 0 || $_ % 5 == 0} 0 .. 1000; | |
$b += $_ for grep { $_ % 3 == 0 || $_ % 5 == 0} 0 .. 1000; | |
print $a.$/.$b; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python | |
reduce(lambda x, y: x+y,map(lambda x : x if 0==x%3 or 0==x%5 else 0, range(0,1000))) | |
reduce(lambda x, y: x+y, filter(lambda x : 0==x%3 or 0==x%5, range(0,1000))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment