{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
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)
Image of page 1

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

View Full Document Right Arrow Icon
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)
Image of page 2
3.4 T > ;;;;;;;;; ;;;;Problem Statement: To define a function that shifts the elements in the list by one place towards the right side
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern