0% found this document useful (0 votes)
3 views

Assignment

The document outlines a practice assignment for an Introduction to Computer Science course at the German University in Cairo, focusing on various logic and programming exercises. It includes problems such as navigating between a City of Lies and a City of Truth, solving the Towers of Hanoi puzzle, and addressing fruit crate labeling challenges. Additional exercises involve logic puzzles related to racing, transporting items across a river, and balancing weights.

Uploaded by

yusuf tarek
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Assignment

The document outlines a practice assignment for an Introduction to Computer Science course at the German University in Cairo, focusing on various logic and programming exercises. It includes problems such as navigating between a City of Lies and a City of Truth, solving the Towers of Hanoi puzzle, and addressing fruit crate labeling challenges. Additional exercises involve logic puzzles related to racing, transporting items across a river, and balancing weights.

Uploaded by

yusuf tarek
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

German University in Cairo

Media Engineering and Technology Faculty


Prof. Dr. Slim Abdennadher
Assoc. Prof. Milad Ghantous
Dr. Nourhan Ehab

Introduction to Computer Science, Winter Semester 2023-2024


Practice Assignment 1

To be discussed in Tutorials:

Exercise 1-1 City of Lies & Truth


You are at an unmarked intersection ... one way is the City of Lies and another way is the City
of Truth.
Citizens of the City of Lies always lie.
Citizens of the City of Truth always tell the truth.
A citizen of one of those cities (you don’t know which) is at the intersection. What question could
you ask to them to find the way to the City of Truth?

Exercise 1-2 Play Game


Sometimes when you are coding in groups, someone will make an error that will affect everyone.
Somebody has already written programs for the images below, but each one has a mistake! Figure
out what the programs are supposed to look like, and circle the error in each one. Then, draw the
correct symbol in the box beneath.

1
Figure 1: Instructions for drawing

Exercise 1-3 Towers of Hanoi


The Towers of Hanoi is a mathematical puzzle invented by a mathematician in 1883. The puzzle
setting consists of eight disks and three pegs. Disks can slide onto the pegs. Initially, the disks are
neatly stacked in order of their sizes on one peg so that they form a conical shape. The objective
of the puzzle is to move the disks from one peg to another using only the three pegs. The following
rules have to be obeyed during the moves:

• The same order of the pegs has to be maintained after moving them.
• Only one disk has to be moved at a time.
• No large disk can be placed on a smaller one.

A simple version of the towers of Hanoi consists of three disks instead of eight. In plain simple
English write a set of steps by which you can move the three disks from one peg to the other.
https://www.mathsisfun.com/games/towerofhanoi.html

Exercise 1-4 Cut Block


Cut Block puzzles were devised by Japanese puzzle inventor Naoki Inaba.
There are two rules that must hold of a completed cut block puzzle.

• Each area marked out by darker lines must contain the numbers from 1 up to the number
of squares in the area. For example, the top most area in the first puzzle below consists of 5
squares so those squares must be filled with the numbers: 1, 2, 3, 4 and 5 with no repeated
numbers. If the area has two squares, like the one bottom left below, then it must be filled
with the numbers 1 and 2.
• No number can be next to the same number in any direction, whether horizontally, vertically
or diagonally. So in the grid below, the fact that there is a 4 on the side means there cannot
be a 4 in any of the 5 squares surrounding it.

2
Figure 2: Cut Block

Exercise 1-5 Balance puzzle


The Balance puzzle is a logic puzzle that is based on balancing similar-looking items. A well-
known example has 8 balls that are identical in weight except for one odd ball. The objective of
the puzzle is to find the different ball using the least number of weighings.

a) Start by trying to find the smallest the number of weighings for 4 balls, knowing that the
odd ball is heavier than the rest. What could be the number weighings for 8 balls?.
b) What will happen if you know that the odd ball is just different i.e could be heavier or
lighter?
What could be the number weighings for 4 balls? Can you do it for 6, what about 8, what
about 13?

To be solved in Labs:

https://studio.code.org/hoc/1

https://hoc.nclab.com/karel/

Extra Exercises:

Exercise 1-6 Crates of Fruit


You work at a fruit factory.

There are 3 crates in front of you. One crate contains only apples. One crate contains only oranges.
The other crate contains both apples and oranges. And each crate is labeled. One reads "apples",
one reads "oranges", and one reads "apples and oranges".

3
But the labeling machine has gone crazy and is now labeling all boxes incorrectly.

If you can only take out and look at just one of the pieces of fruit from just one of the crates, how
can you label ALL of the crates correctly?

Exercise 1-7 Race


Andrew, Britney and Carol race each other in a 100meter race. Each of them run at a constant
speed throughout the race.
Andrew beats Britney by 20 meters.
Britney beats Carol by 20 meters.

By how many meters does Andrew beat Carol?

Exercise 1-8 A Trip to the Market


A farmer is on her way to the local village with her sheepdog, Mist, who goes with her everywhere.
To get to the village she has to cross a fast flowing river. An inventor living on the village side
of the river has created a contraption to make it easier to get across. It consists of a rope and
pulleys, with a seat hanging from the rope just big enough for one person. The locals have agreed
to always leave the seat at the village side where the inventor lives so that it is easy for her to pack
it away each evening: after all she is not charging anyone to use it. When she gets to the river the
farmer pulls the seat across from the far side using the rope. She gets in, hugging Mist, then pulls
herself across and continues into the village.

On one particular day she buys a new hen and a sack of corn. Returning home later in the day she
arrives back at the ravine, and quickly realises she has a problem. She can only carry one thing
across with her as she crosses using the seat. She will have to make several trips. The trouble is,
if she leaves the hen and the corn alone on either side, the hen will eat the corn. Similarly if she
leaves Mist and the hen together on one side the dog will worry the hen and may mean it stops
laying eggs. Mist doesn’t eat corn so it will come to no harm if left with him.

Write down the series of steps that she must take to get everything across so she can continue on
her way.

You might also like