How To Use These Puzzles

How to use the puzzles: Start at the beginning of the puzzles and solve them one-by-one in order. The puzzles start out easy and gradually become more difficult. Try to work each puzzle. If you merely read the puzzle and then look at the answer you are not using your time effectively.

Don't rush through these. Do a few puzzles, and then stop. Later in the day, or the next day, when ever you have some time available, do a few more. Short practice sessions are more effective than long ones.

Revise your Code: Often students stop as soon as their program sort of works. But their program could be better done, and is just not professional grade. Just as with other subjects, you can learn a great deal by revising and improving your work.

Break Things: If you have a working program, find ways in which it fails, and then fix the problems. Look for dangerous assumptions that you have made (such as assuming that the data will always be positive, or that a buffer if big enough, or that an array will always contain some data.) Some of the suggested solutions may have such problems. Try to find them.

The language: The language used for these puzzles is ANSI C. The particular programming environment is Bloodshed Dev-C++. The answers to the puzzles have been tested in that environment. However, any C++ environment should work. All C++ compilers also compile ANSI C. Dev-C++ is available here:

http://www.bloodshed.net/devcpp.html

The puzzles can easily be used with the free edition of Microsoft Visual C++ Community Edition, the Express edition.

https://www.visualstudio.com/vs-2015-product-editions

Console Applications: All of these puzzles are "console applications" which means that standard input is the keyboard and that standard output is the console (on Windows machines, the "DOS Window", sometimes called the "command prompt window"). With Dev-C++ a command prompt window will automatically be created if you compile and run an ordinary source file, one not part of a Windows Application project.

system("pause"): When a console application runs from within Dev-C++ or MS-VCPP, the system sends standard output to a new console window it creates. But when the program stops running, the new window vanishes and you can't see what the program did. To prevent this, put system("pause") at the end of the program. This keeps the console window on the screen until you hit a key. Another way to do this is to put getchar() at the end of the program. Yet another way to deal with this is to use the debugger and place a breakpoint at the last statement.

If you use system("pause") you may need it put #include <stdlib.h> at the top of your source file.

Difficulty Rating: Difficulty is rated Easy, Medium, and Hard. A puzzle rated [E-8] has eight lines of easy code. A puzzle rated [M-10] has ten lines of medium difficulty code. A puzzle rated [H-5] has only five lines of code, but those lines are hard to write. The number of lines of code includes lines in the function body, not counting blank lines, braces, doucumentation, or lines contained in a previous answer.


Back