WOGL Puzzles
Earlier in class, we talked four different modes of learning:
- Study: read or listen to information provided by others
- Solve / build: work to accomplish a specific goal
- Play: conduct unstructured exploration without a clear goal, guided by curiosity and delight
- Experiment: conduct structured exploration with a specific goal; carefully form and test theories
Today’s activity is a lesson in conducting experiments. Our learning goal is to practice experimental science on software:
- Observe.
- Make guesses. Form a theory.
- Devise a new experiment to test the theory.
- Consider the results.
- Revise the theory and repeat.
This may sound familiar from science classes you’ve taken in the past. Today, you’re not just studying the scientific method in general; you’re learning to apply it to software. That means you will:
- Get a sense of what kinds of experiments and approaches are particularly useful in the software domain.
- Learn how to design experiments around a specific computer science question.
- Practice that all-important practice of making guesses before observing the results.
Experiment 1: Upper and lower case
| Setup | |
|---|---|
| Program: | NEATSOILMUG |
| Sides: | somewhere between 5 and 7, not an integer |
| Step: | large enough to see each segment clearly, small enough to see the whole thing at once |
| Debugging: | enable “Show turtle” |
| Rendering: | increase dot size |
Set the debugging mode to Manual and click restart. Using the debugger to step through the program one letter at a time, and note:
- Which letters in the program turn and draw? Answer:
EATOIU - Which letters in the program only draw? Answer:
L - Which letters in the program only turn? Answer:
NSMG
(The answers are right there in the hidden blocks, but do the experiment for yourself! Then use the hidden text to check your program. The point here is for you to practice experimenting and observing, not just to have the answer.)
Now set the debugger back to Fast. One by one, change each letter in the program to lowercase, and as you change each one, note:
- Which lowercase letters move and draw a dot?
- Which lowercase letters only move?
- Which lowercase letters only draw a dot?
Compare your observations here with the notes above. Form a theory to answer the following question:
Is there a consistent relationship between what the uppercase form of a letter does and what its lowercase counterpart does?
Is your theory always true? Is it a consistent rule? Let’s test it.
- Look at the class’s WOGL documentation.
- Pick a few more uppercase letters that do not appear in
NEATSOILMUGthat would help you test your theory. (What different kinds of letters should choose to make this a good test? At a minimum, one that only draws, one that only moves, and one that does both.) - Add those uppercase letters to your program.
- One by one, predict what the lowercase form for each one should do, then test your prediction.
If your theory didn’t work out in your experiments, revise it and try again.
If your theory held true for many letters, does that mean it must hold true for all letters? No, but it’s likely — and the more a theory holds up to experiment, the more likely it is that it will be true in cases you didn’t test! This is how science works: testing theories with experiments doesn’t offer absolute certainty, but it does offer confidence. (Look up Karl Popper.)
Experiment 2: Apostrophe and quotation mark
| Setup | |
|---|---|
| Program: | LAdLE |
| Sides: | anything > 2 |
| Step: | large enough to see each segment clearly, small enough to see the whole thing at once |
| Rendering: | Lines and dots both fairly thick |
| Debugging: | Fast speed |
Try adding a single apostrophe between the first and second letters: L'AdLE. What changed? Go back and forth a little to make sure you’re seeing it correctly.
What setting appears when you add the apostrophe? +Hue Why do you think it appears? Try making it bigger.
Now change the apostrophe to a quotation mark: L"AdLE. What changed? Is it the same as apostrophe? Hint: The same thing changed, but it didn’t change in the same way. What setting appeared when you added the "?
Make a guess about the relationship between ' and ".
Here are some experiments to help you test your guess, and you should also come up with your own:
- What is the difference between
L'AdLEwith a +Hue of 120 andL'''AdLEwith a +Hue of 40? - What does
L'AdL"Edraw? Which parts of it do and do not change when you adjust +Hue?
Experiment 3: Apostrophe and word recursion
| Setup | |
|---|---|
| Program: | ddd L |
| Step: | large enough to see each segment clearly, small enough to see the whole thing at once |
| Rendering: | Lines and dots medium thick |
| Debugging: | Fast speed |
First, discuss and then reveal each answer:
- What does
ddo by itself? Draws a dot. - What does
Ldo by itself? Moves the turtle forward while drawing. - What does the space in this program do? It recursively adds the
Lafter everyd. What is a sequence of letters without a space that produces an identical result? dLdLdL (We looked at this in the previous class. If you’re still confused, that’s OK! Flag the instructor for help.)
Now, think about the following program but do not put it into WOGL yet:
ddSd L
(S turns counterclockwise.)
- How many line segments will this program draw?
- How many dots will this program draw?
Try it and see if your guesses were correct. Make sure you understand the result.
Now, consider this program, but again do not run the program yet:
dd'd L
- How many line segments will this program draw?
- How many dots will this program draw?
Try it, and see if your guesses were correct this time.
No matter whether you guessed correctly or incorrectly, what’s surprising about this result? What’s your theory about the difference between ddSd L and dd'd L?
Does the same theory hold true for "? Test it. Do you have a guess at the general pattern here? Can you test that theory?
Work at this for a while. (This is a great time to get the attention of a preceptor or instructor!) Once you have a theory and you have tested it, you can reveal the answer:
When there is a word followed by a space, then after each letter in the word, WOGL will recursively run the entire program following the space.
However, that is only true for letters. Punctuation marks suppress recursion.
The program dd'd L is equivalent to dLdL'dL. Note that WOGL does not do the L after the '.
Experiment 4: Parentheses
| Setup | |
|---|---|
| Program: | AEIOU d |
| Sides: | 5 or more |
| Step: | large enough to see each segment clearly, small enough to see the whole thing at once |
| Rendering: | Lines and dots medium thick |
| Debugging: | Fast speed |
Take a look at what the program draws. Make sure you understand why it does what it does. (You do not need to puzzle out the exact angle of every turn, but you do need to be able to look at the result and say, “Yup, that’s the A, that’s the E, all those dots are the ds…” etc.)
Now try these programs:
(A)EIOU dA(E)IOU dA(EI)OU d
What do parentheses do? Form a theory, then find more ways to test your theory.
If your theory is looking good after testing, then try switching the debugging mode to Manual and stepping through one of the programs above, trying to predict each next letter will be before you see it.
So what are parentheses good for? (Click to expand)
Here is an example that uses parentheses to draw something mathematicians call a “devil’s staircase” (or, less colorfully, a “Cantor ternary function”…but “devil’s staircase” is cooler, right?).
Here is the program (but use the link above to see it with some good settings):
8 <D(<L>)D> aN
The 8 followed by a space repeats the following word, so the program above is the same as:
<D(<L>)D> <D(<L>)D> <D(<L>)D> <D(<L>)D> <D(<L>)D> <D(<L>)D> <D(<L>)D> <D(<L>)D> aN
The L in the middle of each word draws a line segment; the parentheses around it prevent recursion. The < and > cause those line segments to be smaller and smaller with each level of recursion, so the L in the first word is bigger than the L in the second, which is bigger than the L in the third…. Put together, each repetition of <D(<L>)D> thus does the following:
< |
Make the step size smaller |
D |
Recursively draw a smaller staircase |
(<L>) |
Draw a line segment at a slightly smaller size, without recursion |
D |
Now recursively draw another smaller staircase |
> |
…and restore the original step size |
The final aN causes the staircase to rise a tiny bit without drawing anything. At the end of aN, the turtle is still pointed in its original direction, but now is positioned just a bit higher.
Here is that same example with extra code to show the levels of recursion with color and line thickness.
Experiments 5+: Punctuation extravaganza!
If you are enjoying the puzzling and feel like you’re learning from it, here’s a challenge: figure out what all the other punctuation marks do! Some of them are quite interesting.
To save you some time and puzzlement, these don’t do anything (yet, but I have some ideas and I’m also open to suggestions):
!#$&,.:;?@`{}
Digits are a nice one to study:
0123456789
They are fairly straightforward once you figure out how they work — but figuring it out may be a trick. Here’s a starting point for puzzling them out: 3AE and 3 AE do very different things. Step through each of those and study what to do. (Try 10 AE with sides=4. It’s quite pleasing!)
The following all have an effect you can observe directly, and there’s a good chance you can figure them out just combining each one with some letters, playing with any additional parameters that appear, and following your nose:
+-*/<>_=
These are a little trickier:
~%
Try placing each one in sequences of letters like LAPLA or EEEEE.
This one will be tricky…until it isn’t:
#
Hint: Try #A while dragging the Sides slider.
Also tricky:
|\
Here’s an experiment to help you start to figure those two out: Try FA\|L and FA\|LdL with different numbers of sides.
These four are tricky to figure out:
[]$^
Start with the square brackets. Here are some useful examples for you to puzzle over:
[AAA]EEEF[AAA]EEE-
F[A[AA][EE]]EEE(Try stepping through this one in the debugger) [A][E] d[A][E] [A][E] d-
5 [A][E] d(Try adjusting the number of sides) -
5 <[A][E]> d(Crank up the Step, then play with *Step) -
5 <[A][E] d(Compare this to the last one. What’s the difference? Why??)
If you made it this far, let me know and I’ll give you some more puzzles!