.


:




:

































 

 

 

 


4.

4.1. , , .

pal([],""):-!.

pal(Str,Newstr):-

Str=[H|T],

pal(T,RT),

append(RT,[H],Newstr).

ā% library(win_menu) compiled into win_menu 0.00 sec, 29 clauses

% c:/documents and settings/student/application data/swi-prolog/pl.ini compiled 0.00 sec, 1 clauses

% c:/Documents and Settings/Student/ /aa.pl compiled 0.00 sec, 3 clauses

Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 6.2.0)

Copyright (c) 1990-2012 University of Amsterdam, VU Amsterdam

SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to redistribute it under certain conditions.

Please visit http://www.swi-prolog.org for details.

1.?- pal("",X), string_to_list(Y,X).

X = [1090, 1077, 1074, 1080, 1088, 1055],

Y = "".

4.2. .

min(X,Y,X):- X<Y,!.

min(_,X,X).

str_min(Str1, Str2, Str1):-

length(Str1, Length1),

length(Str2, Length2),

min(Length1,Length2,Length1),!.

str_min(_, Str, Str).

list_str_min([],_):-!.

list_str_min(List, Min):-

List=[First|AllWords],

list_str_min(AllWords, MinfromAllWords),

str_min(First, MinfromAllWords, Min).

list_of_words([],[]):-!.

list_of_words(Str, ListofWords):-

append(FirstWord, [32|Tile],Str),!,

list_of_words(Tile, ListofTile),

ListofWords=[FirstWord|ListofTile].

list_of_words(Word, [Word]):-!.

min_from_cent(Str, Min):-

list_of_words(Str, ListofWords),

list_str_min(ListofWords, Min).

.

% library(win_menu) compiled into win_menu 0.00 sec, 29 clauses

% c:/documents and settings/student/application data/swi-prolog/pl.ini compiled 0.00 sec, 1 clauses

% c:/Documents and Settings/Student/ /lab.pl compiled 0.00 sec, 11 clauses

Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 6.2.0)

Copyright (c) 1990-2012 University of Amsterdam, VU Amsterdam

SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to redistribute it under certain conditions.

Please visit http://www.swi-prolog.org for details.

 

For help, use?- help(Topic). or?- apropos(Word).

 

1?- min_from_cent(" , ?",X), string_to_list(Y,X).

X = [1082, 1072, 1082],

Y = "".

6

.. 4--12

. ,, . , , . , , , , , .

Prolog

get([A|B],A,B).

get([A|B],C,[A|D]):- get(B,C,D).

reh([ [FF,'Albert'],['Pavlic',FF],[A,B],[C,D] ]):-

F=['Bictor','Karl'],

get(F,FF,F1),

get(F1,C,_),

get(F1,B,_),

A='Albert',

D='Pavlic'.

% library(win_menu) compiled into win_menu 0.00 sec, 29 clauses

% c:/documents and settings/student/application data/swi-prolog/pl.ini compiled 0.00 sec, 1 clauses

% c:/Documents and Settings/Student/ /tt.pl compiled 0.00 sec, 4 clauses

Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 6.2.0)

Copyright (c) 1990-2012 University of Amsterdam, VU Amsterdam

SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to redistribute it under certain conditions.

Please visit http://www.swi-prolog.org for details.

 

For help, use?- help(Topic). or?- apropos(Word).

 

1?- reh(X).

X = [['Bictor', 'Albert'], ['Pavlic', 'Bictor'], ['Albert', 'Karl'], ['Karl', 'Pavlic']];

X = [['Karl', 'Albert'], ['Pavlic', 'Karl'], ['Albert', 'Bictor'], ['Bictor', 'Pavlic']];

false.

5 . .4--12

t. t .

.

readfromfile(Name,String):-

ls, see(Name),

get_char(T),

not(T=end_of_file),!,

char_code(T,Code),

String=[Code|OtherCodes],

readfromfile(Name,OtherCodes).

readfromfile(_,[]):-seen.

str_delete(Str,Pos,Count,Result):-

I is Pos-1,

append(Head,Tile,Str),

length(Head,I),

append(Cut,TileofTile,Tile),

length(Cut,Count),

append(Head,TileofTile,Result).

.

library(win_menu) compiled into win_menu 0.00 sec, 29 clauses

% c:/documents and settings/student/application data/swi-prolog/pl.ini compiled 0.00 sec, 1 clauses

% c:/Documents and Settings/Student/ /lab5.pl compiled 0.02 sec, 4 clauses

Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 6.2.0)

Copyright (c) 1990-2012 University of Amsterdam, VU Amsterdam

SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to redistribute it under certain conditions.

Please visit http://www.swi-prolog.org for details.

 

For help, use?- help(Topic). or?- apropos(Word).

readfromfile('t.txt',X), length(X,Z), string_to_list(S,X).

X = [53, 54, 115, 115, 102, 115, 100, 102, 115|...],

Z = 11,

S = "56ssfsdfsd5".

readfromfile('t.txt',X), length(X,Z), string_to_list(S,X), str_delete(X,10,1,Y),string_to_list(Q,Y).

X = [53, 54, 115, 115, 102, 115, 100, 102, 115|...],

Z = 11,

S = "56ssfsdfsd5",

Y = [53, 54, 115, 115, 102, 115, 100, 102, 115|...],

Q = "56ssfsdfs5".

.. 4--12

.

3

1. , .

.

count(empty,0).

count(tree(_,empty,empty),0).

count(tree(_,Left,Right),X):-

count(Left,XL),

count(Right,XR),

X is XL+XR+1.

 

sum1(empty,0).

sum1(tree(X,Left,Right),Y):-

sum1(Left,SL),

sum1(Right,SR),

Y is SL+SR+X.

 

tree_leavessum(tree(Y,empty,empty),Y):-!.

tree_leavessum(tree(_,Left,Right),Y):-

tree_leavessum(Left,YL),

tree_leavessum(Right,YR),

Y is YL +YR.

 

tree_avogadro(Tree, Avr):-

count(Tree, Count),

tree_leavessum(Tree,Sum),

sum1(Tree,Sum1),

Avr1=Sum1-Sum,

Avr is Avr1/Count.

 

main:- T=tree(2,tree(7,empty,empty),tree(3,tree(4,empty,empty),tree(1,empty,empty))),

write(T), nl,

tree_avogadro(T,Avr),

write('Avr='), write(Avr).

% library(win_menu) compiled into win_menu 0.00 sec, 29 clauses

% f:/reer.pl compiled 0.00 sec, 10 clauses

Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 6.2.0)

Copyright (c) 1990-2012 University of Amsterdam, VU Amsterdam

SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to redistribute it under certain conditions.

Please visit http://www.swi-prolog.org for details.

 

For help, use?- help(Topic). or?- apropos(Word).

 

1?- main.

tree(2,tree(7,empty,empty),tree(3,tree(4,empty,empty),tree(1,empty,empty)))

Avr=2.5

true

 

 



<== | ==>
| 1.
:


: 2016-10-07; !; : 526 |


:

:

, - , ; , - .
==> ...

1677 - | 1690 -


© 2015-2024 lektsii.org - -

: 0.017 .