Assignment 1, CSC430, Winter 2016
1 Guidelines
1.1 Captain Teach
2 Assignment
2.1 Some Textbook Problems
2.2 Magic Tricks
2.3 Low-degree Polynomials
2.4 Derivative
2.5 Binary Tree
2.6 Min-Depth
2.7 Traversal
6.4.0.8

Assignment 1, CSC430, Winter 2016

1 Guidelines

For this and all remaining assignments, every function you develop must come with the following things:

For this assignment, you must develop your solutions using the ’plai-typed’ language. Your test cases must use the (test ...) form.

Your solution should take the form of a single file. Solve each problem separately, ands make sure that each solution appears in a separate part of the file, with comments separating each problem’s solution.

Hand in your solution using the handin server. For help with the handin server, please see the course web page.

1.1 Captain Teach

By Monday, January 11 (11 pm), you’ll need to submit your solution to Problem 3.3.3 to Captain Teach.

Here’s the URL:

https://www.captainteach.org/2162-cpe430/

I apologize in advance for requiring you to have a Google account to use the tool. Let me know if that’s a problem.

I’ll be giving you more details about this submission as the time approaches.

2 Assignment

2.1 Some Textbook Problems

Solve the following two problems from the textbook How To Design Programs, available online at www.htdp.org:

  1. Problem 2.3.3

  2. Problem 3.3.3

2.2 Magic Tricks

Here is a data definition for magic tricks:

; Represent a magic trick
(define-type Trick
  [card-trick (decks : number) (volunteers : number)]
  [guillotine (realism : number) (has-blood? : boolean)])

Develop the function trick-minutes, that computes how long a trick will take. Assume that a card trick requires one minute per deck of cards and that its length is doubled for every volunteer required, and that a guillotine trick requires ten minutes unless it has blood, in which case it requires 20.

2.3 Low-degree Polynomials

Develop a data definition for a polynomial (with type name Polynomial) that includes variants for linear (Ax + B) and quadratic (Ax^2 + Bx + C) polynomials of one variable. Call the variants linear and quadratic; each should accept the coefficients in the order given here (i.e., A comes first). For the purposes of this and the next problem, you should assume that the first coefficient (A) of a quadratic polynomial is never zero. The first coefficient of a linear polynomial, however, may be zero.

Next, define the function eval that accepts a polynomial and a value for the variable and produces the result of plugging in the value for the variable.

2.4 Derivative

Using the data definition you developed in the last problem, develop the function derivative that accepts a polynomial and returns another polynomial that represents its derivative. Ensure that your derivative function does not return a quadratic polynomial whose first coefficient is zero.

2.5 Binary Tree

Develop a data definition for a binary tree called BTree with symbols at the leaves but no values at the interior nodes. Its variants should be named leaf and node. Include a define-type and at least three examples of the data.

2.6 Min-Depth

Using the BTree data definition, develop the min-depth function that accepts a binary tree and produces the length of the shortest path to a leaf. A single leaf has a min-depth of zero.

2.7 Traversal

using the same data definition, develop the in-order function that accepts a binary tree and produces a list representing an “in-order” traversal of the symbols at the leaves of the binary tree.