# Can Computers Think?Introduction to Computer Science

## CSC 106Union CollegeWinter 2010

### In class exercises for Thursday, 2/18

#### Purpose:

• Practice working with recursion.

#### Problem 1: A turtle spiral

Write a recursive function that makes the turtle draw a square spiral shape. For example like this:

The function should take a number as its parameter that indicates how many layers the spiral should have. For example, spiral(1) should produce this image spiral(2) should produce this image and spiral(7) should produce this image

#### Problem 2: The Koch snowflake

A Koch curve is a recursive structure that is built as follows:

 Koch curve of degree 0: Koch curve of degree 1: Koch curve of degree 2: Koch curve of degree 3:

You can build a snowflake shape by arranging three Koch curves in a triangle.

##### Step 1: Koch curve

Write a recursive function that draws a Koch curve. The function should take a number as its parameter that indicates the degree of the Koch curve.

##### Step 2: Koch snowflake

Write a function that makes the turtle draw a Koch snowflake. This function should also take one parameter indicating the degree of the three Koch curves. This function should make use of (i.e., call) the function for drawing a Koch curve that you defined in Step 1.