There is one nice property of the real data: it is guaranteed to be a real month - it will be output as part of the UNIX 'date' command. So we don't have to worry about words that are not months. Our function can return any number it likes.
We will encode each letter as a number and add them up the result will be the number of the month.
The fun is in finding a suitable code...
Since we have 19 unknowns and only 12 constraints we can expect there to be several solutions -- there should be 7 letters that we can have any value we like, and then 12 will be determined by our chosen values. There is of course a possibility that no set of values for our variables can possibly satisfy all 12 constraints. If so we will find a variable that has to have two different values.
We will write it in algebraic form with single lower case letters standing for the codes of the corresponding character. So we start by listing the months (on a piece of paper) and then the letters that appear in them:
Now I have several ways to tackle these:
Go an buy a linear algebra package.
Go and hire a mathematician.
Go to the library and look up the algorithms....
. . . . . . . . . ( end of section Alternative Approaches) <<Contents | End>>
It was only when I came to write up how I found the solutions that I found I had made several errors... including one that should have seen when I tested the code.... But such is the strength of ego that I could not see my own errors....
Learn from this.... it is not enough to test a program, you have to be able to explain why it works.
So here is my reconstruction of how I should have tacked it. Please check for mistakes.
This works because of one of Euclid's Axioms: subtracting equals from equals gives equals.
More importantly, the original pair of equations can be replaced by a pair where one is much simpler.
Jun and Jul are nearly the same.
Jun and Jan are nearly the same.
Mar and Apr are similar.
Mar and May are almost the same.
So I have a new set of equations that are indeed similarly to the original set:
Now
I have a visual brain - it needs pictures so I sketched out a picture where each equation with 3 unknowns was a triangle and each equation with two unknowns was a line.
I found it easy to place values on this diagram and work out the consequences.
In the code I assumed the following:
These are the values expressed in the code.... [ months.cc ]
I was reviewing your developement of the "months" function, URL
http://www.csci.csusb.edu/dick/samples/months.html
In the final code (beginning with Let{(2.14) ...) I don't see
any value for the letter "j"!
Paul E. Black p.black@ieee.org
Reply: Thank you - I have added [ 2.26 ] above. I took the oportunity to fix a typo in [ 2.17 ] where it used to say n=1 rather than l=1.
. . . . . . . . . ( end of section Comments by Readers) <<Contents | End>>