Created
October 25, 2013 02:09
-
-
Save fffprograming/7148462 to your computer and use it in GitHub Desktop.
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
odd(X) :- X mod 2 =\= 0. | |
odd2sum1(1,1). | |
odd2sum1(N,Sum) :- odd(N), N2 is N-2,odd2sum1(N2,Sum2),Sum is Sum2 + N*N. | |
odd2sum1(N,Sum) :- N2 is N-1,odd2sum1(N2,Sum). |
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
o2sum(N,M,Sum) :- N > M,Sum is 0. | |
o2sum(N,M,Sum) :- N2 is N + 2,o2sum(N2,M,Sum2),Sum is Sum2 + N*N. | |
odd2sum2(N,S) :- o2sum(1,N,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
odd2sum3(N,S) :- A is (N + 1) / 2, B is floor(A), S is B * (4*B*B - 1) / 3. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment