Work 06: 9/24

posted Sep 24, 2018, 12:23 PM by JonAlf Dyrland-Weaver
Define the following functions in racket:
  • isBetween
    • Takes 3 numbers as arguments (let's call them a, b and c)
    • Returns:
      • #true if b is greater than a and b is less than c ( a < b < c)
      • #false in all other cases
    • Examples:
      • (isBetween 4 5 6) ==> #true
      • (isBetween 3 9 7) ==> #false
      • (isBetween 4 4 9) ==> #false
  • pythTriple
    • Takes 3 numbers as arguments (let's call them a, b and c)
    • Returns:
      • #true if the three parameters could be the sides of a right triangle, with the last parameter being the hypotenuse
      • #false in all other cases
    • examples:
      • (pythTriple 3 4 5) ==> #true
      • (pythTriple 6 7 10) ==> #false
      • (pythTriple 4  3 5) ==> #true
      • (pythTriple 5 3 4) ==> #false
  • pythTriple2
    • Takes 3 numbers as parameters (let's call them a, b and c)
    • Returns:
      • #true if the three parameters could be the sides of a right triangle, where any of the sides could be the hypotenuse
      • #false in all other cases
    • examples:
      • (pythTriple2 3 4 5) ==> #true
      • (pythTriple2 6 7 10) ==> #false
      • (pythTriple2 4  3 5) ==> #true
      • (pythTriple2 5 3 4) ==> #true
      • (pythTriple2 4 5 3) ==> #true
  • xor
    • This is known as the exclusive or operator
    • Takes 2 boolean values as parameters
    • Returns:
      • #true if exactly one of the 2 parameters is true
      • #false in all other cases
    • Examples:
      • (xor #true #true) ==> #false
      • (xor #true #false) ==> #true
      • (xor #false #true) ==> #true
      • (xor #false #false) ==> #false
      • (xor (> 3 4) (<= 5 6)) ==> #true
  • Challenge Question
    • xor3
      • Takes 3 boolean values as parameters
      • Returns
        • #true if exactly one of the 3 parameters is true
        • #false in all other cases
Submit this as booleans
Comments