rooms of a house
Posted: Sat May 12, 2012 2:22 pm
I'm working on my first ever assignment dealing with Lisp. My function deals with 9 rooms of a house. 1.Library 2. Upstairs-bedroom 3. back-stairs 4. front-stairs 5. downstairs-bedroom 6. living-room 7.dining-room 8. kitchen 9.pantry
-The input is a room and the output is the number of direct rooms you can go from that room. The living room and Dining room's output is 3, the rest is 2.
-I tried 2 approaches to this, but not very successful. Could someone tell me what I'm doing wrong or the more efficient way of doing this?
Approach #1:
> (defun how-many-choices (loc)
(setq library 2)
(setq back-stairs 2)
(setq downstairs-bedroom 2)
(setq upstairs-bedroom 2)
(setq front-stairs 2)
(setq living-room 3)
(setq dining-room 3)
(setq kitchen 2)
(setq pantry 2))
HOW-MANY-CHOICES
> (how-many-choices 'back-stairs)
2
> (how-many-choices 'living-room)
2
>
--The living-room's output should be 3, not 2
Approach #2:
(defun how-many-choices (loc)
(if(eql loc 'living-room 'dining-room)
3
(= loc 2)))
HOW-MANY-CHOICES
> (how-many-choices 'library)
error: too many arguments
>
-The input is a room and the output is the number of direct rooms you can go from that room. The living room and Dining room's output is 3, the rest is 2.
-I tried 2 approaches to this, but not very successful. Could someone tell me what I'm doing wrong or the more efficient way of doing this?
Approach #1:
> (defun how-many-choices (loc)
(setq library 2)
(setq back-stairs 2)
(setq downstairs-bedroom 2)
(setq upstairs-bedroom 2)
(setq front-stairs 2)
(setq living-room 3)
(setq dining-room 3)
(setq kitchen 2)
(setq pantry 2))
HOW-MANY-CHOICES
> (how-many-choices 'back-stairs)
2
> (how-many-choices 'living-room)
2
>
--The living-room's output should be 3, not 2
Approach #2:
(defun how-many-choices (loc)
(if(eql loc 'living-room 'dining-room)
3
(= loc 2)))
HOW-MANY-CHOICES
> (how-many-choices 'library)
error: too many arguments
>