Exercises 4 β
These exercises focuses on using tuples and optionals.
As with the previous exercises, whenever youβre asked to declare a function, itβs up to you to choose appropriate parameters, argument labels, and return values. Also, include at least one function call with every function you declare, to show that you know how to call the function.
Exercise 4.1 β
Note
This exercise builds on Exercise 1.7.
Declare a function to calculate the integer quotient and floating-point remainder of a division of two floating-point numbers.
Exercise 4.2 β
Note
This exercise builds on Exercise 1.9.
Declare Point
as a type alias for a tuple that represents a two-dimensional point.
Next, declare a function to calculate the distance between two points.
Exercise 4.3 β
Note
This exercise builds on Exercise 2.2.
Declare a function that, given the coefficients
Exercise 4.4 β
Note
This exercise builds on Exercise 2.1.
Declare Position
as a type alias for a pair of coordinates on a chessboard.
Next, declare a function that, given a position on a chessboard, calculates the next position. Unlike Exercise 2.1, this function should not wrap from (7, 7) to (0, 0). Instead, consider (7, 7) as the last position.
Exercise 4.5 β
A caller of the previous function may decide to wrap from (7, 7) to (0, 0) anyway. Show how you can achieve this without modifying the function.