Professor Simonson
How Computers Work
CSC 195
Assignment 6 - 20 points
Recursive Logo Procedures
Due: Midnight, Thursday, March 15
- 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.
- evenlist? :alist - Take a list and output true if it
has all even numbers else output false.
- center :alist - Takes a list and outputs the element in
the center. If the list has an even number of elements it
should output [].
- 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].
- 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).
- intersect :list1 :list2 - Take two lists and output a
list of all the items they have in common. (Hint: Use the Logo
procedure "member?")
- 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.
- smallerthan :item :alist - Takes an item and a list and
returns a new list that contains all the elements smaller than
:item.
- biggerthan :item :alist - Takes an item and a list and
returns a new list that contains all the elements bigger than
:item.
- quicksort :alist - Sorts a list of distinct elements
using the following strategy:
- Create two new lists: one that contains all the
elements smaller than the first element, and one that contains
all the elements larger than the first element. You
should make use of problems 8 and 9 for this part.
- Recursively sort each list.
- Glue the smaller sorted list to the first element to the
sorted larger list.
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