Introduction Welcome Getting Started My First Program     Troubleshooting and Distributing Transforming Data Interactive Programs     Programming Exercises     Making Games
Documentation Declarations     Procedures     Variables Statements     Flow Control Expressions Libraries     Print     IO     Random     Game Engine
Tutorials Complete Tutorials     Introduction to Programming     Quick Start     Programming Exercises     Programming Games

PROGRAMMING EXERCISES


A complete hub of programming exercises, challenges and ideas;
full of hints and useful links to help you develop your skills





How to Best use this Hub

Welcome, traveller, to this most exotic place.
It contains useful information for people of all skill levels; especially for you.

The next section will help you get into a problem-solving mindset - essential to creating wonderful computer software.

The rest of the page is divided into several sections full of exercises of escalating complexity.
This doesn't necessarily mean you have to complete all of the exercises, or even do them in order. Though it would be beneficial to at least skim the contents of each one and maybe tackle a few exercises before going to the ones you want the most. And if you are having a hard time, just go back a few exercises. You can progress at your own pace, slowing down and redoing exercises that you don't fully understand or skipping the ones you solved easily.

Each exercise contains an explanation of the desired interaction and/or output of the program. They may contain input values for you to test with or different cases, showcasing how the program responds to different user input. But don't feel like you have to make it exactly like the exercise suggests. If you want to try something different, by all means, go head. That is how new and interesting results happen. The exercises serve more as a guide or an idea generator if you don't know how to progress in your journey.
After reading the initial explanation, try to solve the problem (keeping in mind the problem solving mindset described in the following section).

Each exercise contains a series of hints. Each one helps you solve the problem more and more explicitly. While it is desirable that you try to solve the exercises with as few hints as possible, don't let you be disappointed if you need the hints - some of the problems are really hard and the hints are there to help you! Even if you do solve the exercise without using the hints, you can read them afterwords for valuable insights. :)




Solving Programming Problems

When you encounter a programming problem (or any kind of problem, really) it can be very useful to break it down into smaller and smaller problems, until they are easy enough for you to start solving them.
For example:
Create a program that sums three numbers the user entered

If you have solved similar problems, you may already have an idea on how to start. Pay attention how (even automatically) you thought about the steps required to solve the problem.
For instance, you might write the same problem in a different way:
1. Read three values
2. Add them together
3. Display the result

This may be enough for you to get started if you weren't sure how to program based on the first description alone. Those problems might be broken down even further:
1. Declare a variable
2. Assign it the result of
scan_int

3. Do steps 1 and 2 for two more variables
4. Declare a variable result and assign it to the sum of the first three variables
5. Call
print_int
and pass the variable result

Depending on your skill level, you might need to go all the way and write a more descriptive breakdown of the problem, or you might just start typing code after you read the problem.
But don't be fooled, there are problems that will require you to break them down even if you are an advanced programmer.

Let's go to a more complicated example:
Given a number of seconds, display the equivalent time in days, hours, minutes and seconds
Example:
Enter a number of seconds: 3812
This correspond to: 0d 1h 3m 32s

In this case, you might not be sure how to solve the problem, so it might be useful to break it down.
One simple way you could think about this problem is input, processing and output, or:
1. Read the number of seconds
2. Calculate the days, hours, minutes and seconds
3. Print the days, hours, minutes and seconds

Even though it might not have helped with the calculation part of the problem, at least you know how to get started!
It's important to note that you don't have to know everything about what you will program before starting, especially because as you work more on a specific problem, you will see it in a different way and gain more understanding of it. Making it easier to break it down and solve it. So break the problem just enough for you to get started. Start from the easiest task you can solve, implement a simple solution and when you are stuck, break the specific problem you are having. (This exercise will come up later on, so I won't give too much away! :) )

One last example to leave you wondering about breaking down problems:
Make a Space Invaders game

Just like the other examples, we can break it down like so:
Make the user control a ship on the bottom of the screen
Make the user shoot up
Create an enemy that move accordingly
Make the shot destroy the enemy and make the others speed up
Make the enemies shoot back
Make the game over condition
Make the win condition

As you can see, by breaking down the problem it becomes a lot easier to start tackling it. If you need, you might breakdown even further from there (you can see the actuals steps to make a game in the Making Games page.

Hopefully that gave you some food for thought to help you when you're stuck on some problem. The hints will try to help you breaking down complex problems into smaller ones so you can develop this skill. :)

Now let's get programming!




First Steps

These problems require a basic programming understanding and knowledge of the print procedure.

Hello, There!     [show]

Roses are Red     [show]


Input, Processing, Output

Now is the time to put to test the skills you learned in the previous pages.
You will have to read data, operate it and display it.

Your Name     [show]

The Most Important Year in my Life     [show]

Rectangle     [show]

Min-Max Rectangle     [show]

Even=0, Odd=1     [show]

Even=1, Odd=0     [show]

Seconds and Minutes     [show]

Days, Hours, Seconds and Minutes     [show]

RPG Combat System     [show]


Introducing Conditions

Conditions are a fundamental tool in a programmer's belt.
They allow certain instructions to be executed only on specific cases. Combined with user input, this can result in interesting and engaging programs. :)
In order to test a condition, you can use an if statement. If you have never used them, it might be worthwhile heading to the documentation to learn a bit about conditions, or doing one of the Vizzcode's embedded tutorials. In any case, these exercises will start out simple and increase in complexity (resulting in better and better programs!)

Let's go!

True or False     [show]

Expressing Comparisons     [show]

Operating on Truth and Falsehood     [show]

Conditional Execution     [show]

Covering All Cases     [show]

Greatest of Them All     [show]

Let's Play     [show]

I Will Remember This     [show]

I Will Improve This     [show]

Your Turn     [show]

I'm Going on an Adventure     [show]

Your Own Adventure     [show]


Loops

Another powerful tool you have at your disposal is the ability to loop.
Either to repeat the same instructions a number of times (even with variations between them) or to keep doing a group of instructions while a condition is valid; it's important to know loops inside out.
Just like if statements, loops allow you to control the flow of the program.
In Vizzcode, you can use the while and for statements to loop through the program. It's recommended you read about them a bit in these links before trying to solve the exercises, but the hints are there to help you!

Please Type a Number     [show]

Breaking the Loop     [show]

Choose Your Luck     [show]

Complete Calculator I     [show]

Count to 10,000     [show]

For Every...     [show]

Three and its Friends     [show]

Power Of     [show]

Power Of Them All     [show]

Complete Calculator II     [show]

Factorial     [show]

Multiplication Table     [show]


Transforming Lots of Values

Like we've talked before, programming is mostly transforming data.
When we are dealing with lots of data of the same type, it can be very useful to store it in an array.
They allow you to iterate through the items and operate them very easily.
You can learn all about arrays here and these exercises will put your knowledge to the test.

That's What I Said     [show]

All Backwords     [show]

Master of Numbers     [show]

Change of Plans     [show]

Sorting Algorithm     [show]

Poking Numbers     [show]

Querying Multiple Data     [show]

Aging Well     [show]

Shopping Lister 9000     [show]

More of The Same (Shopping Items)     [show]

Removing Elements     [show]

Linear Transformation     [show]

Battleship     [show]