Создать список, элементами которого являются 2^n - Prolog

Формулировка задачи:

Создать список, элементами которого являются 2^n,n!, члены последовательности Фибоначчи

Код к задаче: «Создать список, элементами которого являются 2^n - Prolog»

textual
domains
num_train=string /*nomer poezda*/
destination=string /*punkt naznacheniya*/
departure_hour=integer/*vremya otpravleniya_chas*/
departure_min=integer /*vremya otpravlenya_min*/
arrival=string /*vremya pribytiya*/
database
train(num_train,destination,departure_hour,departure_min,arrival)
trainNeed(num_train,destination,departure_hour,departure_min,arrival)
predicates
menu
open_base(string) /*otkritie basy*/
case(char)
print_base /*vivod basy na ekran*/
trainToMoscow(integer,integer) /*poezd do Moscvy po zadaniu*/
checkTime(integer,integer,integer,integer) /*proverka vremeni*/
compare(integer,integer,integer,integer) /*sravnenie vremeni*/
taskTrain
goal
clearwindow,
write("Enter the name of base:"),nl,
readln(FileName),
open_base(FileName),
menu,
save(FileName),
retractall(_).
clauses
open_base(FileName):-
existfile(FileName),
consult(FileName).
open_base(_).
menu:-
clearwindow,
write("1 - Show time table\n2 - Enter new record\n3 - Delete record\n4 - Task\n0 - Exit\n\n"),
readchar(Item),
case(Item).
case('1'):- /*vivod basy na ekran*/
clearwindow,
print_base,
readchar(_),
menu.
case('2'):- /*dobavlenie novoy zapisi*/
clearwindow,
write("Number of train:"),nl,
readln(Numb),
write("Destination:"),nl,
readln(Dest),
write("Departure (hour):"),nl,
readint(DepHour),nl,
write("Departure (min):"),nl,
readint(DepMin),nl,
write("Arrival time (hour:min):"),nl,
readln(Arriv),nl,
assertz(train(Numb,Dest,DepHour,DepMin,Arriv)),
menu.
case('3'):- /*udalenie poezda po nomeru*/
clearwindow,
write("Enter number of train:"),nl,
readln(DelNumb),
retract(train(DelNumb,_,_,_,_)),
menu.
case('4'):- /*zadanieoisk blizhaishego poezda do moskvy*/
clearwindow,
write("Enter hour of departure"),nl,
readint(TimeHour),nl,
write("Enter minute of departure"),nl,
readint(TimeMin),nl,
trainToMoscow(TimeHour,TimeMin),
taskTrain,
retractall(trainNeed(_,_,_,_,_)),
readchar(_),
menu.
case('0').
case(_):-
menu.
print_base:-
train(Numb,Dest,DepHour,DepMin,Arriv),
write(Numb," | ",Dest," | ",DepHour,":",DepMin," | ",Arriv),nl,
fail.
print_base.
trainToMoscow(TimeHour,TimeMin):-
train(Numb,Dest,DepHour,DepMin,Arriv),
Dest="Moscow",
checkTime(DepHour,DepMin,TimeHour,TimeMin),
assertz(trainNeed(Numb,Dest,DepHour,DepMin,Arriv)),
fail.
trainToMoscow(_,_).
checkTime(DepHour,DepMin,TimeHour,TimeMin):-
X=DepHour+6,
compare(DepHour,DepMin,X,TimeMin),
compare(TimeHour,TimeMin,DepHour,DepMin),!.
checkTime(DepHour,DepMin,TimeHour,TimeMin):-
X=TimeHour+6,
Y=DepHour+24,
compare(Y,DepMin,X,TimeMin),
compare(TimeHour,TimeMin,Y,DepMin),!.
compare(T1,_,T2,_):-
T1<T2.
compare(T1,M1,T2,M2):-
T1=T2,M1<=M2.
taskTrain:-
trainNeed(Numb,Dest,DepHour,DepMin,Arriv),
write(Numb," | ",Dest," | ",DepHour,":",DepMin," | ",Arriv),nl,
fail.
taskTrain.

9   голосов, оценка 4.333 из 5


СОХРАНИТЬ ССЫЛКУ