Skip to content

Instantly share code, notes, and snippets.

@fffprograming
Created October 25, 2013 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fffprograming/7148462 to your computer and use it in GitHub Desktop.
Save fffprograming/7148462 to your computer and use it in GitHub Desktop.
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).
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).
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