Computer Science

# Computer Science Warmups: Level 2 Challenges

Tony wants to print out the full lyrics to the song "99 Bottles of Beer on the Wall," so he's written the code below. The song is supposed to involve taking down each of the 99 bottles in turn and passing them around until all the bottles have been taken down and passed around.

 1 2 3 4 5 6 7 8 9 number = 99 while number > 1: # each loop prints one verse of the song print number + " bottles of beer on the wall." print number + " bottles of beer on the wall." print "Take one down; pass it around." number = number - 1 print number + " bottles of beer on the wall." print " " 

What is wrong with his lyrics?

###### Image Credit: Darien Graham-Smith

Your friend has written a program to check whether or not a number $n$ is prime. It is very simple and works by checking if $n$ is divisible by each number from 2 all the way to $n-1$. When you see this, you curse your friend and tell him he's wasting time.

If your friend didn't want to waste time, what is (approximately) the biggest number that he needs to check before he can determine that any number $n$ is prime?

Sandip, Tracy, Jamal, and Sheng are best friends who work together everyday at a banana stand. Since they are so close, their happiness on any given day depends on the happiness of the other three people on the previous day. Suppose they behave as follows:

• Sheng is happy today only if Tracy and Jamal were both happy yesterday.
• Jamal is happy today only if Sandip or Sheng (or both) were happy yesterday.
• Sandip enjoys watching Sheng cry, so Sandip is happy today only if Sheng was sad yesterday.
• Tracy is happy today only if Tracy was happy yesterday, meaning she has an independent streak.

Suppose that on day 1, all four of the friends are sad. After a few days, the friends reach a stable emotional state that repeats itself. What is the emotional state of each person in this repeating state?

Alice wants to send Bob a large file.

She is also worried about the security of the network. So, she needs to encrypt it.

Should she compress the data and then encrypt? Or should she encrypt the data and then compress? Or does it not matter?

Find the first 10-digit prime number that is found in consecutive digits of $e$.

Background: The tech giant Google is known to have s​etup such billboards in the heart of Silicon Valley, and later in Cambridge, Massachusetts; Seattle, Washington; and Austin, Texas. It read

"{first 10-digit prime found in consecutive digits of e}.com".

Solving this problem and visiting the website led to an even more difficult problem to solve, which in turn led to Google Labs where the visitor was invited to submit a resume. Unfortunately, that website has been taken down.

×