Wednesday, February 21, 2024

Reverse a list.

 

Reverse a list.

my_reverse(L1,L2) :- my_rev(L1,L2,[]).


my_rev([],L2,L2) :- !.

my_rev([X|Xs],L2,Acc) :- my_rev(Xs,L2,[X|Acc]).



Find the number of elements of a list.

 

Find the number of elements of a list.

my_length([],0).

my_length([_|L],N) :- my_length(L,N1), N is N1 + 1.

Find the K'th element of a list in prolog

 

Find the K'th element of a list in prolog

element_at(X,[X|_],1).

element_at(X,[_|L],K) :- K > 1, K1 is K - 1, element_at(X,L,K1).


Find the last element of a lis in prolog

 Find the last element of a list in prolog

my_last(X,[X]).

my_last(X,[_|L]) :- my_last(X,L).


Determining if a term is a list.

 Determining if a term is a list.


list([]).
list([X|Xs]) :- list(Xs).



?- list([a,b,c]).

yes

?- list(abc).

no

LIST PROGRAM IN LIST

 


Determining if a term is a list.  click

 Find the last element of a list in prolog  click

Find the K'th element of a list in prolog click

Find the number of elements of a list.

Reverse a list.

Find out whether a list is a palindrome.


prolog 1

 Permutation:



insert(X,L,[X|L]).


insert(X,[H|T],[H|U]) :-

  insert(X,T,U).




permute([],[]).


permute([H|T],L) :-

  permute(T,U),

  insert(H,U,L).

Sunday, February 18, 2024

basic command

 

ADDITION:

set x 5

set y 10

expr $x + $y

set z [ expr $x + $y]

puts "sum=$z"

output:

15

sum=15


LOOP:

set i 0

while{$i <10}{

puts $i

set i [ expr $i + 1]

}


ORIENTATION

 The optional orientation values may be defined in degrees or by text like :



                                                                        right (0)



                                                                       right-up (45)

                                                            right-down (-45),

 left (180), left-up (135), left-down (-135), up (90), down (-90).

Wednesday, February 14, 2024

NS2

 

Introduction  click

BASIC COMMAND-

NODE CREATE  CLICK

TCP CLICK

UDP  CLICK

4.Packet tracing: 

DUPLEX LINK CLICK

 QUEUER TYPE -CLICK

LARGE TOPOLOGY USING LOOP CLICK

DIFFERENT COLOR NODE:   CLICK

TOPOLOGY  CLICK

ORIENTATION -CLICK