#lang planet wrturtle/pyret/bsl # Exercises in chapter 2 of HtDP, written in pyret/bsl # Exercise 1 def x: 8 def y: 36 # Create an expression that computes the distance between x and y sqrt(x * x + y * y) # Exercise 2 def prefix: "hello" def suffix: "world" # Create an expression that adds "_" between prefix and suffix prefix + "_" + suffix # Exercise 3 def str: "helloworld" def i: 5 # Create an expression that adds "_" at the ith position of str substring(str, 0, i) + "_" + substring(str, i, len(str)) # Exercise 4 # Same setup as ex 3, but this time, /remove/ the letter at position i substring(str, 0, i) + substring(str, i+1, len(str)) # See `chapter2-images.rkt` for the exercises involving images. # Exercise 9 def b1: True def b2: False # Create an expression tfhat determines whether b1 is False or b2 is True b1 = False or b2 = True