thread269-1703513
What is the best way to store a simple date.
Should I just store it as a String or should I go through the process of using java.util.calendar or something similar?
I found this code on the internet and is a good example to work with dates
import java.util.Calendar;
import...
SUM LISTS OF LISTS
(if you want only pairs of numbers)
sum_list([], []).
sum_list([[A,B]|Rest], [Current|RestResult]) :-
Current is A + B,
sum_list(Rest, RestResult).
?- sum_list( [[1,2],[3,4],[5,6]], X ).
X = [3, 7, 11]...
Calculate the sum of a list of lists
%calculates the sum of one list of lists
sum_List([],[]).
sum_List([[E|T]|Rest],[Current|RestResult]):- soma(T,R),Current is E + R,sum_List(Rest,RestResult).
%calculates the sum of one list of numbers
soma([],0):-!.
soma([E|T],S):-soma(T,R),S is E+R...
for simple atomic statement
max(X,Y,X):-X >= Y.
max(X,Y,Y):-X < Y.
And for one list of numbers.
maxLis( [] ).
maxList( [E],E ).
maxList( [E,E2 | T],L ):-maxList( [E2 | T],L1 ),max(L1,E,L).
this program calculates the binary of any number. all you must do is write binario(7,X) for example.
% |0 se x<y
% div(x,y)|
% |1+div(x-y,y) se x>=y
% div(4,2,X).
div(X,Y,0):-X<Y.
div(X,Y,Z):-X>=Y,
X1 is X-Y,
div(X1,Y,Z1),Z is 1+Z1...
%first put into a list
lstCard(C):-findall(Y,card(_,Y),C).
%the last element of the list
lastb([]):-!,fail.
lastb([E],E):-!.
lastb([_|T],L):-lastb(T,L).
%is_top(e).
is_top(L):-lstCard(C),lastb(C,L).
hi
create a list with all the elements.
reverte the list and the top is the on the head
I don´t know if you can use predicates pre defined like "findall, reverse,head"
Ricardo
:)
...generateList(N,[X|Xs]):- N > 0,
X is N+1,
N1 is N-1,generateList(N1,Xs).
%formula of perfect numbers (2^p-1)*2^(p-1)
%ie calc(2,10,R)
calc(2,K,R):-power(2,K,X),R1 is X-1,primo(R1),
power(2,K-1,R2),
mul(R1,R2,R).
primo(X):-Y is...
thanks
yes
I have one error on the first part of this formula
I need to check, not only that p is prime,but that 2^p-1 is also prime(first part of the formula).
...find that person. But here it is .
%generate all perfect number until 100...
%Create perfect numbers
%divisible(10,2).
divisible(X,Y):- N is Y*Y,N =< X,X mod Y =:= 0.
divisible(X,Y):- Y < X, Y1 is Y + 1, divisible(X,Y1).
%isprime([3],Z).
isprime([X|_],X):-Y is 2, X >1, \+divisible(X,Y)...
...find that person. But here it is
%generate all perfect number until 100...
%Create perfect numbers
%divisible(10,2).
divisible(X,Y):- N is Y*Y,N =< X,X mod Y =:= 0.
divisible(X,Y):- Y < X, Y1 is Y + 1, divisible(X,Y1).
%isprime([3],Z).
isprime([X|_],X):-Y is 2, X >1, \+divisible(X,Y)...
...numbers
%divisible(X,Y):- Y=<X,X mod Y =:= 0.
%divisble(X,Y):- Y < X, Y1 is Y + 1, divisible(X,Y1).
%divisible(10,2).
divisible(X,Y):- N is Y*Y,N =< X,X mod Y =:= 0.
divisible(X,Y):- Y < X, Y1 is Y + 1, divisible(X,Y1).
%isprime([3],Z).
isprime([X|_],X):-Y is 2, X >1, \+divisible(X,Y)...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.