Adding euler: cs and erlang, and a Makefile for cleaning and basic building

This commit is contained in:
Dan Ballard 2011-03-31 13:53:27 -07:00
parent f2cd84cffc
commit 3d62d1bdf7
3 changed files with 30 additions and 2 deletions

6
Makefile Normal file
View File

@ -0,0 +1,6 @@
default:
mcs *.cs
clean:
rm -r -f *.exe *.beam

13
e1.cs Normal file
View File

@ -0,0 +1,13 @@
using System;
public class E1
{
public static void Main() {
int sum = 0;
for(int i = 2; i < 1000; i++) {
if (i % 3 == 0 || i % 5 == 0)
sum += i;
}
System.Console.WriteLine(sum);
}
}

13
e1.erl
View File

@ -1,4 +1,13 @@
-module(e1).
-export([e1/1]).
-export([e1/0]).
e1(
add_list([], Acc) -> Acc;
add_list([X| Tail], Acc) -> add_list(Tail, Acc+X).
find_3_5_divisibles(Start, Max) -> find_3_5_divisibles(Start, Max, []).
find_3_5_divisibles(Max, Max, Acc) -> Acc;
find_3_5_divisibles(Start, Max, Acc) when Start rem 3 == 0; Start rem 5 == 0 -> find_3_5_divisibles(Start+1, Max, [Start |Acc]);
find_3_5_divisibles(Start, Max, Acc) -> find_3_5_divisibles(Start+1, Max, Acc).
e1() -> add_list(find_3_5_divisibles(2, 1000), 0).