The bonus problems on this page may be submitted anytime before the last day of classes, Friday, December 10 at 5 PM. Submit these problems by sending an e-mail directly to Ran (hadas@cs.hmc.edu) with your code attached.
0 = 4 + 4 - 4 -4 1 = 44 / 44 2 = (4/4) + (4/4) 3 = 4 - (4/4) - sqrt(4) 4 = .4 * (4 + 4 + sqrt(4))The permitted operations are
_
.4
This number is four ninths, so that you could write eight as
_
8 = sqrt(.4) * (4 + 4 + 4)
although there are more concise ways to write eight with 4's.
You may want to base your solution on the "Game of 24" from Assignment 9, though any approach is OK. This is a very open-ended extra credit -- all solutions are necessarily partial solutions. You should consider solving the problem from 0 to 100 an absolute success.
Martin Gardener (a long-time columnist for Scientific American) claimed that solving it for the integer 113 was impossible, though it's not proven one way or the other! If you do try it, submit your Prolog code in a separate file named bonus.pl. You should name the main predicate as follows:
fours(N,Tree)where N is the number which we would like to express as a combination of four fours, and Tree is a representation of the operations that are part of that combination.
FACTS: 1. There are 5 houses in 5 different colours. 2. In each house lives a person with a different nationality. 3. These 5 owners drink a certain beverage, smoke a certain brand of cigarette and keep a certain pet. 4. No owners have the same pet, brand of cigaratte, or drink. CLUES: 1. The Brit lives in a red house 2. The Swede keeps a dog 3. The Dane drinks tea 4. The green house is on the left of the white house. 5. The green house owner drinks coffee. 6. The person who smokes Pall Mall keeps birds. 7. The owner of the yellow house smokes Dunhill. 8. The man living in the house right in the center drinks milk 9. The Norwegian lives in the first house. 10. The man who smokes Blend lives next to the one who keeps cats 11. The man who keeps horses lives next to the man who smokes Dunhill 12. The owner who smokes Camel drinks beer 13. The German smokes Marlborough. 14. The Norwegian lives next to the blue house 15. The man who smokes Blend has a neighbour who drinks water. The question is, who keeps the fish?
You will need to give some thought to how to do this without taking an inordinate amount of computation time.
In addition, you should have a method int height() which returns the height of the tree. Recall from class that the height of a tree is the length of the longest path from the root to a leaf node, where the leaf nodes are assumed to be "null" nodes. Thus, a tree comprising just a single root node with two null children has height 1. An empty tree is a "null" tree and thus has height 0. Do you see why this height method wasn't specified in the DictionaryADT interface, even though we want to have it implemented in the Btree class?
Make sure that your code is well-structured, clean, and readable. Submit your file Btree.java and any other files which it requires. Notice that Btree.java defines a B-tree and is not executable. However, you should write a thorough tester program to make sure that your class functions correctly. We will test your Btree class using our own tester programs.