13. Intro Exercises 0
Objectives:
- I can simplify Boolean expressions.
- I know the two key simplifications of
boolean=?.
-
Simplify each as much as possible.
(< 30 50)(string=? "move" "button-down")(<= 30 40 60 50)(image? 100)(string-ci<? "cat" "DOG")(and (>= 50 40) (string<=? "wet" "frog"))(not (string=? "button-down" "drag"))
-
Assume each variable mentioned below has the correct type to be used in the comparisons. Simplify as much as possible.
(and (string=? word "apple") (string=? word "banana"))(and (<= x 100) (>= x 30) (not (= x 120)))
-
What is wrong with the following code? Briefly explain how to fix it.
(= x (or 5 10 15))(boolean=? wet? "true")
-
What’s wrong with the following code? How would you fix it?
(define (bad-apple? fruit) (string=? "rotten apple")) -
This code is not wrong to Racket, but a human will not like it. Why not?
(define name? "Micah") -
Make a “truth table” with columns
cold?(not cold?)and(boolean=? cold? true). Can you see a simpler way to write theboolean=?column? -
Make a “truth table” with columns
cold?(not cold?)and(boolean=? cold? false). Can you see a simpler way to write theboolean=?column? -
Quick, edit this code so it has better programming style. I found four edits.
(define (bad-day raining clothes) (and (string=? "wet" (substring clothes 0 3)) raining)) -
Simplify as much as possible.
(boolean=? legs-hurt? false)(or (boolean=? cross-fit? true) (and (< 0 miles-ran) (>= miles-ran 2.0)))
-
The function
home-early?takes in a booleansbaby-dolphin-day?,family-pickup?, andfast-bus?. You get home early if you get picked up by your family or if it is a baby dolphin day and you ride a fast bus. Write this function.