2
\$\begingroup\$

BACKGROUND: I am a CS lecturer (teaching C++) and I keep thinking how to incorporate coding challenges in teaching.

Many questions in this site are great; I have just used Do you want to code a snowman? as a warm-up homework assignment. The challenge of writing short programs fits my goal of encouraging my students to write short and succinct code. The problem is, when the code is made too short (e.g. by putting everything in a single line without spaces), it is not readable - which goes against another educational goal.

QUESTION: is there a way to design a challenge of the form "solve problem X using the shortest code possible, but the code must still be readable"?

I am not sure how to define "readable" in a consistent way; maybe "the code should pass a linter check"?

\$\endgroup\$
4
  • 6
    \$\begingroup\$ The problem with "readable" is that it isn't objective, and we require all challenges to have objective specifications. You can encourage users to include an ungolfed version, but there's no real way to require that \$\endgroup\$ – caird coinheringaahing Mar 11 at 0:04
  • 4
    \$\begingroup\$ You could do an atomic code golf sort of thing, where the actual formatting doesn't matter, if you chose an instruction set similar enough to C++ to be helpful to your students. The linter check could be a neat idea too. \$\endgroup\$ – Redwolf Programs Mar 11 at 0:27
  • 1
    \$\begingroup\$ There's also [fastest-algorithm], which may (sometimes) result in shorter code. \$\endgroup\$ – user Mar 11 at 0:28
  • 1
    \$\begingroup\$ @RedwolfPrograms You might want to turn that into an answer. \$\endgroup\$ – user Mar 11 at 0:42
4
\$\begingroup\$

Atomic code golf challenges define a language (or subset of one), and require doing something with as few of those operations as possible.

The advantage of this is that the formatting doesn't matter very much. You could write your program with whatever whitespace and variable names you want, as long as what counts as an operation is clearly defined. This doesn't require compact code, but it does require compact algorithms (not necessarily fast ones, though :p).

A disadvantage of something like this is that what counts as an operation must be very clearly defined, and if you're trying to make the language used something complicated like C++, quite a lot of work will need to be put in to do this.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Interesting. There should also be a way to autmoatically count the number of atoms, so that we do not have to manually count words in hundreds of submissions.. \$\endgroup\$ – Erel Segal-Halevi Mar 11 at 7:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .