Monday 1st January

29Dec13

In the twelve months from March 2013 to March 2014, I programmed solutions to the problems posted on the Contest Coding blog run by Lewis Cornwall, solving 33 problems (out of 47) and achieving a position of 4th on the leaderboard (out of 23).

As that blog has now been discontinued, I’m posting here the solutions I programmed to those problems.

Monday 1st January

Happy New Year from contestcoding!

Find the number of years between 0 AD to 2014 AD that have began (on the 1st January) on a Monday.

Solution and answer (Monday 1st January.pas):

Uses: lib_seal_calendar.

{$R+}
program Monday_1st_January( output );
{
Solution and answer for problem "Monday 1st January" (29th December 2013) of http://ContestCoding.WordPress.com/

282 years between 0 A.D. and 2014 A.D. (inclusive) begin (on the 1st of January) on a Monday.

Solution programmed in Pascal using Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition); solution took ~4s to run on a 80MHz PowerPC 601.
}
uses
  lib_seal_calendar;
var
  year : -1..2014;
  month : 0..12;
  day : 0..31;
  day_of_week : 0..7;
  total : 0..maxint;
begin
  year := 2014;
  month := 1;
  day := 1;
  day_of_week := 3;
  total := 0;
  repeat
    if ( day = 1 ) and ( month = 1 ) and ( day_of_week = 1 ) then
      total := total + 1;
    day := day - 1;
    if day = 0 then begin
      month := month - 1;
      if month = 0 then begin
        year := year - 1;
        month := 12
      end;
      day := f_NumberOfDaysInMonth( month, year )
    end;
    day_of_week := day_of_week - 1;
    if day_of_week = 0 then
      day_of_week := 7
  until year = -1;
  writeln( total, ' years between 0 A.D. and 2014 A.D. (inclusive) begin (on the 1st of January) on a Monday.' )
end.
Advertisements


No Responses Yet to “Monday 1st January”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: