There are three assignments to pick from.

Pick TWO

First one due Nov 25th.

Second one due Dec 1st.

Late penalty 7% per day.

Hamarabi

Rewrite Hamarabi in lisp.

*Start with year = 0, Pop =100, Food = 100, and Garden = 0
*Ask them how much to dedicate to growing food, making babies, or building the garden.
Then
Year=Year+1
*Garden = Garden + PeopleWorkingOnGarden
*Pop = integer(pop * 0.95 + PeopleMaingBabies/2)
*Food = 2 * PeopleMakingFood + 0.5 * Food
*if (Food > Pop)
Food = Food – Pop
Else
Pop = Food
Food = 0

*No input should be negative
*The inputs should not exceed availale resources
*They win if Garden > 100

Hints:
(random 17) returns a number 0 ... 16
(read) returns the number they just typed in
(display "you have killed all your goats") sends a message to the user

This is worth 9 points (one per '*').

-OR-

Association Lists

Make the following functions

I'm fully aware that the web is filled with sample code to do these things. Use of such code is cheating! I shall check.

(define (test)
  (display (set 'a 1 '((a 10) (b 11) (c 12))))
  (newline)
  (display (set 'd 4 '((a 10) (b 11) (c 12))))
  (newline)
  (display (eqv? 10 (get 'age (set 'age 10 '(())))))
  (display (eqv? '() (get 'age '(()))))
  (display (eqv? 10 (get 'age (set 'age 10 '((age 8) (height 6) (weight 3))))))
  (display (eqv? 10 (get 'height (set 'height 10 '((age 8) (height 6) (weight 3))))))
  (display (eqv? 10 (get 'age (set 'age 10 '((width 4) (age 8) (height 6) (weight 3))))))
  (display (eqv? 7 (get 'weight (set 'weight 7 '((age 8) (height 6) (weight 3))))))
  (display (eqv? 'fifth (get 'grade (set 'grade 'fifth '((age 8) (height 6) (weight 3))))))
  (display (eqv? '() (get 'missing (set 'age 10 '((age 8) (height 6) (weight 3))))))
  (display (eqv? 10 (get 'age (set 'age 10 '()))))

  (display '(“Deleting spam from list”))
  (display (delete 'spam '((spam 10))))

  (display '(“Deleting spam from list”))
  (display (delete 'spam '((nospam 10))))

  (display '(“Deleting spam from list”))
  (display (delete 'spam '()))

  (display '(“Deleting spam from list”))
  (display (delete 'spam '((fred 5) (steve 7) (spam 10))))

  (display '(“Deleting spam from list”))
  (display (delete 'spam '((spam 10) (wilma 4) (fred 2) (fry yes))))

  (display '(“Deleting spam from list”))
  (display (delete 'spam '((wilma 10) (spam yes) (fred 2) (fry yes))))

  (display '(“Deleting spam from list”))
  (display (delete 'spam '((nospam 10) (wilma 4) (fred 2) (fry yes))))

)

-OR-



Comparing Lisp and Prolog

Write four of these programs in both Lisp and Prolog. Then write me at least 200 words telling me which you like better and why.

1) Determine if a list is a palindrome. For example '(a b c b a) is and '(a b c b) is not.

2) Delete the last item from a list. You may only traverse the list once, so (reverse (cdr (reverse l)) does not work.

3) Tell if a list is "flat". A flat list has no sublists. Therefore '(a b c) is flat and '(a (b c)) is not flat.

4) Find any solution that is within 0.001 to x^2+3x-10=0 using binary search.

5) Compute sin(x) = x - x^3/3! + x^5/5! - x^7/7! + x^9/9! - x^11/11! ... until the next term is less than 0.000000000001.