On this page:
1.1 Problem 1
1.2 Problem 2
1.3 Problem 3
8.11

1 Homework 1B

Due:

Thursday, 1/11 at 9PM

This assignment is SOLO, and entirely AUTOGRADED.

What to Download:

hw1b.rkt

Please start with this file, filling in where appropriate, and submit your homework to the HW1B assignment on Gradescope. This page has additional information, and allows us to format things nicely.

1.1 Problem 1

Design a function sum-div-5 that takes a list of numbers and produces the sum of only those numbers that are divisible by 5.

It should pass the following tests:

 (check-expect (sum-div-5 (list 1 3 5 7 9 10)) 15) 
 (check-expect (sum-div-5 (list 1 2 3 4 5)) 5) 
 (check-expect (sum-div-5 (list -5 2 3 4 5)) 0)

1.2 Problem 2

Consider the following data definition:

 (define-struct wire (length size leads-to)) 
 (define-struct junction (wires)) 
 (define-struct end ()) 
  
 ;; A Circuit is one of: 
 ;; - (make-wire Natural Natural Circuit) 
 ;; - (make-junction (ListOf Circuit)) 
 ;; - (make-end) 
 ;; Interpretation: a part of a residential electric circuit, where wires have a length 
 ;; and size in natural numbers (integers >= 0). 
 ;; Examples: 
 (define W1 (make-wire 10 2 (make-end))) 
 (define W2 (make-wire 5 1 (make-end))) 
 (define J1 (make-junction (list W1 W1 W2))) 
 (define J2 (make-junction (list W2 (make-junction (list W2)) W2)))

Which captures (a limited view of) basic residential electrical circuits which have wires corrected to either other wires or to junctions that join multiple wires.

Copper is expensive, and you want to design a function that, given a Circuit, returns the total cost of the circuit. Your function, circuit-cost, should take as input a Circuit and a cost of copper in wire volume (calculated by length multiplied by size) and return the total cost of all Wires in the Circuit.

It should pass the following tests:

 (check-expect (circuit-cost W1 5) 100) 
 (check-expect (circuit-cost J1 5) 225) 
 (check-expect (circuit-cost J2 10) 150)

1.3 Problem 3

Consider the following data definition:

 (define-struct book (author title pages)) 
  
 ;; A Book is a (make-book String String Natural) 
 ;; Interpretation: a book with an author, title, and number of pages 
 ;; Examples: 
 (define B1 (make-book "Felleisen" "How to Design Programs" 765)) 
 (define B2 (make-book "MacKenzie" "Mechanizing Proof" 427)) 
 (define B3 (make-book "Pierce" "Types and Programming Languages" 623))

Which represents books, as might appear in a library. Your task is to design a function that, given a list of books, returns the authors of all those over 600 pages long.

It should pass the following tests:

 (check-expect (wordy-authors (list B1 B2 B3)) (list "Felleisen" "Pierce")) 
 (check-expect (wordy-authors (list B2)) (list))