Pseudocode practice quiz

Just learning to code? Is the language getting in your way? Give this pseudocode practice quiz a shot and see how well you think algorithmically.

What is output from the following code?

a = 2
loop while a < 10
   print a + " "
   a = a + 2

What is output from the following code?

x = 15
if x > 15 
   print "go"
if x < 20 
   print "stop"

What is output from the following code?

x = 10
loop while x > 85
   x = x - 5
print x

What is output from the following code?

x = 20
loop while x > 10
   x = x - 4
print x

What is output from the following code?

x = 10
sum = 0
loop while x > 3
   sum = sum + x
   x = x - 2
print sum

Question 1 of 5

Find nth Occurrence

Find nth Occurrence

This problem comes from a given, but unimplemented, method from the 2017 AP Computer Science exam called Phrase.

In one part you were tasked with replacing the \(n^{th}\) occurrence of one string within another string. And they gave you a method findNthOccurrence to help you out.

But the implementation for findNthOccurrence was not shown. So for this coding challenge, that's you job.

As an example, the call findNthOccurrence( "dogdogdogdog", "dog", 2 ) should return 3 because the 2nd "dog" starts at index 3. findNthOccurrence( "dogdogdogdog", "dog", 3 ) would return 6.

If find does not occur in str the method should return -1. Likewise if there is no \(n^{th}\) occurrence the method should also return -1.

findNthOccurrence("dogdogdogdog", "dog", 1) => 0
findNthOccurrence("dogcatdogdodgdogddd", "dog", 3) => 13
findNthOccurrence("dogdogdog", "dag", 1) => -1
findNthOccurrence("catcatcat", "dog", 3) => -1
findNthOccurrence("fishchickendogcatplatypus", "chicken", 5) => -1

Why Write Code on Paper?

Why Write Code on Paper?
School is about to start up for students all over the United States. And for those that are taking a computer science course for the first time, they’ll learn that it’s not always just typing code into a computer. So why do we write code on paper?

Many teachers and professors have their students write at least some of their code on paper, and then it’s hand graded rather than run through a compiler.

But why? For students this seems like a very odd thing. They’re learning to program a computer, but not using a computer.

Let’s take a step over to the other side and look at why this can be a good way to learn programming. Continue reading