# OSDev.org

The Place to Start for Operating System Developers
 It is currently Wed Jan 24, 2018 3:27 am

 All times are UTC - 6 hours

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Course - Mental Calculation of the CalendarPosted: Fri Sep 30, 2016 8:53 pm
 Member

Joined: Tue Mar 06, 2007 11:17 am
Posts: 1084
Week 1 - Calculating the Calendar Mentally. Learning the Sequence of Days 1 to 31.

This is a short course about an algorithm to calculate the calendar using only simple arithmetic mental calculations.

Currently there's only 1 video for Week 1, but it should give enough time to understand each part of the course in a fine-grained manner.

The algorithm is very lightweight so it is suitable to allow for mental usage and calculations with it, so it should also be extremely simple, optimized and lightweight if used to implement a date managing application, for example in an open source BIOS or in a kernel.

It isn't about calculating a timestamp but the actual day numbers 1-31 and its corresponding weekday names.

Quote:
Calculating the Calendar Mentally.
Learning the Sequence of Days 1 to 31.

The first thing we need to learn to mentally calculate the calendar is learning the sequence of the days in vertical order. It will allow us to reach all weeks of the month fast for any day, will also allow us to obtain all the day numbers for every weekday.

The only other thing that we must never forget is the weekday name in which the month starts, and also the number of days in that month. We simply must memorize that, and normally it's enough to memorize it for the current month. Over time it will become more routinary to remember those details.

We have months with 28, 29, 30 and 31 days, but if we learn the sequence for 31 days we can calculate any day of shorter months.

The following is the verbal sequence we need to learn. A single line is the sequence for a single weekday. The month can start at any day, so the sequence for day 1 or the rest of these sequences can fall at any weekday name:

1, 8, 15, 22, 29.
2, 9, 16, 23, 30.
3, 10, 17, 24, 31.
4, 11, 18, 25.
5, 12, 19, 26.
6, 13, 20, 27.
7, 14, 21, 28.

Just memorize the previous numbers and see if you can then inspect the calendar for the current month and match this sequence with the sequence for the actual month that you are interested in. There are only 7 weekdays so this list can only start in 7 different ways, but this same sequence is used for all 7 combinations.

Now see if you can determine the first day of the week without looking at the calendar as well as the last day. Practice with other days as you need them.

Determining the Last Day.

We have months with 28, 29, 30 and 31 days.
28-day months end the weekday before they started.
29-day months end the same weekday in which they started.
30-day months end the next weekday from which they started.
31-day months end two weekdays after the one in which they started.

The first day of the following month is simply the very next weekday for any of the last weekdays we just described.

Now see if you can calculate the last weekday for this month and then the first weekday for the next month by advancing to the following weekday.

Now also try to calculate the weekday of several birthdays or deadline weekdays for when you need to finish or pay something. Also try to calculate the weekdays for the next Saturday and Sunday.

_________________
http://devel.archefire.org/forum/
http://www.archefire.org/_PROJECTS_, http://sourceforge.net/u/udocproject/

IP for hosts file:
190.150.9.244 archefire.org (udocproject@yahoo.com)

Top

 Post subject: Course - Mental Calculation of the Calendar (Week 2)Posted: Fri Oct 07, 2016 10:15 pm
 Member

Joined: Tue Mar 06, 2007 11:17 am
Posts: 1084
Week 2 - Calculating the Calendar Mentally. Calculating Freely for Any Month.

Quote:
We must remember the first weekday of the year, whether it's a leap year, and the following sequence of numbers below. If it isn't a leap year, we must calculate the sequence normally and then substract 1, and it applies from February.

This sequence applies with 0 for January since it's the starting point, and then from February to the first day of the next year.

To manually know whether this is a leap year, we simply need to see if February is 29 days long. If it only has 28 days, then it isn't a leap year.

Also in general, if this year is exactly divisible by 4, then it's a leap year. It might be that it doesn't apply for all existing years, but it's the minimum consideration that we can determine calculating only mentally in a simple way.

We must learn the following sequence of numbers for being able to calculate the initial day of any month. Each one of these numbers corresponds to each one of the months of the year, from January to December, and the last individual number corresponds to the first day of the next year.

0, 3, 5, 1.
3, 6, 1, 4.
7, 2, 5, 7.
3.

Examples of leap years are 2000, 2004, 2008, etc.

We could learn:
- The number of a specific special year. For example 1984.
- The first weekday of that year. Sunday in this case.
- And whether it's a leap year or not. In this case it is.

Just with that and with our techniques so far, we can now calculate any day of that year.

Now try to determine the first day of November 2016 and November 2 2016. 2016 started in Friday, it's a leap year because February has 29 days. 2016 is divisible exactly by 4.

For November it corresponds to us to advance 5 days and since it's a leap year we have to advance those 5 days instead of 4 days, to reflect that February 29 is present. So, since we started the first day of the year in:

Friday.

If we now advance 5 days, starting from the initial weekday of the year, we have:

Friday, Saturday, Sunday, Monday, Tuesday.

So November 1 2016 falls in Tuesday, and obviously November 2 falls in Wednesday.

_________________
http://devel.archefire.org/forum/
http://www.archefire.org/_PROJECTS_, http://sourceforge.net/u/udocproject/

IP for hosts file:
190.150.9.244 archefire.org (udocproject@yahoo.com)

Top

 Post subject: Re: Course - Mental Calculation of the CalendarPosted: Sat Oct 08, 2016 12:43 am
 Member

Joined: Sat Mar 31, 2012 3:07 am
Posts: 3042
Location: Chichester, UK
Is this a joke, or just an insult to our intelligence?

Whatever, it is not an Announcement, Test Request, or Job Opening.

Top

 Post subject: Re: Course - Mental Calculation of the CalendarPosted: Sat Oct 08, 2016 2:08 am
 Member

Joined: Thu Mar 10, 2016 7:35 am
Posts: 134
Location: Lancaster, England, Disunited Kingdom
Well I was taught a method for doing it for any date of any year of any century in the Gregorian calendar and it took a 5 minute interlude in the middle of a Maths lecture in 1972. I've used it ever since. The method in this thread looks far too complicated for me. But then - the man that taught me also invented Life!

Top

 Post subject: Re: Course - Mental Calculation of the CalendarPosted: Sat Oct 08, 2016 3:54 am
 Member

Joined: Tue Dec 25, 2007 6:03 am
Posts: 702
Location: Perth, Western Australia
I have to agree with @iansjack - this is off-topic both for this forum, and for the entire site. Locking thread.

_________________
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 5 posts ]

 All times are UTC - 6 hours

#### Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ Operating System Development    OS Development    OS Design & Theory    Announcements, Test Requests, & Job openings Everything Else    General Programming    General Ramblings    Auto-Delete Forum OSDev.org    OSDev Wiki    About this site