More Programming in BlooP and FlooP

Due by class time Friday, March 3

Instructions: Please write out your program definitions on paper and bring them with you to class on Friday. We will go over the solutions together in class. If you wish, you may work with another student on this assignment. Also, if you wish, you may try out your solutions using the BlooP/FlooP interpreter (available on our class web page under Notes).

  1. Write a BlooP program called EVEN? that takes a number N as input and checks if N is even. An even number is one whose remainder is 0 when divided by 2. Your program should output YES if N is even, and NO otherwise. You can use the built-in BlooP operation REMAINDER [A, B] to calculate the remainder of dividing A by B. Here is the basic skeleton to get you started:

    DEFINE PROCEDURE ''EVEN?'' [N]:
    BLOCK 0: BEGIN
       ...
    BLOCK 0: END.
    
  2. The language FlooP is exactly the same as BlooP, but with one added feature: MU-LOOPs. A MU-LOOP (also called a "free loop" or an "unbounded loop") is a loop without a pre-specified upper bound or ceiling on the number of loop cycles that can be executed. MU-LOOPs can be dangerous because they can lead to infinite loops, but they can also be very useful.

    Write a FlooP program called WONDROUS? that takes a number N as input and determines whether it has the "wondrous" property, as described in the Dialogue Aria with Diverse Variations. Your program will need to use a MU-LOOP, since predicting in advance how many steps a number might take to reach 1 is difficult. The syntax of a MU-LOOP looks like this:

    MU-LOOP:
    BLOCK 1: BEGIN
       .....statements.....
       ...to be executed...
       .....repeatedly.....
    BLOCK 1: END;
    

    Since your program tests for a particular property of N (rather than computing a numerical value such as N factorial), it should output either the word YES or the word NO. As a special case, when N is 0, the output should be NO. Your program will also need to make use of the QUOTIENT and REMAINDER operations, which are built into FlooP.