in reply to How preparing the weekly shift roster led to a fascinating discovery...

Sometimes we run away with ourselves ...

You don't have to test all years, nor 400 years, not even 14 years or 7!

Considering just one year (any year you wish) is enough.

This might seem surprising, but it really isn't. As long as you don't start your year on the 1st of January, but on the 1st of March.

Suppose, the 1st of March is a Monday then:

As you can see there is never a "+3" in the above sequence, meaning that the 31st will miss "day + 3" (where day 1 is the day of 1st of March).

Because of leap years the last day of January can at the most shift one day, but as it is on the "+0" spot, it can never make it to the "+3" spot, hence "day +3" is always missing for the 31st.

QED

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

  • Comment on Re: How preparing the weekly shift roster led to a fascinating discovery...

Replies are listed 'Best First'.
Re^2: How preparing the weekly shift roster led to a fascinating discovery...
by lidden (Curate) on Dec 14, 2007 at 22:31 UTC
    Very nice++.

    But there is a little thinko in there. Because Jan 31 next year is a +0 day next year does not mean it is this year. For a non leap year it is +6 and +5 for a leap year.

      Yes, but it doesn't matter for the problem at hand. January of the previous year can at most be one day off its normal, non-leap day, but it can never become a "+3".

      To explain in a bit more detail what you have already found: As a normal year has 52 weeks and one day, January of the same year must thus be a "-1" (or "+6") compared to the day of the 1st of March of the same year.

      In a leap year, (52 weeks and two days) January 31st will be a "-2" (or "+5") day, but it can never ever be a "+3" day.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re^2: How preparing the weekly shift roster led to a fascinating discovery...
by McDarren (Abbot) on Dec 15, 2007 at 04:13 UTC
    mmm, yes.. that is a nice bit of deductive reasoning, but...

    What if you hadn't of know beforehand that the 31st was the _only_ one that missed out?

    I mean, once glide let the cat out of the bag and the result was obvious, then it becomes much easier to apply a bit of backwards logic to explain the phenomena.

    Of course, I didn't know what the result would look like until I'd written some code to test it. And once the code was written, it became a simple matter to modify it to test for as many years as I wished.

    By the way..

    Because of leap years the last day of January ..
    Don't you mean February?

    Cheers,
    Darren :)

      What if you hadn't of know beforehand that the 31st was the _only_ one that missed out?
      Then I would never have given the matter a single thought.

      But ... consider this: someone finds a curious phenomenon and reports it to his fellow scientists. These start running a number of experiments which prove or disprove this phenomenon in a variety of circumstances. Then someone steps in and formulates a theory and finally someone proves (based upon the existing body of scientific knowledge) that the theory is correct.

      I think we just have witnessed the scientific method at work in our Monastery!

      Don't you mean February?
      No no, I really mean January. February never has 31 days, so by starting my "year" in March (as did the old Romans -- why do you think September really means the seventh month?) my reasoning does not have to take into account leap years but for the month of January (which as lidden said can only be a "+5" of "+6" day but never a "+3".) thus making my proof much easier and clearer.

      Shall we --in line with good scientific practice and hubris-- call this theory the "McDarren-CountZero-lidden Theory of the Missing Weekday of the 31st"?

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      If you restrict to months different from february, all of them have at least 30 days and you can easily see that "having" days 1..7 always gives you all the days up to 30 (just write numbers 1..30 putting a newline every 7 of them). Restricting to months from march to december (which always present the same pattern, whatever year you consider after the transition from Julian to Gregorian calendars) you can quickly check that all days 1..7 are there for all days of week (it suffices to see it for only one of them, then that's only a matter of modulo-7 maths).

      So the only one that remains tricky is 31, because not all months "support" it.

      Flavio
      perl -ple'$_=reverse' <<<ti.xittelop@oivalf

      Io ho capito... ma tu che hai detto?