8.14

Homework 1b🔗

home work!

Programming Language #lang htdp/bsl

Due Date Thu at 9:00pm (Week 1)

Purpose To practice basic writing basic functions & tests.

MAKE SURE YOU INCLUDE TESTS FOR ALL OF YOUR FUNCTIONS.

Submit all of the following in a single .rkt file to Handins. You will get (nearly-)immediate feedback and can resubmit multiple times before the deadlne.

Exercises

Exercise 1 Define a function dist that consumes three numbers, x, y and z, and that computes the Euclidean distance of point (x,y,z) to the origin.

Exercise 2 Define iff. The function consumes two Boolean values, call them sunny and beach. Its answer is #true if sunny and beach are both true or both false, and #false otherwise. This Boolean operation, short for if and only if, is an equivalence, and logicians often use the notation happy <=> outside for this purpose.

Exercise 3 Different video formats have different shapes: TV, movies, TikTok videos, etc. all have different ratios of their width to their height, called aspect ratios. The most common aspect ratios are
  • Square: a width-to-height ratio of exactly 1:1

  • Fullscreen: a width-to-height ratio of up to 4:3

  • Widescreen: a width-to-height ratio of up to 16:9

  • Portrait: a width-to-height ratio of anything less than 1:1

Define the function image-classify, which consumes an image and conditionally produces "square", "fullscreen", "widescreen" or "portrait" according to the ratios above, and "too wide" otherwise.

Exercise 4 Define the function image-area, which counts the number of pixels in a given image.