Author Topic: Palindromic Dates  (Read 3207 times)

0 Members and 1 Guest are viewing this topic.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Palindromic Dates
« on: February 05, 2020, 07:48:48 am »
Apparently February 2nd was "International Palindrome Day" because the date was 02/02/2020.  Luckily this is palindromic in both British configuration (DD/MM/YYYY) and American configuration (MM/DD/YYYY).

So I thought that I'd find out which dates have been palindromic.  The program gives a list of palindromic dates from year 0 to 2100.  British date configuration is used, but you can easily adapt it to American configuration.  A text file is created as well as print to screen as there are, not surprisingly, quite a few such dates.

Code: QB64: [Select]
  1. 'Palindromic Dates (British Date Configuration DDMMYYYY) 05/02/2020 by Qwerkey
  2. '02022020 was palindromic
  3. 'Do up to 2100 (assuming gregorian calendar goes back to zero)
  4.  
  5. CONST False = 0, True = NOT False
  6.  
  7. DIM Months%%(12)
  8. FOR N%% = 1 TO 12
  9.     READ Months%%(N%%)
  10. NEXT N%%
  11.  
  12. OPEN "palindate.txt" FOR OUTPUT AS #1
  13.  
  14. Day%% = 1
  15. Month%% = 1
  16. Year% = 0
  17.  
  18. WHILE Year% < 2101
  19.     Palin$ = DayMonth$(Day%%) + DayMonth$(Month%%) + Annus$(Year%)
  20.     IF IsPalindromic%%(Palin$) THEN
  21.         PRINT Palin$
  22.         PRINT #1, Palin$
  23.     END IF
  24.     Day%% = Day%% + 1
  25.     IF Day%% > Months%%(Month%%) THEN
  26.         Day%% = 1
  27.         Month%% = Month%% + 1
  28.         IF Month%% > 12 THEN
  29.             Month%% = 1
  30.             Year% = Year% + 1
  31.             'Modification for leap years:
  32.             IF Year% \ 4 = Year% / 4 THEN
  33.                 Months%%(2) = 29
  34.                 IF Year% \ 400 = Year% / 400 THEN Months%%(2) = 28
  35.             ELSE
  36.                 Months%%(2) = 28
  37.             END IF
  38.         END IF
  39.     END IF
  40.  
  41.  
  42. FUNCTION IsPalindromic%% (P$)
  43.     IsPalindromic%% = True
  44.     M%% = 1
  45.     WHILE M%% <= 4 AND IsPalindromic%%
  46.         IF MID$(P$, M%%, 1) <> MID$(P$, 9 - M%%, 1) THEN IsPalindromic%% = False
  47.         M%% = M%% + 1
  48.     WEND
  49.  
  50. FUNCTION DayMonth$ (M%%)
  51.     S$ = LTRIM$(STR$(M%%))
  52.     IF M%% < 10 THEN
  53.         DayMonth$ = "0" + S$
  54.     ELSE
  55.         DayMonth$ = S$
  56.     END IF
  57.  
  58. FUNCTION Annus$ (Y%)
  59.     A$ = LTRIM$(STR$(Y%))
  60.     IF Y% < 10 THEN
  61.         Annus$ = "000" + A$
  62.     ELSEIF Y% < 100 THEN
  63.         Annus$ = "00" + A$
  64.     ELSEIF Y% < 1000 THEN
  65.         Annus$ = "0" + A$
  66.     ELSE
  67.         Annus$ = A$
  68.     END IF
  69.  
  70. DATA 31,28,31,30,31,30,31,31,30,31,30,31
  71.  
« Last Edit: February 06, 2020, 10:10:44 am by Qwerkey »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Palindromic Dates
« Reply #1 on: February 05, 2020, 09:38:14 am »
Wait Groundhog Day, Superbowl Day AND Palindrome Day with BOTH British and American date configurations!

Were all the planets lined up as well? No, just the Republicans. Oh, and the Democrats. ;-))
« Last Edit: February 05, 2020, 09:41:09 am by bplus »

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Palindromic Dates
« Reply #2 on: February 05, 2020, 12:22:13 pm »
Groundhog Day.  The other day my wife and I asked ourselves "what exactly is Groundhog Day?".  Wikipedia says: "It derives from the Pennsylvania Dutch superstition that if a groundhog emerging from its burrow on this day sees its shadow due to clear weather, it will retreat to its den and winter will persist for six more weeks, and if it does not see its shadow because of cloudiness, spring will arrive early.".  This is a thing that you North Americans want to celebrate??? You're a lot stranger than we thought!

... just the Republicans.  Oh no! Don't set Pete off, please!

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Palindromic Dates
« Reply #3 on: February 05, 2020, 05:27:21 pm »
And Guy Fawkes Day is completely sane? 11/5 2020 - 5/11/2020 may not be Palindromic but perhaps Pedantic. He says holding a flaming torch, glazed eyes and a Capital building in front of him.