For those readers who missed it at the bottom of my last post, the Orange County districts are both taking the week after Easter (Bright Week) off for spring break. Two years ago, Easter was later, and so the district closed the week before Easter (Holy Week) instead. Last year, all schools closed for coronavirus just before we made it to the spring holiday. But this year, I still have one week left of the Big March -- which explains why I sing seven verses of the "Big March" this year, one for each of the seven weeks between Presidents' Day and spring break.
Lesson 13-8 of the U of Chicago text is called "Exterior Angles of Polygons." In the modern Third Edition of the text, there again is no separate lesson for today's material. Part of it appears in Lesson 5-7 along with yesterday's lesson.
This is what I wrote two years ago about today's lesson -- which includes a discussion of Logo, the programming language mentioned in Lesson 13-8.
[2021 update: I'm retaining that old discussion this year, even though my focus is now on other programming languages (Mocha BASIC and Java).]
The simplest way to get to infinity is by a simple program. We write it in BASIC:
10 PRINT "HELLO"
20 GOTO 10
but we can also write it in Logo:
to hello
print "Hello
hello
end
Ironically, we must end the procedure with "END" even though it doesn't end. Last year, I mentioned an infinite polygon program written by Brian Harvey:
to poly :size :angle forward :size right :angle poly :size :angle end
So that is what I wrote last year. This year I decided to go back to the Berkeley Logo and show you some more interesting programs. One of my favorites is Tic-Tac-Toe:
https://www.cs.berkeley.edu/~bh/v1ch6/ttt.html
This set of procedures combines both list processing (for the strategy) and turtle graphics (to draw the X and O symbols). We can recognize most of the turtle graphic procedures:
to drawx
setheading 45
pendown
repeat 4 [forward 25.5 back 25.5 right 90]
end
This procedure obviously draws the X's. The only procedure with which we might be unfamiliar is the line setheading 45. Of course the 45 refers to 45 degrees. What this line does is tilt the turtle 45 degrees so that the symbol looks more like an X than like a + symbol.
Now that we've seen drawx, we may be curious to see what drawo looks like -- perhaps it's similar to the 180GON that we see in the U of Chicago text. Well, actually it isn't:
to drawo
pendown
arc 360 18
end
Of course, we can easily figure out what the line arc 360 18 does -- the 360 obviously means 360 degrees, and I think that 18 refers to the radius of the arc (in turtle units).
Most of the link above discusses Tic-Tac-Toe strategy and how to implement it. Harvey writes:
At the beginning of the discussion about strategy, I suggested that one possibility would be to make a complete list of all possible move sequences, with explicit next-move choices recorded for each. How many such sequences are there? If you write the program in a way that considers rotations of the board as equivalent, perhaps not very many. For example, if the computer moves first (in the center, of course) there are really only two responses the opponent can make: a corner or an edge. Any corner is equivalent to any other. From that point on, the entire sequence of the game can be forced by the computer, to a tie if the opponent played a corner, or to a win if the opponent played an edge. If the opponent moves first, there are three cases, center, corner, or edge. And so on.
Actually, the problem of Tic-Tac-Toe strategy has already been completely solved. The solution is given by the website xkcd, which describes itself as "A webcomic of romance, sarcasm, math [ha! -- dw], and language":
https://xkcd.com/832/
By the way, xkcd has created webcomics for several math topics. I was able to find two different webcomics involving Zeno's Paradoxes!
https://xkcd.com/1153/
https://xkcd.com/994/
Harvey goes on to write:
If you're tired of tic-tac-toe, another possibility would be to write a program that plays some other game according to a strategy. Don't start with checkers or chess! Many people have written programs in which the computer acts as dealer for a game of Blackjack; you could reverse the roles so that you deal the cards, and the computer tries to bet with a winning strategy. Another source of ideas is Martin Gardner, author of many books of mathematical games.
[emphasis mine]
[2021 update: Actually, a very interesting game to attempt is the one that Alice and Bob play in Putnam problem 2020 B2. Since the goal for the Putnam participant is to find ways for Alice to win, we should let the user be Alice and the computer be Bob. Then our goal as the programmer is to find ways for Bob to win.]
What the -- here's yet another Martin Gardner reference! Well, that just goes to show how popular Gardner and his math games column was!
Actually, before taking up Harvey's suggestion the challenge would be to implement xkcd's game strategy in Logo. Notice that xkcd's Tic-Tac-Toe strategy is in fact foolproof, in that if the computer were programmed to follow it, the computer will always either win or tie. So in the procedure:
to ttt
local [me you position]
draw.board
init
if equalp :me "x [meplay 5]
forever [
if already.wonp :me [print [I win!] stop]
if tiedp [print [Tie game!] stop]
youplay getmove ;; ask person for move
if already.wonp :you [print [You win!] stop]
if tiedp [print [Tie game!] stop]
meplay pickmove make.triples ;; compute program's move
]
end
we can delete the line that says You win! (where "you" refers to you, the computer user) because that line can never be reached.
By the way, I spend so much time writing about the BASIC emulator Mocha, so now it's natural to wonder whether there's an online Logo emulator. Well, I found the following link:
http://www.calormen.com/jslogo/
To use this emulator, we must click on the arrow near the "Run" box on the bottom of the screen -- this allows us to enter procedures on more than one line. Then we can type in REGGON as written in the text:
to reggon
repeat 18[forward 7 right 20]
end
reggon
Then we click the "Run" box to run the program.
This program works, but some of the others written in the book don't work. For example, 180GON doesn't work since apparently, procedure names must start with a letter, not a digit. So we can place an "a" in front of the procedure name:
to a180gon
repeat 180[forward 3 right 2]
end
clearscreen
a180gon
It also appears that infinite loops don't work -- apparently the computer must complete the entire program before the turtle moves a single step. So we can't run "hello" or "poly" as mentioned earlier in this post.
On the other hand, loops that eventually stop will work. The program "tree" as given at the Brian Harvey link works:
http://people.eecs.berkeley.edu/~bh/v1ch10/turtle.html
In fact, "tree" is already pre-programmed in, and we can just click on it on the right side of the screen.
I tried some of the other programs from the Harvey page. His "face" works -- in the text editor, enter his program "to square" first, then "to face." I'd add these three lines before clicking "Run":
clearscreen
face
hideturtle
The last line hides the turtle so that there isn't a turtle in the middle of the face. The command to make the turtle reappear is:
showturtle
Here's another program I had fun with:
to namegame :name
cleartext
print sentence sentence :name :name sentence "bo word "b bf :name
print sentence [Banana fana fo] word "f bf :name
print sentence [Me mi mo] word "m bf :name
print :name
end
namegame "David
Unfortunately in all the years I've posted, I've never full created a Lesson 13-8 worksheet. So instead I'll post what one of the eighth grade classes from last year used. It's actually a foldable that can also be included in an interactive notebook.
What's bad about this is that "interior angles" and "exterior angles" are apparently misspelled as "internal angles" and "external angles." Thus the only part that actually matches anything in our Chapter 13 isn't even spelled correctly. But it beats anything I've previously posted for this lesson -- and vocabulary, foldables, and interactive notebooks are all things that I need to incorporate into my own lessons more often.
[2021 update: That is, I needed to incorporate these before the coronavirus. I just did a virus-friendly lesson for Lesson 13-7, so we don't need one for 13-8.]
No comments:
Post a Comment