EEL5840 AI

# EEL5840 AI - Tarak Trivedi ECE Dept Fall 09 UFID 51837169 EEL-5840 Elements of Machine Intelligence Fall 2009 Homework 2 Programming Assignment 3.1

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 '%\$\$@)) (ABC (QUOTE %\$\$@) 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.

## This note was uploaded on 09/17/2009 for the course EEL 5840 taught by Professor Arroyo during the Fall '08 term at University of Florida.

### Page1 / 9

EEL5840 AI - Tarak Trivedi ECE Dept Fall 09 UFID 51837169 EEL-5840 Elements of Machine Intelligence Fall 2009 Homework 2 Programming Assignment 3.1

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online