# CompSci 18S - Fall 2009 - Logical Thinking

Classwork 6: (10 pts)

Sept. 28, 2009

## PART ONE: Writing logical code

Consider the following problem. There are 8 coins and they are all suppose to weigh the same amount; however, one coin is faulty and is heavier. You have a balanced scale with two sides and want to use the scale to determine which of the coins is faulty. Explain how you do this with the fewest number of weighings. ## PART Two: Writing logical code in Alice

In Alice objects don't have weights, but they do have heights. Suppose you have 3 identical objects to start with and one of them has been made a little bit taller. We want to figure not only which is tallest, but use this information in other methods/functions. 1. First write a function (return type: object) called tooTall that takes in three object parameters. Assume that one of these three objects is taller than the other two. Write code to find the tallest object, and then return the tallest object.

2. Write a method called spinTallest that will spin around the tallest object. The only requirement is that this function takes in the three object parameters. and use the function tooTall to figure out which object to spin around.

3. Write a function (return type: number) called tallestHeight that takes in three object parameters. Assume that one of these three objects is taller than the other two. Write code to find the tallest object, and then return the tallest object's height.

4. Write a method that takes in three object parameters. Call this method setAllSame. The method setAllSame resizes all the other objects to be the same as the tallest object. (Hint: the resize ratio, a.k.a. the ratio of the tallest object to the other objects, is equal to [the tallest height] / [object's height]).

## PART THREE: Boolean Conditions Game

Play a game using the decks of white and colored cards. Each white card has an English sentence that is either true or false. Each colored card has one of three logical operators: AND, OR or NOT.

The game is played as follows.

1. Each player starts with 6 cards, 3 white and 3 colored.
2. When it is your turn, if you can make a logical formula that evaluates to true using at least 4 of your cards, put down the formula and draw new cards. Otherwise, trade in one of your cards for a card of the same color.
3. The first person to put down at least 12 cards wins.