Finished prolog and implemented objc for euler1
This commit is contained in:
parent
d6600f66bd
commit
ee9765dbac
2
Makefile
2
Makefile
|
@ -3,4 +3,4 @@ default:
|
||||||
mcs *.cs
|
mcs *.cs
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -r -f *.exe *.beam
|
rm -r -f *.exe *.beam a.out
|
||||||
|
|
|
@ -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
8
e1.pl
|
@ -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).
|
||||||
|
|
Loading…
Reference in New Issue