|
|
|
CS 404: Journal --- Week 1
There are two problems that you are to solve. The solutions will not be presented in class; they are to be entered into your journal.
- This is a puzzle from What is the Name of this Book? by Raymond Smullyan. It concerns an island in which certain inhabitants called "knights" always tell the truth and others called "knaves" always lie. Every inhabitant is either a knight or a knave. In this one, there are three inhabitants, A, B, and C. Two people are said to be of the same type if they are both knights or both knaves. A and B make the following statements:
 |
A: B is a knave.
|
 |
B: A and C are of the same type.
|
The question is: What is C?
Note that this is different from what I said in class. I had asked that you tell me what A, B, and C are. But you can determine only what C is from the information that I gave you.
- Write a program (in C or Pascal) that performs binary search. That is, given the following variables:
VAR A: ARRAY [0..n] of REAL; (* A is sorted *)
k: REAL; (* A[0] <= k < A[n] *)
i: 0..n-1;
your job is to write a program that sets i to a value such that A[i] <= k < A[i+1]. That is, if k exists in the array, then i will be set to the index of the right-most occurrence. If it isn't in the array, i will be set to the index of where it should be inserted if the array is to be kept sorted.
Due: 20 January 1995.
|