a1q2 - true true)(list empty))) ; => (list (list...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-reader.ss" "lang")((modname a1q2) (read-case- sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) ;; CS 116 ;; r46wang Ru Wang 20319247 ;; Assignment 1 Question 2 ;; at-least-one-true: (listof list) -> (listof list)[contains at least one true value] ;; purpose: to create a list of lists that contains one or more "true" values and eliminate empty or "false"-valued lists. ;; examples: ;;(at-least-one-true (list (list false)(list false false)(list false false false))) => empty ;;(at-least-one-true (list (list empty)(list empty))) => empty ;;(at-least-one-true (list (list true)(list false true)(list false false true))) ; => (list (list true) (list false true) (list false false true)) ;;(at-least-one-true (list (list false false false)(list false false true)(list
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: true true)(list empty))) ; => (list (list false false true) (list true true)) ;; true-exists?: (listof boolean) -> boolean ;; returns true if there contains a "true" within the list of boolean inputted, else returns false. (define (at-least-one-true lst) (local [(define (true-exist? l) (cond [(empty? l) false] [else (or (first l)(true-exist? (rest l)))]))] (filter true-exist? lst))) ;;tests: (check-expect (at-least-one-true (list (list false)(list false false)(list false false false))) empty) (check-expect (at-least-one-true (list empty empty)) empty) (check-expect (at-least-one-true (list (list true)(list false true)(list false false true))) (list (list true) (list false true) (list false false true))) (check-expect (at-least-one-true (list (list false false false)(list false false true)(list true true) empty)) (list (list false false true) (list true true)))...
View Full Document

Ask a homework question - tutors are online