Friday, December 11, 2020

Will Geulleu

 Will Geulleu

By Bobby Neal Winters

One day last week I was sitting in the faculty lounge and separating decks of playing cards that someone had shuffled together for some reason.  Doing tasks like this is my karma, both in the literal and the metaphorical sense.  I was working happily away when Will Geulleu, a well-known member of the faculty walked in.  

Will is not well-known because he’s a great teacher; he might very well be.  He’s not well known because he’s a careful researcher; I can’t say one way or the other.  

He is well-known, however, to be a card shark.

Will, looking at the cards in my hands and their state of disarray, smiled.

“I bet I can tell you exactly how many cards you have in your hands,” he said with a twinkle.

“I don’t bet,” I replied because indeed I don’t.  I remember, but I didn’t tell him, that line from “Guys and Dolls” about a card jumping from a deck and spitting cider in your ear.  “I don’t bet,” I repeated, “but I would be interested in you telling me how many cards I have.”

Will thought a spell before replying.

“Okay,” he finally replied, “but it will require effort on your part.  This is magic, but it comes at a cost.”

It was my turn to smile.  I don’t believe in magic anymore than I believe in taking someone else’s bet, but know I was curious to see how his game played out.

Will then outlined a procedure for me to follow, which I will now share with you.

Deal out (almost) all of the cards into four stacks; each of the stacks will contain exactly the same number of cards.

When dealing out the cards into four stacks, they might not come out even, i.e. there might be 1, 2, or 3 left over.  If there are cards left over, put them into their own stack in a particular case.  If the cards come out even, put down a poker chip in the place where you would’ve stacked the cards. 

Once all of the cards have been dealt and either the left over cards (or the chip) have been put in their place, pick up exactly one of the four equal piles and move the remaining three stacks out of the way.

Take the one stack you took from the four equal stacks produced by your dealing, and repeat steps 1-3 from above with it. Again, when you are done, put down either the left over cards or the poker chip to the right of your previous cards or poker chip.

Continue this process until all of the chips are gone.

I asked Will to leave the room while I did this because I wanted to be sure he wasn’t counting the cards as I dealt them out. That wouldn’t  have been fun at all.  Once he was safely out of the room, I began the process.

The first round of dealing came out even, so I put down a poker chip.  The second round I only had one card left over, so I put it down to the right of the poker chip.  After the third round, I had two cards left; to make the easy to count, I put them down in a vee shape to the right of the single card from round two.

At this point, each of the stacks had only one card, so I was momentarily confused.  I became very literal-minded at this point, and dealt it out into four stacks of 0 cards and had only one left over.  When I was done, it looked as in the picture below:

At this point, I invited Will back into the lounge.  He looked at the cards, knitted his brow a bit, and moved his lips silently, giving the appearance of great concentration.  Once he was done with his dramatics, he gave his pronouncement.

There are 100 cards.

I gathered all of the cards together and this time used my own algorithm, counting them into stacks of ten.  When I was done, I had ten stacks of ten.  Will was right, there were 100 cards.

The reader is at this point invited to pause to figure out how it was done.

The Explanation

As a mathematician, I realized immediately how he did it.  Actually, it took a minute or two, but there was no way I was going to let him know that, so I played it cool until I figured it out and then--and butter would not have melted in my mouth--I told him how he did it.

Now I will tell you.

The process Will described was a sneakily disguised algorithm for rendering numbers into base 4.  You can use it to put numbers into any base, actually, by having the number of equal stacks be equal to the desired base.  In this process, we represented the number of cards by



But in standard written notation it would be 1210 (base 4); note the reversed order which makes it even sneakier.  Expanding this number from base 4 gives (1)(64) + (2)(16) + (1)(4) + (0)(1) =100 base 10.

The dealing process and reserving the number of left over cards is a physical representation of what mathematicians call the Division Algorithm.

The process of yielding a number into a particular base can be put into a simple algorithm that we represent in pseudo-code below:

Digit_list = []
While N > 0:
N, r := N // base, N % base
        Digit_list.append(r)
Return Digit_list

Where // denotes integer division and % denotes keeping the remainder from division. 

Doing this on a computer seems like cheating when compared to the elegant simplicity of the Dealing Algorithm. To use a computer, one must know what the number is to begin with and have a representation of it in some base already.  With the Dealing Algorithm, the number of cards is unknown at the beginning.  Performing the algorithm reveals the name of the number, like tricking out the name of Rumplestilskin. 

A Final Walk-Through

To achieve a fuller understanding from the barebones level, let’s trace through the Dealing Algorithm again.

Recall, in the first round everything came out even and a put down a poker chip that represented 0.  Add 0 times 1 to the total.

I had four stacks of cards each having exactly the same (unknown) number of cards.  I only took one of those stacks to the next round, but each card in that one stack is standing for four cards, one from each of the stacks.

In the second round, when I deal out the cards and have one card left over, that one card is standing in for four cards.  I now add 4 cards to my previous total making 4 cards all together now. 

I take one of the four stacks to the third round, but each card in that stack is standing for four from the previous stack and each of those was standing for four from the first round.  That means when I have two cards left over, they are representing 2 time 16 = 32 cards.  Adding this to the total brings it to 36.

My equal “stacks” of cards each now consists of one card.  That one card will be the remainder of the fourth round dealing process.  It stands for four third round cards, and therefore for 64 cards total. So this round contributes 64.  Adding this to the total brinks us to one hundred. 

This is a simple physical process, but it does arithmetic for us.



Monday, January 6, 2020

Solving Sudoku on the Computer

Solving Sudoku on the Computer

By Bobby Neal Winters

Introduction

My journey toward writing a decent computer program to solve Sudoku puzzles began with free time and a question.  The free time was Christmas Break and the question was whether I could write such a program.  This journey led me to learn some new things--some new mathematics--that I can now share with you, the gentle reader.  I hope that, having read this far, you will stick around for the story of my journey.

The truth is that I wrote two such programs.  I wrote them both in Python using the pandas library.  The initial puzzles, i.e. the clues for the puzzles, were input using Excel spreadsheets.  My reason for using Python, pandas, and Excel is an ancient one: “When all you have is a hammer, everything looks like a nail.”  However, in this case, these tools were indeed sufficient for my purposes.
This first of these two programs, which I will refer to as “the Naive Program,” was very...naive.  I will expand on it briefly in the sequel.  The second program required that I learned some new mathematics.  New to me, at least. I will share this with you at length in the sequel, but it will all be kept at an informal level.

The Structure of the Sudoku Board

I am virtually positive that any of you who have made it this far are at least as familiar with Sudoku puzzles as I am, but for the sake of exposition--and setting up notation--let me explain Sudoku puzzles.

Each Sudoku puzzle begins with a 9 by 9 grid of cells that can be partitioned three ways: 9 horizontal rows and 9 vertical columns.  We number the rows beginning at the top as R1, R2, R3,...,R9.  We number the columns beginning on the left as C1, C2, C3,...,C9.  The cell where Rr meets Cc will be denoted as RrCc.

Each of these cells RrCc is ultimately to be filled with a value v that is one of the numbers 1,2, 3,..., 9. (Here I should say that any nine distinct symbols would work, but that using another symbol set offers no advantage.)

In addition to rows and columns, there is structure of 9, disjoint, 3 by 3 squares of cells that we shall denote by B1, B2, B3,..., B9.  Note that the cell RrCc will belong to the block Bb where
b = [( r - 1) // 3] * 3 + (c -1) // 3 + 1
With // denoting integer division, i.e. 4 // 3 = 1.
To fill out a Sudoku puzzle correctly, one must obey the following requirements:
  1. Each cell RrCc must contain a value v from the set {1,2,3,..., 9}.
  2. Each row Rr must contain each value from the set {1,2,3,..., 9}.
  3. Each column Cc must contain each value from the set {1,2,3,..., 9}.
  4. Each block Bb mush contain each value from the set {1,2,3,..., 9}.
  5. A Sudoku puzzle is said to be solved when all of the requirements above are met.

The Naive Program

I designed the Naive Program in the following way.  I thought of the cells in the Sudoku puzzle as being ordered like the words on a page: Every cell in a higher row precedes every cell on a lower row; given two cells on the same row, the cell on the left precedes the cell on the right.  The algorithm I follow proceeded as below:
  1. Place the cells that do not hold an initial value in a list which is ordered as described above.
  2. Set a pointer to the first cell.
  3. In the cell pointed to by the pointer, place the smallest untried value for that cell that doesn’t cause duplicate entries for the row, column, and block.  If such a value can be found go to step 5; otherwise proceed to step 4.
  4. Forget about all values tried in this cell; decrement the pointer; go back to step 3.
  5. Put the value found in step 3 in a used this for this cell; decrement the pointer; go to step 3.
This ends positively when the pointer can no longer be incremented and negatively when it can no longer be decremented.
I applied this algorithm to a small number of test cases, one of which required 3537 seconds to find a solution.  The save you the arithmetic, this works out to about an hour.  A college of mine did the same puzzle in half an hour while talking to a colleague. Clearly it may be improved upon.

A More Informed Approach

At this point, I decided to to a bit of light research.  By “light” I mean I didn’t use any source deeper than Wikipedia.  It was there (see Wikipedia: Exact Cover) that I discovered the Exact Cover Problem, the Exact Hitting Problem, and Algorithm X (Wikipedia: Knuth’s Algorithm X)  by Donald Knuth. This provides us with an opportunity to display the value of abstraction in mathematics:  An algorithm that will solve problems about finite sets of integers and Sudoku puzzles with no transparent connection between the two.

The Exact Cover and Exact Hitting problems are stated in terms of finite sets and there is a good exposition of both and Algorithm X applied to both in the links given above.  It is shown how they can be translated into a problem about a finite bipartite graph.  The bipartite graph can then be translated into a matrix of zeros and ones (the incidence matrix of the bipartite graphs), and Algorithm X can then be applied to this matrix.

Were I teaching a class on this, I would work examples based on sets at this point, but since the sources above already does a nice job of that, let me instead proceed by explaining a way of thinking that led me to a better understanding of the problem at hand.

Activities and Requirements

The totality of a Sudoku puzzle, especially using the model we will be using, is quite a big thing.  Let’s think first about a smaller problem: Graduating from school.  In order to graduate from school, there are certain requirements we must meet.  To meet these requirements, there are certain activities we can engage in. If you want to think about this as a graph, you can list the activities on the left side of a piece of paper; list the requirements on the right; and then connect each activity to the requirements it satisfies by  line segments.  Since the requirements for a given school can still be ridiculously complicated, let’s look at a simple one below.

Wildwood Academy

Wildwood Academy is an institution of higher learning not too far from here.  At Wildwood Academy, there are six requirements that need to be met.  They are denoted as follows: Woodsmanship, Nature, Religion, Culture, Survival, and Art.  The activities that are offered to satisfy these requirements are: Noodling, Moonshine, Shape Note Singing, Bible Study, Water Witching, Indian Lore, and Square Dancing.  While there has been (and no doubt will be) endless debate as to which activity satisfies which requirement, the following is what is currently on paper:
  1. Noodling satisfies Woodsmanship, Nature, and Survival;
  2. Moonshine satisfies Nature. (This has been debated vociferously.)
  3. Shape Note Singing satisfies Religion and Art;
  4. Bible Study satisfies Religion and Culture;
  5. Water Witching satisfies Woodsmanship, Nature, and Survival;
  6. Indian Lore satisfies Woodsmanship, Nature, and Culture; and
  7. Square Dancing satisfies Art.
These are summarized in a matrix as below:
The empty cells can be thought of as having zeros in them.

Like students everywhere, the folks who attend Wildwood Academy don’t necessarily want to take more classes than they have to take in order to satisfy their requirements.  Because of this, the rule has been legislated than no requirement can be satisfied twice.  This is ridiculous and self-defeating, of course, but it is nonetheless the rule.

We will state an algorithm formally in a later section, but before we will work through an example heuristically, explaining our reasons as we go alone.  The example is in the figure below which will be explained by the text that follow the images:


Heuristically, we want to make sure the requirements are satisfied, so we first choose the requirements that have the fewest activities that satisfy them.  For example, Religion, Culture, and Art each have only two activities that satisfy them.  We choose religion because it is leftmost and for no other reason.

Religion is satisfied by Shape Note Singing and Bible Study.  We choose Shape Note Singing because it is listed before Bible Study and for no other reason.  Observe that Shape Note Singing satisfies Art in addition to Religion.  Since Art and Religion are satisfied and we don’t want anything satisfied twice we eliminate the activities that satisfy those.  We are are left with Woodsmanship, Nature, Culture, and Survival to be satisfied and with Noodling, Moonshine, Water Witching, and Indian Lore to satisfy them.

Going to the next stage, we note that Culture has a single activity that satisfies it, namely Indian Lore.  Indian Lore also satisfies Woodsmanship, and Nature. As Woodsmanship and Nature are collectively satisfied by Noodling, Moonshing, and Water Witching, we remove them all.  Having done this, all of the activities have been removed, but the Survival requirement remains.  We must back up.

Going up one level is not even as there was no choice of activities there. We must go to the first level.  There we chose between Shape Note Singing and Bible Study.  Let’s choose Bible Study on this occasion.  Doing this will drive us to choosing Square Dancing which, in turn, will drive us to choose Noodling.  

We may check this against the original matrix to verify that Noodling, Bible Study, and Square Dancing will satisfy Wildwood Academy’s requirements.

Algorithm X

It is my hope that the previous example will provide motivation for Algorithm X but, failing that, will at least provide enlightenment for someone trying to understand the algorithm.

I am not presenting Algorithm X in its greatest generality, but in a form that more transparently connects with our application.  With this caveat, let me say that the algorithm assumes that, as in our example, we are trying to satisfy each of our requirements with exactly one activity, and that we have our activities and requirements organized in an incidence matrix as in that example.

The Algorithm

  1. If your matrix has no columns, you are done as all of your requirements have been satisfied.
  2. Choose the column of your matrix that has the fewest ones.  (This assumes that no column has zero ones.)
  3. Collect all of the rows that are incident to your column and put them on a stack.  You will return to this stack if the algorithm hits a dead end. 
  4. Pop a row off of that stack created in step 3.  Push this onto a new stack called the partial solution stack.
  5. Take the newest row from the partial solution stack and determine all of the columns it is incident to. Determine all of the rows that are incident to all of these columns; this will include the original row.  Create a new matrix by dropping all of these rows and columns.
  6. If this new matrix has a column that is all zeros, pop the row off of the top of the partial solution stack and go back to step 4. Otherwise apply step 1 recursively to the new matrix.
It turns out that this matrix is easy to implement when one uses a pandas dataframe as a matrix.

Setting up the Matrix for Sudoku

We will now describe how this algorithm can be used to solve a Sudoku puzzle that the construction of an appropriate matrix.  Earlier we listed out the rules of Sudoku.  Let’s do it again thinking more specifically in terms of the context of requirements and activities, using precise symbolism.

Requirements

  1. RrCc is the requirement of having some value in the cell RrCc.
  2. Rr#v is the requirement of having the value v in the row Rr.
  3. Cc#v is the requirement of having the value v in the column Cc.
  4. Bb#v is the requirement of having the value v in the block Bb.
There are 81 each of the requirements (1) through (4) which comes to a total of 324 requirements.

Activities

What are the activities?  The sole type of activity consists of putting a particular value in a particular cell.  We will let RrCc#v denote the activity of putting the value v in the cell RrCc.  There are 81 cells with 9 values, so the comes to 729 activities.  Our matrix will by 729 by 324.  What will its entries be?

Matrix Entries in General

Note that RrCc#v satisfies RrCc, Rr#v, Cc#vk, and Bb#v, where b is calculated as in the section on the structure of the Sudoku board. Conversely, note that RrCc is satisfied by RrCc#w for any value w; Rr#v is satisfied by RrCd#v for any column Cd; Cc#v is satisfied by RsCc#v for any row Rs; and Bb#v is satisfied by RsCd#v for any s, d that will yield b according to our formula.

The Matrix for a Particular Puzzle

As was noted before, the incidence matrix for all activities and all requirements is 729 by 324.  However, each Sudoku puzzle begins with some cells that have already been filled in.  That is some activities have already satisfied some requirements.  This means we will have to drop some rows and columns from our matrix before we apply Algorithm X to it.

Let us consider the puzzle that has initial data as below:
Note that there are 29 cells that have been filled in with values; 29 activities have been completed.  Rather can calculate all of the rows and columns to be eliminated with all of these activities, let’s pick one activity that is not too special: R2C4#1.

It is easy to see at once the following requirements are satisfied: R2C4, R2#1, C4#1, and B2#1 so that the corresponding columns will have to be eliminated, but it doesn’t stop there.  Rows corresponding to the following activities:

R2C4#1, R2C4#2, R2C4#3, R2C4#4,..., R2C4#9
R2C1#1, R2C2#1,R2C3#1, R2C4#1,..., R2C9#1
R1C4#1, R2C4#1, R3C4#1, R4C4#1,..., R9C4#1
R1C4#1, R1C5#1, R1C6#1, R2C4#1, R2C5#1, R2C6#1, R3C4#1, R3C5#1, R3C6#1
will also have to be eliminated. 

Perhaps I am making a mistake in giving so much emphasis to this part of the implementation but I lots many fruitless hours in debugging my implementation of Algorithm X because I got the matrix wrong.

Once the initial matrix is modified with respect to the initial data, Algorithm X works remarkably well in producing a solution.  For example, the puzzle that took 3537 seconds to solve with the Naive program was solved in just over a second by Algorithm X.

Concluding Remarks and Future Directions

While I am incredibly pleased by improving the execution time by a factor of 3000, I am still impressed that a human being could solve the puzzle twice as fast as a computer operating naively.  Those of you who have played Sudoku seriously--and some of you are very serious--know some shortcuts.  One question is whether these could be worked into an algorithm. Another question that has captured my interest, given my interest in Python computing, is whether machine learning (or artificial intelligence or whatever you call it) in the form of a neural network can be taught to solve Sudoku well.  I am putting this on my list for possible future activities.







Saturday, October 26, 2019

Next week, no algebra, I promise


By Bobby Neal Winters

I have made a mistake.  Worse than that, I have made a mistake in print.  Please let me explain.

Last week my column was about how 57 is not a prime number and how I know.  I talked about tests for divisibility by 2, 3, 5, and--most to my current point--7.  The first three tests are widely known and, in my day at least, were taught in primary school.  You might not remember them, but they were.
The test for divisibility by 7 was new even to me, and I hadn’t worked with it much.  Indeed, working on that column was the first time I’d ever applied it, so, of course, I applied it wrong.

Rather than show you what I did wrong again, let me explain it correctly this time.  Let us take a number, say 149, and determine whether it is divisible by 7 by this test.  I chose 149 because I know that it is not. There is an easy way that doesn’t use this test, but I don’t want to muddy the water.

Take the number and remove the last digit, 9.  This leaves 14.  Now take 14 minus 2 times 9 (which is 18).  This 14 minus 18 is -4, which is not divisible by 7, so 149 is not divisible by 7. 
Let’s make it a little harder.  Consider 358.  Note that 35 minus 16 is 19 and that 19--being prime--is not divisible by 7.

How would this have worked with the number 57 that we used last week?  Well 5-14 is -9 which is not divisible by 7, so 57 is not divisible by 7 either.

Now I seriously doubt that anyone caught my error because in the era of calculators and computers, very few people worry about arithmetic anymore.  No one would’ve looked at it much because newspapers disappear having an afterlife of lining dresser drawers or wrapping fish. 

An obscure local columnist such as myself can reasonably hope his mistakes might disappear with the Wednesday trash pick-up.  Even with columns on the internet, what we write might live forever, but it does so like the Ark of the Covenant in a giant warehouse.

I seek to correct my mistake for a couple of reasons.  The first of which is my education as a mathematician.  We are so boring, if we aren’t right, then what are we good for?  The second is I would like to model what I consider proper behavior is when a person makes a mistake. 

If you make a mistake, you should ferret it out yourself, before anyone else has a chance to do it, and own it.  Don’t double down on it: Own it.  Everyone makes mistakes.

If you don’t catch it first, do the same thing: Own it.

When I found the test for divisibility by 7, I was in a hurry and I didn’t read it carefully enough, so I misinterpreted it.  I compounded this mistake by not proving the result myself.  What did Ronald Reagan say? Trust but verify! 

I trusted the Internet, but I didn’t verify.

For those of you who have hung in this long, let me now prove the result.  It is a simple proof, but it will take some algebra, so it you aren’t in the mood for algebra, I will see you next week.

When I say remove the last digit of a number, I am saying take a number of the form 10x + y where x is any positive integer and y is an integer between 0 and 9.  When you remove the last digit.  This leaves you with x.  Then the number you get by subtracting 2 times the last digit is x - 2y. 

We say that 10x + y is divisible by 7 exactly when x - 2 y is.  How do we know this is true.  Well (10x + y) minus 10 times (x - 2y ) is 21y.  Now 21y is definitely divisible by 7.  It follows from this that (10x+y) is divisible by 7 exactly when (x - 2y) is.  This is because 10 is not divisible by 7.

See, simple.

Next week, no algebra.  I promise.

Bobby Winters, a native of Harden City, Oklahoma, blogs at redneckmath.blogspot.com and okieinexile.blogspot.com. He invites you to “like” the National Association of Lawn Mowers on Facebook. )


Sunday, August 4, 2019

8÷2(2+2)

8÷2(2+2)

By Bobby Neal Winters

It is a rare day when a bit of mathematics is in the news, and it is an even rarer one when it is a bit that experts and laypersons can talk about with equal confidence, equal accuracy, and be equally wrong.

Today is one of those days.

This is because the 8÷2(2+2) meme has been going around the Internet.  It is a corker to be sure. Is it 16? Is it 1? Is it a communist conspiracy?

Well, as with all such things we should treat it as a teachable moment and in several directions.  The first thing if ought to say is that if you type it into a computer program interpretive interface, like the IPython console, for instance, it will give you 16 every time.

This is not a definitive answer, however, because dealing with computer input and output is HARD and allowances have been made.  It has been a special case since computers came into existence and there have been multiple methods of dealing with it.  One of these was quite good and it was called Reverse Polish Notation (RPN), and if you ever owned an old-fashioned HP programmable calculator in the eighties, then you’ve used it.  As you may have guessed, there is something called Polish Notation (PN) as well that has been used in dealing with computer input. It would take us too far afield to discuss either of these, but there are nice articles on Wikipedia that discuss both.

Whenever I get to teach Elementary Statistics, I use an Excel spreadsheet for some applications and I’ve learned that dealing with multi step calculations can be confusing, so I teach coping mechanisms as I go along.  We approach them with care because everything has to be typed in in a linear fashion and we can’t use all of the methods that mathematicians standing in front of a blackboard or writing in longhand on a piece of paper have at their disposal.

This brings me to something that has bothered me since the first time I saw this meme: The used of the symbol ÷ for division.  I haven’t used it in years.  You cannot find it on a computer keyboard.  To type this into a computer, you write 8/2(2+2).  When I see this, the ambiguity pops right out at me.  I would teach students to write either (8/2)(2+2) or 8/(2(2+2)) so that the problem goes away.  That ÷ symbol was put in there on purpose to make a point.

My dad was a truck driver and truck drivers have a saying about the right of way in driving: He was right, but he dead right.  As a mathematician, I need to keep that sentiment alive. If you follow the order of operations (parenthesis, exponentiation, multiplication division, addition, subtraction) you will get 1.  However, you can’t count on computers do that; you can’t count on people walking around on the street to do that; therefore, you need to order your mathematical communications in such a way as to be as unambiguous as possible.

So I’ve answered the first two questions, 16 if you are a computer and 1 if you are a mathematician, what about the third, is it a communist conspiracy?

Maybe not communist, but the use of the ÷ symbol makes me believe there is something going on here that requires a bit of technical sophistication.  I had to look up how to get my computer to do that symbol.  Maybe it is easier for others, I will be open to learning that, but I had to use [control][shift]uf7 to get Google Docs to do it. Its use in this meme not only hides the ambiguity of this expression from professional mathematicians, it makes the question accessible to people who’ve had no exposure to mathematics beyond eighth grade arithmetic.  Is this good? Is this bad? I don’t know, but it is interesting.

Perhaps I am sensitive to this because there is a fairly steady stream of anti-mathematics education memes that go around in social media.  They hate the new methods of teaching subtraction; they hate the common core; they think we should stop teaching algebra all together and teach how to balance checkbooks instead (that is not an either or, by the way, we do both, but the second we don’t do in math class).

So the final lesson that should be taken away from this is that we who teach math can’t ignore this.  We must engage it in some way.

So the answer to 8÷2(2+2) is that we need to talk.

Bobby Winters, a native of Harden City, Oklahoma, blogs at redneckmath.blogspot.com and okieinexile.blogspot.com. He invites you to “like” the National Association of Lawn Mowers on Facebook. )

Monday, May 20, 2019

Coding and Essays

Coding and Essays

“A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.”
― Robert A. Heinlein

By Bobby Neal Winters

I like to program computers.
I began back in the late seventies when I was in my mid-teens on a TRS-80 microcomputer that my high school had bought.  The math teacher (there was only one) didn’t know how to program it or have the time to learn, so he flopped the manual down on my desk and said to figure it out.

So I did.

From that day until this, I’ve had exactly one class in programming...and it shows.

From day one, I’ve approached computer programming as a problem solver, a redneck problem solver.  You’ve no doubt seen those pictures on Facebook of someone who has put a ladder in the basket of a cherry-picker to get to some hard-to-reach place to paint. Most of the code that I’ve written over the course of my life has looked like that.  My programs have been like Rube Goldberg devices: they do what they are supposed to, but not necessarily in the most straightforward way.

There is a solution to this, and it is amazingly similar to the way to improve writing.  It is...wait for it...rewriting.  Learning to rewrite was a revelation to me.  The fact that my words were not necessarily fit to be carved on stone was a hard lesson to learn, but when I did learn, I was a massive step forward.  (There are no doubt those of you reading this now who would tell me that I need to do even more of it, and I would agree.)

We are reluctant to rewrite our prose for many reasons that may include but need not be limited to: writing is hard for us in the first place; we really don’t like to write; and our belief that what we’ve written is just so marvelous the way it came out of our heads that it couldn’t possibly be improved.
These particular reasons can be taken care of by practice.  The more we write, the easier it becomes.  When something becomes easier, it becomes more enjoyable.  And when we return to a piece, look at it, and not understand it even ourselves, the penny drops and we realize that not everything we write down is golden.

Rewriting computer code is quite similar. Sometimes the programming problem is so treacherous that we feel lucky there is any solution at all.  The thought of reworking the problem seems ridiculous. Why waste your time rewriting unreadable code, when you could use it do go out and write more unreadable code, hmmm?

One gets insights in coming back to code that you have written a year before, needing it to solve another problem, but not being able to use it because you cannot make heads or tails of it.  When this happens a time or two, you start trying to be clearer.  Once you’ve gotten your code to work, you go back over it and make sure that it will be readable to your future self.

If you start taking this stuff seriously, it has an effect on you.  You see how well it works.  The approach spreads into other areas of your life.  From writing, to computer programming, to you name it.  You learn that you can stick with a job until it is done right.

This habit is the product of an education. Don’t misunderstand me by thinking this can only happen in school. No, far from it. If you’ve learned this in your home from your hard-working parents, then you are way ahead when enter the world. 

I’ve seen a quote on my Facebook feed from my South American friends: La escuela es la segunda casa, pero la casa es la primera escuela.  This translates as: The school is the second home, but the home is the first school.  The habit of hard work and the desire to do something well set us on a pathway to success in our endeavors.

So whether you are coding a computer program, writing an essay, setting a bone,  fixing a car, or whatever other task you are doing, the idea of sticking with it until it’s done right will pay off.

Bobby Winters, a native of Harden City, Oklahoma, blogs at redneckmath.blogspot.com and okieinexile.blogspot.com. He invites you to “like” the National Association of Lawn Mowers on Facebook. )

Tuesday, September 25, 2018

How to Do Your Math Homework

By Bobby Neal Winters

The first thing you need is a place.  The place should be clean, comfortable, well-lit and free of distractions. A table in a fallout shelter would be ideal or a similar spot in a bathroom, but the dining room table would work nicely as well.

And you do need the table.  I’ve seen what your work looks like when you do it on your lap.  Egyptologists wouldn’t be able to read it.  Sit in a chair at a table and not on the sofa in front of the danged TV. It should be off anyway.

After you’ve got the place, you need to have the supplies in place: pencil, paper, calculator, and wastebasket.  I said pencil instead of pen and I meant it.  You will make mistakes, so the pencil should have an eraser. I’ve known profs who’ve insisted on pens.  They are insane sadists.  If you know one, send him to me and I will call him that to his face.  It won’t be a problem because he knows that already; he glories in it; that is why he does it.

You will need the paper, but that shouldn’t be a problem because paper is cheap.  Seriously, it is.  You can buy legal pads off Amazon for 4 cents a sheet. (Not that I would ever advise anyone to buy anything out of town.  The folks at the Chamber of Commerce know where I live.)  Don’t worry about cutting trees because those trees are grown for the very purpose of making paper.  If there wasn’t pulpwood being grown on that land, they’d be using it to make moonshine or grow pot.

And, this is a big thing: Use the paper.  I know young people who otherwise show no great concern for their parents’  resources but suddenly become misers when they are doing their math homework.  They will try to squeeze into two lines problems that should take up half the page.  

The “New Math,” which came in vogue about 50 years ago, took a lot of heat because it was about “how you did the problem and not getting the right answer.”  Okay, at the end of the day we do want to get the right answer, but we want to get the right answer the next time too; and the time after that.  Mathematics is about the process.  When a math teacher grades, he (she/it) looks not only at the answer--which often comes from someone else’s paper--but also grades the process.  The reason you want to have plenty of paper around--and use it--is so that you can run through the process in a manner his tired old eyes can see.

The word calculator might cause some eyebrows to raise because I am old-school in so many ways: I still come out of the classroom with chalk dust on my hands.  I do believe in mental arithmetic.  You should just know that 25 squared is 625.  There will, however, be times in your life when you will need to know 4 divided by 7 to three decimal places.  While you should be able to do that with paper and pencil, when you go out into the world, your boss will want you spending your time--his money--in the most efficient means possible.  

This means you need to be able to use a calculator.

A calculator is like any other machine. You have to learn how to use it.  You don’t just sit down at a piano and expect to be able to play a concert. You don’t climb behind the controls of a bulldozer and expect to be able to dig a pond.  Why do you expect to be able to sit down with a calculator and be able to work your exam?

Okay, you’ve got a place; you’ve got the equipment. One more thing: Do it!

Don’t just sit there counting the text messages coming in; that phone should be off! Do the work.  If you don’t know how to do it, look at the notes you took of the examples that were worked.  If you didn’t take notes, open the book or use the Powerpoint slides and try to replicate what the teacher did.  Our school motto is: “By doing, learn.” This works well with math. Or, to put it more accurately, if you don’t do it, you are not going to learn.

Okay, what are you waiting for? Get to work!