0% found this document useful (0 votes)
21 views10 pages

RaghavGupta - AI - Lab Experiment 2

Artificial Intelligence

Uploaded by

Raghav Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views10 pages

RaghavGupta - AI - Lab Experiment 2

Artificial Intelligence

Uploaded by

Raghav Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY

LAB FILE
FOR

SUBJECT: ARTIFICIAL INTELLIGENCE LAB


SUBJECT CODE: CSP472

SUBMITTED BY: Raghav Gupta


SYSTEM ID: 2018004539
ROLL NUMBER: 180101241

DR. VIVEK KUMAR SINGH


ASSISTANT PROFESSOR (CSE)

DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY


SHARDA UNIVERSITY, GREATER NOIDA
S.No Date Topic Page
No

1 15/09/21 Practical 01: Design a DFA which will accept all the strings containing 02
odd number of 1's over an alphabet {0, 1} and write a program to
implement the DFA.

10
Practical No 1: Write following programs in LISP.
Date: 15 September 2021

i. Write a LISP function to compute the sum of squares.

Code:

(defun sumsqr(x y)
(+(* x x)(* y y)))

(write(sumsqr 2 3))

Output:

2
ii. Write a LISP function to compute the difference of
squares. (if x>y return x 2 – y2, otherwise y2 - x2)

Code:

(defun diffsqr(x y)
(if(> x y)
(-(* x x)(* y y))
(-(* y y)(* x x))))

(write(diffsqr 2 3))

Output:

3
iii. Write a Recursive LISP function which takes one
argument as a list and returns the last element of the list.

Code:

(defun last_element(ab_list)
(first(reverse ab_list)))

(write (last_element '(a b c d)))


Output:

4
iv. Write a Recursive LISP function which takes one
argument as a list and return list except the last element of
the list.

Code:

(defun not_last(ab_list)
(reverse(rest(reverse ab_list))))

(write(not_last '(a b c d e)))

Output:

5
v. Write a Recursive LISP function which takes one
argument as a list and returns the reverse of the list.

Code:

(defun list-append (L1 L2)

(if (null L1)


L2
(cons (first L1) (list-append (rest L1) L2))))

(defun show-list-reverse (L)

(if (null L)
nil
(list-append (show-list-reverse (rest L))
(list (first L)))))

(write (show-list-reverse '(1 2 3 4)))

Output:

6
vi. Write a Recursive LISP function which takes two
arguments, first an atom and second a list, returns a list
after removing the first occurrence of that atom within the
list.

Code:

(defun remove(lst elt)


(cond((null lst)nil)
((equal(first lst)elt)(rest lst))
(elt(cons(first lst)
(remove(rest lst)elt)))))

(remove '(1 2 3 3 4 4)'3)

Output:

7
vii. Write a Recursive LISP function which appends two
lists together.

Code:

(defun list-append (L1 L2)


(if (null L1)
L2
(cons (first L1) (list-append (rest L1) L2))))

(write (list-append '(a b c) '(c d e)))

Output:

8
viii. Write a Recursive LISP function which takes two lists
as arguments and returns a list containing alternate
elements from each list

Code:

(defun alt(A B)
(cond
(( and (endp A) (endp B)) NIL)
(( endp A) B)
((endp B) A)
(T (cons (car A) (alt B (cdr A)))))
)

(write(alt '(1 3 5) '(6 8 9)))

Output:

You might also like