All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
Fifth Thursdays and Sundays (Posted on 2022-05-17) Difficulty: 3 of 5
  • There are two clubs, X and Y. Club X meets on fourth Thursday of odd numbered months and fourth Sunday of even numbered months. That is, Club X meets on fourth Thursday of January, followed by fourth Sunday of February, followed by fourth Thursday of March...., and so on.
  • Club Y meets on last Thursday of every odd numbered months, and last Sunday of every even numbered months.
  • Arne is a member of both the clubs and wants to attend all the meetings hosted by the two clubs. Now, fourth Thursday is usually the last Thursday and fourth Sunday is usually the last Sunday of a given month. However, in some odd numbered months there are five Thursdays and some even numbered months have five Sundays. In each of these months Arne can attend both the meetings.

      (A) Devise an algorithm to determine all the fifth Thursdays of odd numbered months and fifth Sundays of even numbered months that have them and set it to calculate them for 14 years. You are given subroutines that convert Gregorian calendar dates to and from JD numbers, which are the number of days a given date is past a certain fixed date in the distant past (more than 6,000 years ago). You also have a virtual 2023 C.E. calendar available that intimates that January 5, 2023 will be a Thursday.

      (B) Utilize the above algorithm to calculate the total number of meetings of both the clubs that Arne will be attending from January 1, 2023 to December 31, 2036 inclusively,
      In which of these 14 years will Arne be able to attend a maximum number and a minimum number of meetings?

      *** Assume that Arne will attend the meeting of one of the clubs whenever the dates of the meeting of the two clubs coincide.

No Solution Yet Submitted by K Sengupta    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution solution as I think intended Comment 1 of 1
(A) The fact that 14 years is asked for makes one think that what is sought is years of all 14 types--ordinary vs leap, and beginning on any of the 7 days of the week. But 14 years in a row will not produce this complete set as there are only three or four leap years in such a consecutive set, which thus cannot be all seven beginning days of the week.

So for part (A) I made up this table, showing for each of the 14 types of year, the appropriate months with five Thursdays or Sundays as appropriate for the parity of the month number:

Year       Starting    List of day of week with month number
type          On
ordinary     Sunday    Th  3; Su  4; Su 10; Th 11; Su 12;
ordinary     Monday    Th  3; Su  4; Th  5; Th 11; Su 12;
ordinary    Tuesday    Th  1; Th  5; Su  6; Su 12;
ordinary  Wednesday    Th  1; Th  5; Su  6; Th  7; Su  8;
ordinary   Thursday    Th  1; Th  7; Su  8;
ordinary     Friday    Th  7; Su  8; Th  9; Su 10;
ordinary   Saturday    Th  3; Th  9; Su 10;
    leap     Sunday    Th  3; Su  4; Th  5; Th 11; Su 12;
    leap     Monday    Th  5; Su  6; Su 12;
    leap    Tuesday    Th  1; Th  5; Su  6; Th  7; Su  8;
    leap  Wednesday    Th  1; Th  7; Su  8;
    leap   Thursday    Th  1; Su  2; Th  7; Su  8; Th  9; Su 10;
    leap     Friday    Th  3; Th  9; Su 10;
    leap   Saturday    Th  3; Su  4; Su 10; Th 11; Su 12;
    
The program builds up a yearGrid, showing the number of club meetings Arne can attend in the calendar year:

         ordinary  leap
   Sunday  17       17
   Monday  17       15
  Tuesday  16       17
Wednesday  17       15
 Thursday  15       18
   Friday  16       15
 Saturday  15       17
 
There are a minimum of 15 and maximum of 18 in a given year.


The above was produced by the first part of the program:

clearvars, clc
ordinary=[31 28 31 30 31 30 31 31 30 31 30 31];
leap=[31 29 31 30 31 30 31 31 30 31 30 31];

dNames=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];

for typeY=["ordinary","leap"]
  for start=[1:7]
    totInTypeStart=0;
    eval(['lengths=' char(typeY) ';']);
    sunday1=9-start; 
    if sunday1>7
      sunday1=sunday1-7;
    end
    fprintf('%8s %10s',typeY,dNames(start));
    for mo=1:12
      thursday1=sunday1+4;
      if thursday1>7
        thursday1=thursday1-7;
      end
      if mod(mo,2)==1
        thursday5=thursday1+28;
        if thursday5<=lengths(mo)
          fprintf(' Th %2d;',mo);
          totInTypeStart=totInTypeStart+1;
        end
        totInTypeStart=totInTypeStart+1;
      else
        sunday5=sunday1+28;
        if sunday5<=lengths(mo)
          fprintf(' Su %2d;',mo);
          totInTypeStart=totInTypeStart+1;
        end      
        totInTypeStart=totInTypeStart+1;
      end
      sunday1=sunday1+28-lengths(mo);
      if sunday1<1
        sunday1=sunday1+7;
      end
    end
    fprintf('\n');  
    yearGrid(start,1+(typeY=="leap"))=totInTypeStart;
  end
end

January 1, 2023, will be a Sunday, and that year is the year before a leap year. So the second part of the same program uses the grid built in the first part:

start=1;
for yr=2023:2036
  fprintf('%4d ',yr);
  if mod(yr,4)==0
    fprintf('leap     %12s',dNames(start));
    fprintf(' %2d',yearGrid(start,2));
  else
    fprintf('ordinary %12s',dNames(start))
    fprintf(' %2d',yearGrid(start,1));
  end  
  fprintf('\n')
  
  start=start+1;  % ordinarily new year starts with next day of week
  if mod(yr,4)==0   % mod valid only between 1901 and 2099
    start=start+1;  % leap year leaps over that day to the next
  end               
  if start>7
    start=start-7;
  end
end

producing

part (B)
year  type       beginning   number of
                       on     meetings
                       
2023 ordinary       Sunday       17
2024 leap           Monday       15
2025 ordinary    Wednesday       17
2026 ordinary     Thursday       15
2027 ordinary       Friday       16
2028 leap         Saturday       17
2029 ordinary       Monday       17
2030 ordinary      Tuesday       16
2031 ordinary    Wednesday       17
2032 leap         Thursday       18
2033 ordinary     Saturday       15
2034 ordinary       Sunday       17
2035 ordinary       Monday       17
2036 leap          Tuesday       17

The maximum number of meetings, 18, is indeed achieved in 2032, as this 14-year period does include a leap year beginning on a Thursday.

The minimum, 15, occurs in 2024, 2026, and 2033.

A complete cycle, between the years 1901 and 2099 contains 28 years: one of each leap year beginning day and four of each ordinary year with any given starting day of the week.

From 2033 through 2099, it's

2023 ordinary       Sunday 17
2024 leap           Monday 15
2025 ordinary    Wednesday 17
2026 ordinary     Thursday 15
2027 ordinary       Friday 16
2028 leap         Saturday 17
2029 ordinary       Monday 17
2030 ordinary      Tuesday 16
2031 ordinary    Wednesday 17
2032 leap         Thursday 18
2033 ordinary     Saturday 15
2034 ordinary       Sunday 17
2035 ordinary       Monday 17
2036 leap          Tuesday 17
2037 ordinary     Thursday 15
2038 ordinary       Friday 16
2039 ordinary     Saturday 15
2040 leap           Sunday 17
2041 ordinary      Tuesday 16
2042 ordinary    Wednesday 17
2043 ordinary     Thursday 15
2044 leap           Friday 15
2045 ordinary       Sunday 17
2046 ordinary       Monday 17
2047 ordinary      Tuesday 16
2048 leap        Wednesday 15
2049 ordinary       Friday 16
2050 ordinary     Saturday 15 ________
2051 ordinary       Sunday 17
2052 leap           Monday 15
2053 ordinary    Wednesday 17
2054 ordinary     Thursday 15
2055 ordinary       Friday 16
2056 leap         Saturday 17
2057 ordinary       Monday 17
2058 ordinary      Tuesday 16
2059 ordinary    Wednesday 17
2060 leap         Thursday 18
2061 ordinary     Saturday 15
2062 ordinary       Sunday 17
2063 ordinary       Monday 17
2064 leap          Tuesday 17
2065 ordinary     Thursday 15
2066 ordinary       Friday 16
2067 ordinary     Saturday 15
2068 leap           Sunday 17
2069 ordinary      Tuesday 16
2070 ordinary    Wednesday 17
2071 ordinary     Thursday 15
2072 leap           Friday 15
2073 ordinary       Sunday 17
2074 ordinary       Monday 17
2075 ordinary      Tuesday 16
2076 leap        Wednesday 15
2077 ordinary       Friday 16
2078 ordinary     Saturday 15______________
2079 ordinary       Sunday 17
2080 leap           Monday 15
2081 ordinary    Wednesday 17
2082 ordinary     Thursday 15
2083 ordinary       Friday 16
2084 leap         Saturday 17
2085 ordinary       Monday 17
2086 ordinary      Tuesday 16
2087 ordinary    Wednesday 17
2088 leap         Thursday 18
2089 ordinary     Saturday 15
2090 ordinary       Sunday 17
2091 ordinary       Monday 17
2092 leap          Tuesday 17
2093 ordinary     Thursday 15
2094 ordinary       Friday 16
2095 ordinary     Saturday 15
2096 leap           Sunday 17
2097 ordinary      Tuesday 16
2098 ordinary    Wednesday 17
2099 ordinary     Thursday 15

  Posted by Charlie on 2022-05-17 12:27:15
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (9)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information