Finished prolog and implemented objc for euler1

This commit is contained in:
Dan Ballard 2011-03-31 17:28:23 -07:00
parent d6600f66bd
commit ee9765dbac
3 changed files with 23 additions and 2 deletions

View File

@ -3,4 +3,4 @@ default:
mcs *.cs mcs *.cs
clean: clean:
rm -r -f *.exe *.beam rm -r -f *.exe *.beam a.out

15
e1.m Normal file
View File

@ -0,0 +1,15 @@
// comment
#include <objc/Object.h>
int main(int argc, char **argv) {
int sum = 0;
int i;
for(i = 2; i < 1000; i++) {
if ( i % 3 == 0 || i % 5 == 0) {
sum += i;
}
}
printf("%d\n", sum);
}

8
e1.pl
View File

@ -4,4 +4,10 @@ range(Start, End, [Start| Acc]) :- Next is Start + 1, range(Next, End, Acc).
divisors_3_5([], []). divisors_3_5([], []).
divisors_3_5([X|Xs], [X|Ys]) :- 0 is X rem 3, divisors_3_5(Xs, Ys). divisors_3_5([X|Xs], [X|Ys]) :- 0 is X rem 3, divisors_3_5(Xs, Ys).
divisors_3_5([X|Xs], [X|Ys]) :- 0 is X rem 5, divisors_3_5(Xs, Ys). divisors_3_5([X|Xs], [X|Ys]) :- 0 is X rem 5, divisors_3_5(Xs, Ys).
divisors_3_5([X|Xs], Ys]) :- divisors_3_5(Xs, Ys). divisors_3_5([X|Xs], Ys) :- divisors_3_5(Xs, Ys).
sum(List, Result) :- sum(List, 0, Result).
sum([], Acc, Acc).
sum([X|Xs], Acc, Num) :- Inc is X + Acc, sum(Xs, Inc, Num).
e1(Result) :- range(1,1000, R), divisors_3_5(R, Ds), sum(Ds,Result).