{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

EEL5840 AI

# EEL5840 AI - Tarak Trivedi ECE Dept Fall 09 UFID 51837169...

This preview shows pages 1–4. Sign up to view the full content.

Tarak Trivedi ECE Dept Fall ‘09 UFID: 51837169 EEL-5840 Elements of Machine Intelligence Fall 2009 Homework 2 Programming Assignment: 3.1 T > ;;;;;;;;; ;;; Problem Statement: To define a basic swap function that returns the two-elements in the list in ;;; reverse order. ;;; Function: exchange ;;; The function exchange is defined. In this case we first check if the list is empty or if there is only ;;; one element. ;;; If that is the case then we print the list as it is.(either null or with single element. ;;; However, if the list has two elements then the conses are applied after extracting the second ;;; element and then the first element respectively thereby swapping the two elements. (defun exchange (list) (if (or (null list) (null (cdr list))) list (cons (second list) (cons (first list) ()))) ) EXCHANGE Test Cases: > (exchange '(adam eve)) (EVE ADAM) > (exchange '(abc)) (ABC) > (exchange '()) NIL > (exchange nil) NIL > (dribble)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
3.3 T > ;;;;;;;;; ;;;;Problem Statement: To define a function that shifts the elements in the list by one place towards the left side ;;;; and the former first element becomes the last element ;;; Function: ROTATE-LEFT ;;;;;;;;; ;;; The function ROTATE-LEFT is defined. ;;; Let the list have any elements. We simply append the first element of the list to all the elements starting from the ;;; second element including it.We cons the first element with nil to make it a list as APPEND function concatenates list arguments into one list. (defun rotate-left (lis1) (append(rest lis1) (cons (first lis1) () ) )) ROTATE-LEFT Test Cases: > (rotate-left '(a b c)) (B C A) > (rotate-left '(abc)) (ABC) > (rotate-left '()) (NIL) > (rotate-left '(123 abc '%[email protected])) (ABC (QUOTE %[email protected]) 123) > (dribble)
3.4 T > ;;;;;;;;; ;;;;Problem Statement: To define a function that shifts the elements in the list by one place towards the right side

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern