Practice with Pseudo-coding

A chance to use pseudocode to describe common procedures and to solve a logical challenge.

Scroll down...

Content

Resources

Comments

You've just learned how to use pseudocode to write down a procedure and some of the core logical constructs of coding itself. In this brief exercise, it's time to stretch out a bit and apply pseudocoding techniques to a couple of common tasks and then a logical problem.

The goal is to get you thinking procedurally about about the world in general and then become comfortable expressing them in code. The final problem will present you with a challenge which you'll need to "solve" by writing it out as a procedure and it represents the kind of thinking that interviewers like to test you on.

Mmmm... Grilled Cheese

Just to get in the right frame of mind, we'll start with a classic pseudocoding exercise -- writing a recipe. In this case, break out the recipe for making grilled cheese into discrete steps. It may seem simple but it should be at least 20-30 steps and include things like setting things up and checking if it's done. We'll start you off:

PROGRAM GrilledCheeseSandwich
# Your (pseudo)code here
END

Shopping for Ingredients

Let's go shopping! You've got a list in hand with a variable number of things that need to be procured from the grocery store. The store is laid out into 10 aisles but their signs have all been taken down for repairs so you're not sure which aisles contain which foods.

Write a program which will acquire and then check out with all your items. Start with very broad strokes and then get more specific until you're comfortable with the level of detail. This will probably require more than 50 steps.

PROGRAM GroceryShopping
# Your (pseudo)code here
END

A Logic Game

10 friends are sitting in a circle around a table and decide to play a new game. In it, they count up through the numbers from 1 to 100. The first person says "1", the second says "2" and so on... but with a few catches:

Whenever the number is divisible by 7, they switch directions. So person 6 will say "6", person 7 will say "7", then person 6 again will say "8".

Whenever the number is divisible by 11, they skip the next person.

Your job is to pseudocode a program which will determine which player says the number 100. For this one, be as specific as possible to actually write out the logic of the procedure.

PROGRAM CounterGame
# Your (pseudo)code here
END

Once you've finished your procedure, be sure to walk through the logic and make sure it is actually doing what it's supposed to.

The key here isn't to actually come up with the answer to the problem posed -- you should see how trivial that would be if you actually wrote this using code. The real difficulty is making sure that you've set up the problem properly in the first place.