1

So, I was trying to express the formula for determining the next year on which a given date (month/day) will fall on a given weekday.

The internet has plenty of sites that explain how to determine the weekday of an arbitrary date (at least up through the 39th century). So I was able to get a good start.

The mod 7 of an offset number which can be calculated using specific formulas for day, month, year, and century will provide the "day number" of that date. So, for desired day number of X where the Do = the Day offset for the day of the month and Mo = the month offset for the month of the year, and y = the year we want to find ( and where X, Do, and Mo are known) we can say that

X-(Do +Mo)%7 = ((((39 - (floor(y/100)))%4)*2) % 7 + ((y%4) + (y%4)/4) % 7)%7

So in theory, all I have to do is solve for y, take the minimum and I have the next year that a month/day will fall on a particular weekday. However I quickly realized that I don't have the first clue how to begin solving for y when there is a modulus operation in the expression.

So I'd love help solving for y (and a check on my logic in constructing the above), or as a minimum, help with how to deal with modulus in solving/simplifying/reducing/operating on an algebraic expression.

Robert
  • 123
  • Does it need to be a single expression consisting of the symbol $y$, numbers, mathematical operators, and standard functions? I've always done all but the most trivial date calculations as a sequence of operations, sometimes with iteration. I find them much easier to understand that way, and it seems they're usually just about as efficient (using few operations) as you can get. – David K Aug 06 '14 at 21:30
  • Yes, it needs to be a single expression in the form of y = f(x,do,mo). I agree it's trivial to solve as a series of iterative steps. I can write the program to do it in short order. So its just for fun (recreational-mathematics) that I want to be able to express it as an equation. I know intuitively that it can be expressed, but I just don't know how to manipulate the above to get y off to one side. – Robert Aug 07 '14 at 01:18
  • I suppose $y%4$ is the remainder after integer division of $y$ by $4$; but what is the purpose of $(y%4)/4$ in the formula? It appears to evaluate to one of the numbers $0, \frac14, \frac12, \frac34$. – David K Aug 07 '14 at 19:48

1 Answers1

0

Here are some possibly helpful facts.

If March 1 falls on the same day of the week in the year $x$ and in the year $y$, then every other day from March 1 through December 1 falls on the same day of the week in the year $x$ and the year $y$, and every day from January 1 through February 28 falls on the same day of the week in the year $x + 1$ and in the year $y + 1$. So to know how many years pass before a date falls on the same day of the week again, you just need to find the formula for March 1; you can apply it for any date, except that you have to subtract $1$ from the year number in that formula when the month is January or February.

Define the sequence $a_0, a_1, a_2, ...$ as follows:

$$ \begin{eqnarray} a_0 = a_1 & = & 6 \\ a_2 & = & 11 \\ a_3 & = & 5 \\ a_n & = & a_{n-4} \ \ \mbox{for $4 \le n < 88$} \\ a_{88} = a_{89} & = & 6 \\ a_{90} & = & 12 \\ a_{91} & = & 5 \\ a_{92} = a_{93} = a_{94} = a_{95} & = & 6 \\ a_{96} & = & 7 \\ a_{97} & = & 12 \\ a_{98} = a_{99} & = & 6 \\ a_n & = & a_{n-100} \ \ \mbox{for $100 \le n < 300$} \\ a_{300} = a_{301} & = & 6 \\ a_{302} & = & 11 \\ a_{303} & = & 5 \\ a_n & = & a_{n-4} \ \ \mbox{for $304 \le n < 400$} \\ \end{eqnarray} $$

Then March 1 in the year $2400 + k$ next falls on the same day of the week in the year $2400 + k + a_k.$

The number of years until February 29 falls on the same day of the week is longer, because there is not a February 29 every year. Define $$ \begin{eqnarray} b_0 & = & 28 \\ b_n & = & b_{n-4} \ \ \mbox{for $4 \le n < 72$ such that $b_{n-4}$ is defined} \\ b_{72} = b_{76} = b_{80} = b_{84} = b_{88} & = & 40 \\ b_{92} = b_{96} & = & 12 \\ b_n & = & b_{n-100} \ \ \mbox{for $104 \le n < 300$ such that $b_{n-100}$ is defined} \\ b_{304} & = & 28 \\ b_n & = & b_{n-4} \ \ \mbox{for $308 \le n < 400$ such that $b_{n-4}$ is defined} \\ \end{eqnarray} $$ Then February 29 in the year $2400 + k$ next falls on the same day of the week in the year $2400 + k + b_k.$ Other values of $b_n$ are undefined, because there is no February 29 in the corresponding year.

David K
  • 98,388