Professor Simonson

How Computers Work

CSC 195

Assignment 6 -  20 points

Recursive Logo Procedures

Due:  Midnight, Thursday, March 16 (Summer - Week 3 - Monday)



  1. double :alist - Take a list of numbers and output the numbers in a new list where each number is twice as large as it was.

  2.  
  3. evenlist? :alist - Take a list and output true if it has all even numbers else output false.

  4.  
  5. center :alist - Takes a list and outputs the element in the center.  If the list has an even number of elements it should output [].

  6.  
  7. lastn :n :alist - Take a list and a number n and output the last n items in the list.  If the list has fewer than n items, the whole list should be output. For example, lastn 3 [ A B C D E F G] should output [E F G].  And, lastn 3 [A B] should output [A B].

  8.  
  9. screendigits :alist - Take a list and output a list of all items that are NOT numbers (Hint:  Use a built in Logo command number? to check whether something is a number or not).

  10.  
  11. intersect :list1 :list2 - Take two lists and output a list of all the items they have in common. (Hint: Use the Logo procedure "member?")

  12.  
  13. alldelete :item :alist - Takes an item and a list, and outputs a new list with all copies of the item removed. If the item is not a member of the list, it simply outputs the list.

  14.  
  15. smallerthan :item :alist - Takes an item and a list and returns a new list that contains all the elements smaller than :item.

  16.  
  17. biggerthan :item :alist - Takes an item and a list and returns a new list that contains all the elements bigger than :item.

  18.  
  19. quicksort :alist - Sorts a list of distinct elements using the following strategy:
       
Note:  Normally, in a recursive method,  Logo keeps track of the values of all parameters at every level of recursion. There is a stack of values for each parameter.  This means that each parameter may have simultaneous multiple values depending on the level of recursion your method is up to.  This is crucial to making recursion work correctly.  However, if you use a statement like make "x.... inside a recursive method,  Logo will assume that this is a global variable and not keep track of a stack of values for "x. In order to make sure Logo keeps track of a stack of values for any variable "x that you create inside your method, you must tell Logo explicitly to do so using a line at the start of your method
    local "x
 

back
 


shai@stonehill.edu

http://www.stonehill.edu/compsci/shai.htm