I'm teaching some middle and high school students programming right now, and I found that some of them really liked online programming puzzles. So I created http://www.kapparate.com/coder/ , and right now there's 4 categories of puzzles.

All the puzzles are set up right now so that variables are pre-initialized, and the user plugs in some code in the middle.

For example, the problem might say these are pre-initialized:

int x = ????;
int y = ????;
int z;

and then the program might ask the student to write the final line of code: z = x + y;.

Now I know I could go a long way in improving the usability of this site (like having an area that lists the pre-defined variables), but I was wondering if this concept seems sound. I know some sites have kids fill in functions, but not all of my students know what functions are yet, and I'm trying to introduce online programming puzzles before that.

  • 3
    puzzles are a terrible way to teach practical skills – user7519 Sep 26 '12 at 16:28
  • You're right. My students learn primarily through projects. – Arcymag Sep 26 '12 at 19:51

You could mix your code and English a little better. It's one of those hassles that StackExchange has tackled pretty well. You could develop a system like here and highlight any text which is to be taken as code. Also, use a different color for mathematics, because = means different things if the context is mathematics or C.

You have side lessons within the problems. In that second question you introduce and explain the mod op. Put that in it's own paragraph or link to an aside. Or, honestly, just link it.

The actual problems are kinda buried in those paragraphs. I read through a couple and when I got to the end I had no idea what I was trying to solve for. Feel free to have background explanation (which is, you know, the educational part), but try to clearly state the problem.

And things like: "You may search the internet for the appropriate equation to use." shouldn't have to be stated. Programmers have access to the Internet. Not letting them search for solutions is as archaic as expecting them to write their solutions in pencil.

A standard form for the incoming variables and expected results would help.

A personal nitpick is the use of vague and terse variable names. If you're going to teach programming, teach them to use variable names which make sense.

So, taking a crack at rewriting one of your questions:

Complex Numbers: In mathematics, the square root of a number is X if X times X results in the number. However, the square root of negative one is known as "i". i has the properties such that i*i = -1. Complex numbers are written as the sum of their real and imaginary parts. Thus, 3+2i is a complex number with 3 and an imaginary part 2i. These complex numbers obey standard algeberic rules for adding and multiplying equations with variables. Thus, (3+2i)*5 = 15*10i. Additionally, `(a+bi)*(c+di) = a*c + a*d*i + c*b*i + b*d*i*i, which simplifies to (a*c-b*d)+(a*d+c*b)*i. Further reading: "complex numbers", "multiplying imaginary numbers", "the FOIL method", "multiplying complex binomials"

Problem: Write a function that solves (a+bi)^2.

int realPortion; //Range: any value
int imaginaryPortion; //Range: any value
realPortion should store the resulting real portion of the equation.
imaginaryPortion should store the resulting imaginary portion of the equation.


//You do not need to create double a, or double b

The word is "declare". You declare variables. They're going to run into that later and it's good to stay consistent.

hmmm, something about these implied variable declarations still bugs me. I dunno, maybe you want to explicitly show the code that comes before and after?

void Divisibility_Test()
  int x;
  int y;
  boolean xIsDivisibleByY;

(text box for students to type in)


Also, I think I have a philosophical issue with #7 which uses casting to an int to round off a double. I can't say it doesn't work. Or that it's wrong per se.

This would be above and beyond, but I imagine if you churn through enough impressionable youths you're going to hit those naturally gifted ones which plow through this. If you had challenging bonus questions you might be able to light up some inspiration and get them interested. Things like computing the Fibonacci sequence, constructing markov chains, a bot that can play checkers.

Best of luck. Teaching children to code is a daunting task and it's largely up to them. All you can do is lay out the path. Thinking back, there were an awful lot of pitfalls and hours of frustration. ...of course, that implies anything has changed.

| improve this answer | |
  • Thanks. I'm going to reformat the questions along this style over the next couple days! As for not needing to say programmers have access to the internet... I keep telling some of the kids in elementary and middle school that, and yet they feel so compelled to try to figure it out without the net. Might be because they feel like they're cheating. – Arcymag Sep 26 '12 at 17:25
  • Thanks again. Made some of your changes: www.kapparate.com/coder . Still have a lot of work ahead =). – Arcymag Sep 27 '12 at 1:13

There was a site a while ago (it is dead now) called codingkata.org. The Java katas on there had a problem description and then you used a maven archetype to get the project and implement the given method signatures. There were then unit tests that ran over your code when you ran mvn test that told you whether you passed the kata or not.

Doing something like this would introduce your students to the concepts of maven (which is used heavily in the Java world) and get them used to using it to setup projects, manage the pom and run unit tests.

It would also force them into learning about functions and going from this is my problem to this is my solution all within the safety of knowing that it can be automatically checked.

They can also use their favourite IDE/text-editor/etc. to implement the code as they see fit too.

I would also work on the description of your problems too; I found them hard to read personally.

| improve this answer | |

Some good answers already. Just a few insights:

  • Your problems are fun but at least the first few are as much about math as about math as about programming. That's OK if that's the intent.

  • You might consider introducing the procedure fairly early on. That would make a nice little bundle that could help define the problem statement and make testing the solution clearer. Also, it creates a package for variables to pass into and out of. Instead of seeing that x = 4; y = 2; x + y = 6; a procedure would give the sense of infinite variation such that int plus(int x, int y) { return ???; } would make a lot more sense and I think be clearer for a student to fill in. It's useful (sort of) outside of the scope of the individual problem.

  • It's really hard to write a good problem statement. I'm currently taking Martin Odersky's free online Scala course and I often find myself confused by his problem statements. But he includes a few unit tests with each problem and reading his tests really nails down the scope and intent of the problem. The actual grading uses about twice as many tests as he gives you and you are encouraged to make up your own tests. Really, the unit testing is the first aspect of the course that I can immediately apply at work.

| improve this answer | |
  • Yes, Since the more advanced material I teach requires a decent grasp of math, I felt math+programming would be a good mix. As for doing functions, I might try teaching that earlier to kids so that they can understand problems that complete functions. I absolutely agree with the unit test stuff, and I'll try to expose more of the test cases in the future. – Arcymag Sep 26 '12 at 17:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.