views:

846

answers:

5

How would you write pseudocode for drawing an 8-by-8 checkerboard of squares, where none of the squares have to be full? (Can all be empty)

I don't quite get the pseudocode concept.

+1  A: 

Pseudo code is writing out the code in form that is like code but not quite code. So for opening a file and printing printing out its lines of text

if file exists(path_to_file) then :
 open (path_to_file)
 for each line in file  : print the line of the file

All you should do is create the sequence of steps needed for your problem and write it out like that. Since you mention python, just use use a more python like syntax in your pseudo code.

I suspect that you problem will be to encourage you to consider how to make functions and classes, and writing the pseudo code first will help you do this.

Preet Sangha
You suggest using a more Python-like syntax in pseudocode. But then, it's not pseudocode anymore. All pseudocode should be language independent, using plain English (or, in some cases, your native language). No language constructs should be used.
Thomas Owens
Given the sheer number of languages out there, chances are that your pseudocode will resemble at least one of them. I say, don't sweat it, just make sure your pseudo-syntax is somewhat consistent.
Bugmaster
@Thomas, Wikipedia (at http://en.wikipedia.org/wiki/Pseudocode) disagrees -- showing how pseudocode can be and generally is Pascal-like, math-like, etc, etc -- and I agree with them. See the 90+ articles listed at http://en.wikipedia.org/wiki/Pseudocode and you'll see they use pseudocode including programming constructs such as **if**, **then**, **else**, **while** and so on. Natural language is too often ambiguous and verbose -- e.g. saying "the bit-by-bit exclusive-or operation executed on the binary-string equivalents of integers x and y" rather than "x XOR y" would be just silly.
Alex Martelli
http://en.wikipedia.org/wiki/Pseudocode#Alternative_forms_of_pseudocode
Preet Sangha
+1  A: 

I'm guessing this is a class assignment, right?

In short, pseudocode is very similar to an outline. It's the structure of how you're going to go about solving the problem, without the specific details.

In this case, you'd probably use a couple for-loops, and sketch out the drawing and there...

for x in range(0,10):
    for y in range(0,10):
        #print out the square (x,y)
ewall
+2  A: 

Just write something that looks like a hybrid between code and normal human explanation.

for i from 1 to 8
    for j from 1 to 8
     print "[ ]"
    print "\n"
Unknown
Like python do you :P
Hugoagogo
+4  A: 

I would be even more generic eg.

Loop with x from 1 to 8
    Loop with y from 1 to 8
        draw square at x, y
Mike K
So that would be all there is to it? You don't have to include actual code?
Benjamin
@Steve: pseudo=fake. so no code is needed :-)
klez
+1  A: 

Wikipedia articles use Pseudocode a lot, quite successfully. There is no standard for Pseudocode on wikipedia, and syntax varies, but here is some general information with examples: Algorithms on Wikipedia

Here are two good examples of articles with Pseudocode (more):

Using Wikipedia-like style, I'd do:

for i from 0 to 7
    for j from 0 to 7
        if (i + j) is even then
            paint square (i, j) black
        else
            paint square (i, j) white

(Marking end of if or end of for with 'end if' or 'repeat'/'end for' is a matter of style I guess).

kaizer.se