Problems for the Adept

Lesson 3

Simple exercises

• Use the postscript random function to plot random points on the page. See if you can spot any clusters (hence, evidence, that the random number generator isn’t truly random).

• Play with the PostScript error handler so that it gives you more information; perhaps it would be a good idea to scale down the page so that you can see things that would have been printed off the page.

• Write a program to calculate the first 100 fibonacci numbers and print them out. Do this both recursively and iteratively.

• Fractals (see margins).

• Plot a graph: given a set of points, draw a graph using discrete lines.

• Draw a bar graph: given a set of discrete data points draw the corresponding bar graph.

• Draw a landscape banner; have your procedure take an array of strings and produce the saying nicely centered on the page both vertically and horizontally.

Medium/difficult exercises

• Plot an arbitrary user-supplied function (perhaps taking the function as an argument e.g. { sin } ).

• Substitution cipher: Write a function that takes two arguments: a string of 26 characters and a message string to encode. Return the encoded message string (assume the 26 letters are in the order they are to be substituted for the original alphabet). Also write a decoding routine.

• Draw a landscape banner that may span multiple pages if its length is appropriate; your procedure should take an array of strings and produce text nicely centered both horizontally and vertically on the page.