Docsity

Programming Fundamentals Lab: Chessboard, Beans, and Trust - Prof. niazi, Summaries of Computer Science

Toggle sidebar
bg1
BS (CS) 1st Semester Lab- 01 Fall 2023
Programming Fundamentals Lab
Lab-01 (16-10-2023)
Task 1:
If you were to construct a 8 x 8 chessboard, how many squares (within that chess board) would
be there? (Hint: 64 is not the answer).
Task 2:
A pot contains 75 white beans and 150 black beans. Next to the pot is a large pile of black beans.
A somewhat crazy cook removes the beans from the pot, one at a time, according to the
following strange rules:
Rule 1: He removes two beans from the pot at random. If at least one of the beans is black, he
places it on the bean-pile and drops the other bean, no matter which color, back in the pot.
Rule 2: If both beans are white, on the other hand, he discards both of them and removes one
black bean from the pile and drops it in the pot.
At each turn of this procedure, the pot has one less bean in it. Eventually, just one bean is left in
the pot. Which color is it?
Task 3:
You wake up after your Titanic sank, and find yourself on the bank of the sea, in an island.
Beside everything, what an island has (its natural beauty), there are people on island too. You
come to know that the people of this island are either liar (he may or may not lie) or trustworthy
(always speak the truth). You can ask them questions like who is a liar and who is not? There are
total 100 people in this island. You may ask as many questions as you want. The only
information known is, that number of trustworthy people is greater than liars. Any answer having
greater than 500 questions is not worthy enough to be considered. Figure out who is a liar and
who is a trustworthy person?
Note 1: You need to write the basic algorithmic solution (theoretically or mathematically) of
each of the question.
Note 2: You need to complete these tasks in the lab timings and submit it on a page (Hand
written) in the group of 3 people.

Partial preview of the text

Download Programming Fundamentals Lab: Chessboard, Beans, and Trust - Prof. niazi and more Summaries Computer Science in PDF only on Docsity!

BS (CS) 1st^ Semester Lab- 01 Fall 2023

Programming Fundamentals Lab

Lab-01 (16-10-2023)

Task 1:

If you were to construct a 8 x 8 chessboard, how many squares (within that chess board) would be there? (Hint: 64 is not the answer).

Task 2:

A pot contains 75 white beans and 150 black beans. Next to the pot is a large pile of black beans. A somewhat crazy cook removes the beans from the pot, one at a time, according to the following strange rules: Rule 1: He removes two beans from the pot at random. If at least one of the beans is black, he places it on the bean-pile and drops the other bean, no matter which color, back in the pot. Rule 2: If both beans are white, on the other hand, he discards both of them and removes one black bean from the pile and drops it in the pot. At each turn of this procedure, the pot has one less bean in it. Eventually, just one bean is left in the pot. Which color is it?

Task 3:

You wake up after your Titanic sank, and find yourself on the bank of the sea, in an island. Beside everything, what an island has (its natural beauty), there are people on island too. You come to know that the people of this island are either liar (he may or may not lie) or trustworthy (always speak the truth). You can ask them questions like who is a liar and who is not? There are total 100 people in this island. You may ask as many questions as you want. The only information known is, that number of trustworthy people is greater than liars. Any answer having greater than 500 questions is not worthy enough to be considered. Figure out who is a liar and who is a trustworthy person? Note 1: You need to write the basic algorithmic solution (theoretically or mathematically) of each of the question. Note 2: You need to complete these tasks in the lab timings and submit it on a page (Hand written) in the group of 3 people.