|
1 | 1 | # Description
|
2 | 2 |
|
3 |
| -In this exercise, you will be given a general description of a meetup date and then asked to find the actual meetup date. |
| 3 | +Recurring monthly meetups are generally scheduled on the given weekday of a given week each month. |
| 4 | +In this exercise you will be given the recurring schedule, along with a month and year, and then asked to find the exact date of the meetup. |
4 | 5 |
|
5 |
| -Examples of general descriptions are: |
| 6 | +For example a meetup might be scheduled on the _first Monday_ of every month. |
| 7 | +You might then be asked to find the date that this meetup will happen in January 2018. |
| 8 | +In other words, you need to determine the date of the first Monday of January 2018. |
6 | 9 |
|
7 |
| -- First Monday of January 2022 |
8 |
| -- Third Tuesday of August 2021 |
9 |
| -- Teenth Wednesday of May 2022 |
10 |
| -- Teenth Sunday of July 2021 |
11 |
| -- Last Thursday of November 2021 |
| 10 | +Similarly, you might be asked to find: |
| 11 | + |
| 12 | +- the third Tuesday of August 2019 (August 20, 2019) |
| 13 | +- the teenth Wednesday of May 2020 (May 13, 2020) |
| 14 | +- the fourth Sunday of July 2021 (July 25, 2021) |
| 15 | +- the last Thursday of November 2022 (November 24, 2022) |
12 | 16 |
|
13 | 17 | The descriptors you are expected to process are: `first`, `second`, `third`, `fourth`, `last`, `teenth`.
|
14 | 18 |
|
15 | 19 | Note that descriptor `teenth` is a made-up word.
|
16 |
| -There are exactly seven numbered days in a month that end with "teenth" ("thirteenth" to "nineteenth"). |
17 |
| -Therefore, it is guaranteed that each day of the week (Monday, Tuesday, ...) will have exactly one numbered day ending with "teenth" each month. |
18 | 20 |
|
19 |
| -For example, if given "First Monday of January 2022", the correct meetup date is January 3, 2022. |
| 21 | +It refers to the seven numbers that end in '-teen' in English: 13, 14, 15, 16, 17, 18, and 19. |
| 22 | +But general descriptions of dates use ordinal numbers, e.g. the _first_ Monday, the _third_ Tuesday. |
| 23 | + |
| 24 | +For the numbers ending in '-teen', that becomes: |
| 25 | + |
| 26 | +- 13th (thirteenth) |
| 27 | +- 14th (fourteenth) |
| 28 | +- 15th (fifteenth) |
| 29 | +- 16th (sixteenth) |
| 30 | +- 17th (seventeenth) |
| 31 | +- 18th (eighteenth) |
| 32 | +- 19th (nineteenth) |
| 33 | + |
| 34 | +So there are seven numbers ending in '-teen'. |
| 35 | +And there are also seven weekdays (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday). |
| 36 | +Therefore, it is guaranteed that each day of the week (Monday, Tuesday, ...) will have exactly one numbered day ending with "teen" each month. |
| 37 | + |
| 38 | +If asked to find the teenth Saturday of August, 1953 (or, alternately the "Saturteenth" of August, 1953), we need to look at the calendar for August 1953: |
| 39 | + |
| 40 | +```plaintext |
| 41 | + August 1953 |
| 42 | +Su Mo Tu We Th Fr Sa |
| 43 | + 1 |
| 44 | + 2 3 4 5 6 7 8 |
| 45 | + 9 10 11 12 13 14 15 |
| 46 | +16 17 18 19 20 21 22 |
| 47 | +23 24 25 26 27 28 29 |
| 48 | +30 31 |
| 49 | +``` |
| 50 | + |
| 51 | +The Saturday that has a number ending in '-teen' is August 15, 1953. |
0 commit comments