#lang racket ; the above line tells Racket to use the standard language subset ; CS 42 Homework 1, Problem 3 ; Author(s): [your name here] ; Time spent: [enter the time spent on this homework here] ; You should ALWAYS include the above information. ; Additional comments (optional): ; ; You may add your definitions to this file and load it as Racket code. ; When run as is, many tests will fail. By replacing the definitions ; with correct ones, you should get more tests succeeding, and eventually ; all tests should succeed. ; You should use this file as a template for your hw1pr4.rkt file and for ; all future Racket files. (require htdp/testing) ; this enables the unit-testing interface. ; (generate-report) ;; this command (when uncommented) outputs the test ;; results so far. Generally, you only want one ;; call to generate-report, at the very end. ; Right now, we provide at least one unit test for every function. You should add ; more of your own, to check yourself. You should leave your unit tests in ; the submitted file. We will be using some unit tests that you haven't seen ; yet in evaluating your solutions, and we may evaulate your unit tests. ; ; You do not have to worry about checking for malformed input. We will not be ; using any test cases such as that. ; ; You should pay attention to elegance, readability, and comments where needed. ; Formatting should be straightforward if you use Dr. Racket, since it indents ; for you. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; All answers MUST be done using functional programming. Do not use assignment!; ; Do not use conventional iteration. It isn't needed. ; ; The emphasis here is on constructing and composing functions. Non-compliant ; ; solutions will be counted as wrong. If you don't know how to approach a ; ; problem in the prescribed way, please seek help at your earliest opportunity.; ; ; ; Include comments and use meaningful identifiers where possible. ; ; Make your solutions elegant and clear as possible. ; ; We are interested in style, rather than simply answers. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Problem 3.1 ; ; Function: erdos ; Input: ; N - a non-negative integer ; Output: ; Computes the Erdos number of the input: 3N+1 if N is odd; N/2 if N is even (define (erdos N) 0) ;; Replace with the correct definition ; Unit tests for erdos ; EXPRESSION EXPECTED RESULT (check-expect (erdos 3) 10) (check-expect (erdos 10) 5) ; Problem 3.2 ; Function: erdosCount ; Input: ; N - a non-negative integer ; Output: ; The smallest number of times erdos must be iterated, when started with an ; input of N, in order to arrive at a value of 1 (define (erdosCount N) 0) ;; Replace with the correct definition (check-expect (erdosCount 26) 10) (check-expect (erdosCount 27) 111) ; Problem 3.3 ; ; Function: removeAll ; Input: ; e - an element ; L - a list ; Output: ; A list that is identical to L except with top-level instances of e removed. (define (removeAll e L) '()) ;; Replace with the correct definition (check-expect (removeAll "i" '("a" "l" "i" "i" "i" "e" "n")) '("a" "l" "e" "n")) (check-expect (removeAll "i" '( ("a" "l" "i") "i" "i" "e" "n" )) '(("a" "l" "i") "e" "n")) (check-expect (removeAll 0 '(1 0 1 0 1 0)) '(1 1 1)) ; Problem 3.4 ; ; Function: find ; Input: ; L - A list ; M - A list that may or may not contain L as a sublist ; Output: ; #t if L is a sublist of M, #f otherwise (define (find L M) #f) (check-expect (find '(1 2 3) '(0 1 2 3 4)) #t) (check-expect (find '(1 2 3) '(0 1 2 2 3 4)) #f) ; And a few more (check-expect (find '() '(1 2 3)) #t) (check-expect (find '(1) '()) #f) (check-expect (find '(1 2) '(2 1 1 1)) #f) (check-expect (find '(1 2) '(2 1 1 (1 2))) #f) ;; an element is not a sub-list (check-expect (find '(1 1 3) '(2 1 1 2 3 1)) #f) ; The following will give the overall number of tests correct and incorrect. (generate-report)