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

Info iconThis 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)
Background image of page 1

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

View Full DocumentRight 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 '%$$@)) (ABC (QUOTE %$$@) 123) > (dribble)
Background 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
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
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 Right Arrow Icon
Ask a homework question - tutors are online