How to count occurrences of Friday 13th












9












$begingroup$


I would like to find a function that will count the number of times Friday 13th happens in a particular calendar year.



Does anybody have any hints ?



Thank you










share|improve this question











$endgroup$








  • 1




    $begingroup$
    I fell into a delightful rabbit hole of day-counting algorithms on Wikipedia. I wanted to leave a link to the Doomsday algorithm for mental calculation of the day of the week, for fun: Doomsday rule on Wiki.
    $endgroup$
    – MarcoB
    Mar 4 at 19:54










  • $begingroup$
    Wolfram Challenges.
    $endgroup$
    – J. M. is slightly pensive
    Mar 5 at 2:21










  • $begingroup$
    Sounds like one for the code golf boys and girls
    $endgroup$
    – Strawberry
    Mar 5 at 13:05










  • $begingroup$
    Oh, of course they did it already: codegolf.stackexchange.com/questions/69510/…
    $endgroup$
    – Strawberry
    Mar 5 at 13:11
















9












$begingroup$


I would like to find a function that will count the number of times Friday 13th happens in a particular calendar year.



Does anybody have any hints ?



Thank you










share|improve this question











$endgroup$








  • 1




    $begingroup$
    I fell into a delightful rabbit hole of day-counting algorithms on Wikipedia. I wanted to leave a link to the Doomsday algorithm for mental calculation of the day of the week, for fun: Doomsday rule on Wiki.
    $endgroup$
    – MarcoB
    Mar 4 at 19:54










  • $begingroup$
    Wolfram Challenges.
    $endgroup$
    – J. M. is slightly pensive
    Mar 5 at 2:21










  • $begingroup$
    Sounds like one for the code golf boys and girls
    $endgroup$
    – Strawberry
    Mar 5 at 13:05










  • $begingroup$
    Oh, of course they did it already: codegolf.stackexchange.com/questions/69510/…
    $endgroup$
    – Strawberry
    Mar 5 at 13:11














9












9








9





$begingroup$


I would like to find a function that will count the number of times Friday 13th happens in a particular calendar year.



Does anybody have any hints ?



Thank you










share|improve this question











$endgroup$




I would like to find a function that will count the number of times Friday 13th happens in a particular calendar year.



Does anybody have any hints ?



Thank you







date-and-time






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 5 at 2:20









J. M. is slightly pensive

97.8k10304464




97.8k10304464










asked Mar 4 at 19:23







user63250















  • 1




    $begingroup$
    I fell into a delightful rabbit hole of day-counting algorithms on Wikipedia. I wanted to leave a link to the Doomsday algorithm for mental calculation of the day of the week, for fun: Doomsday rule on Wiki.
    $endgroup$
    – MarcoB
    Mar 4 at 19:54










  • $begingroup$
    Wolfram Challenges.
    $endgroup$
    – J. M. is slightly pensive
    Mar 5 at 2:21










  • $begingroup$
    Sounds like one for the code golf boys and girls
    $endgroup$
    – Strawberry
    Mar 5 at 13:05










  • $begingroup$
    Oh, of course they did it already: codegolf.stackexchange.com/questions/69510/…
    $endgroup$
    – Strawberry
    Mar 5 at 13:11














  • 1




    $begingroup$
    I fell into a delightful rabbit hole of day-counting algorithms on Wikipedia. I wanted to leave a link to the Doomsday algorithm for mental calculation of the day of the week, for fun: Doomsday rule on Wiki.
    $endgroup$
    – MarcoB
    Mar 4 at 19:54










  • $begingroup$
    Wolfram Challenges.
    $endgroup$
    – J. M. is slightly pensive
    Mar 5 at 2:21










  • $begingroup$
    Sounds like one for the code golf boys and girls
    $endgroup$
    – Strawberry
    Mar 5 at 13:05










  • $begingroup$
    Oh, of course they did it already: codegolf.stackexchange.com/questions/69510/…
    $endgroup$
    – Strawberry
    Mar 5 at 13:11








1




1




$begingroup$
I fell into a delightful rabbit hole of day-counting algorithms on Wikipedia. I wanted to leave a link to the Doomsday algorithm for mental calculation of the day of the week, for fun: Doomsday rule on Wiki.
$endgroup$
– MarcoB
Mar 4 at 19:54




$begingroup$
I fell into a delightful rabbit hole of day-counting algorithms on Wikipedia. I wanted to leave a link to the Doomsday algorithm for mental calculation of the day of the week, for fun: Doomsday rule on Wiki.
$endgroup$
– MarcoB
Mar 4 at 19:54












$begingroup$
Wolfram Challenges.
$endgroup$
– J. M. is slightly pensive
Mar 5 at 2:21




$begingroup$
Wolfram Challenges.
$endgroup$
– J. M. is slightly pensive
Mar 5 at 2:21












$begingroup$
Sounds like one for the code golf boys and girls
$endgroup$
– Strawberry
Mar 5 at 13:05




$begingroup$
Sounds like one for the code golf boys and girls
$endgroup$
– Strawberry
Mar 5 at 13:05












$begingroup$
Oh, of course they did it already: codegolf.stackexchange.com/questions/69510/…
$endgroup$
– Strawberry
Mar 5 at 13:11




$begingroup$
Oh, of course they did it already: codegolf.stackexchange.com/questions/69510/…
$endgroup$
– Strawberry
Mar 5 at 13:11










2 Answers
2






active

oldest

votes


















10












$begingroup$

Select[
Table[DateObject@{2019, m, 13}, {m, 12}],
DateString[#, "DayName"] === "Friday" &
]



{Day: Fri 13 Sep 2019,Day: Fri 13 Dec 2019}




countFri13[year_Integer]:=Length @ Select[
Table[DateObject@{year, m, 13}, {m, 12}],
DateString[#, "DayName"] === "Friday" &
]





share|improve this answer









$endgroup$





















    13












    $begingroup$

    I worked on this problem in 2015. Here is part on my notebook from that time.



    A not so good algorithm.



    friday13th[year_Integer] := 
    Select[DayName[#] === Friday &] @
    DateRange[DateObject[{year, 1, 13}], DateObject[{year, 12, 13}], {1, "Month"}]


    A good algorithm.



    friday13th[year_Integer] := 
    Select[DayName[#] === Friday &] @ Table[DateObject[{year, i, 13}], {i, 12}]


    A better algorithm.



    friday13th[year_Integer] := 
    Select[DayName[#] === Friday &] @ Array[DateObject[{year, #, 13}] &, 12]


    Using the better algorithm, I got (at the time I created the notebook)



    friday13th @ 2014


    2014



    friday13th @ 2015


    2015



    And for this year, I get



    friday13th @ 2019


    2019






    share|improve this answer









    $endgroup$













      Your Answer





      StackExchange.ifUsing("editor", function () {
      return StackExchange.using("mathjaxEditing", function () {
      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
      });
      });
      }, "mathjax-editing");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "387"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192605%2fhow-to-count-occurrences-of-friday-13th%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown
























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      10












      $begingroup$

      Select[
      Table[DateObject@{2019, m, 13}, {m, 12}],
      DateString[#, "DayName"] === "Friday" &
      ]



      {Day: Fri 13 Sep 2019,Day: Fri 13 Dec 2019}




      countFri13[year_Integer]:=Length @ Select[
      Table[DateObject@{year, m, 13}, {m, 12}],
      DateString[#, "DayName"] === "Friday" &
      ]





      share|improve this answer









      $endgroup$


















        10












        $begingroup$

        Select[
        Table[DateObject@{2019, m, 13}, {m, 12}],
        DateString[#, "DayName"] === "Friday" &
        ]



        {Day: Fri 13 Sep 2019,Day: Fri 13 Dec 2019}




        countFri13[year_Integer]:=Length @ Select[
        Table[DateObject@{year, m, 13}, {m, 12}],
        DateString[#, "DayName"] === "Friday" &
        ]





        share|improve this answer









        $endgroup$
















          10












          10








          10





          $begingroup$

          Select[
          Table[DateObject@{2019, m, 13}, {m, 12}],
          DateString[#, "DayName"] === "Friday" &
          ]



          {Day: Fri 13 Sep 2019,Day: Fri 13 Dec 2019}




          countFri13[year_Integer]:=Length @ Select[
          Table[DateObject@{year, m, 13}, {m, 12}],
          DateString[#, "DayName"] === "Friday" &
          ]





          share|improve this answer









          $endgroup$



          Select[
          Table[DateObject@{2019, m, 13}, {m, 12}],
          DateString[#, "DayName"] === "Friday" &
          ]



          {Day: Fri 13 Sep 2019,Day: Fri 13 Dec 2019}




          countFri13[year_Integer]:=Length @ Select[
          Table[DateObject@{year, m, 13}, {m, 12}],
          DateString[#, "DayName"] === "Friday" &
          ]






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 4 at 19:35









          KubaKuba

          106k12207529




          106k12207529























              13












              $begingroup$

              I worked on this problem in 2015. Here is part on my notebook from that time.



              A not so good algorithm.



              friday13th[year_Integer] := 
              Select[DayName[#] === Friday &] @
              DateRange[DateObject[{year, 1, 13}], DateObject[{year, 12, 13}], {1, "Month"}]


              A good algorithm.



              friday13th[year_Integer] := 
              Select[DayName[#] === Friday &] @ Table[DateObject[{year, i, 13}], {i, 12}]


              A better algorithm.



              friday13th[year_Integer] := 
              Select[DayName[#] === Friday &] @ Array[DateObject[{year, #, 13}] &, 12]


              Using the better algorithm, I got (at the time I created the notebook)



              friday13th @ 2014


              2014



              friday13th @ 2015


              2015



              And for this year, I get



              friday13th @ 2019


              2019






              share|improve this answer









              $endgroup$


















                13












                $begingroup$

                I worked on this problem in 2015. Here is part on my notebook from that time.



                A not so good algorithm.



                friday13th[year_Integer] := 
                Select[DayName[#] === Friday &] @
                DateRange[DateObject[{year, 1, 13}], DateObject[{year, 12, 13}], {1, "Month"}]


                A good algorithm.



                friday13th[year_Integer] := 
                Select[DayName[#] === Friday &] @ Table[DateObject[{year, i, 13}], {i, 12}]


                A better algorithm.



                friday13th[year_Integer] := 
                Select[DayName[#] === Friday &] @ Array[DateObject[{year, #, 13}] &, 12]


                Using the better algorithm, I got (at the time I created the notebook)



                friday13th @ 2014


                2014



                friday13th @ 2015


                2015



                And for this year, I get



                friday13th @ 2019


                2019






                share|improve this answer









                $endgroup$
















                  13












                  13








                  13





                  $begingroup$

                  I worked on this problem in 2015. Here is part on my notebook from that time.



                  A not so good algorithm.



                  friday13th[year_Integer] := 
                  Select[DayName[#] === Friday &] @
                  DateRange[DateObject[{year, 1, 13}], DateObject[{year, 12, 13}], {1, "Month"}]


                  A good algorithm.



                  friday13th[year_Integer] := 
                  Select[DayName[#] === Friday &] @ Table[DateObject[{year, i, 13}], {i, 12}]


                  A better algorithm.



                  friday13th[year_Integer] := 
                  Select[DayName[#] === Friday &] @ Array[DateObject[{year, #, 13}] &, 12]


                  Using the better algorithm, I got (at the time I created the notebook)



                  friday13th @ 2014


                  2014



                  friday13th @ 2015


                  2015



                  And for this year, I get



                  friday13th @ 2019


                  2019






                  share|improve this answer









                  $endgroup$



                  I worked on this problem in 2015. Here is part on my notebook from that time.



                  A not so good algorithm.



                  friday13th[year_Integer] := 
                  Select[DayName[#] === Friday &] @
                  DateRange[DateObject[{year, 1, 13}], DateObject[{year, 12, 13}], {1, "Month"}]


                  A good algorithm.



                  friday13th[year_Integer] := 
                  Select[DayName[#] === Friday &] @ Table[DateObject[{year, i, 13}], {i, 12}]


                  A better algorithm.



                  friday13th[year_Integer] := 
                  Select[DayName[#] === Friday &] @ Array[DateObject[{year, #, 13}] &, 12]


                  Using the better algorithm, I got (at the time I created the notebook)



                  friday13th @ 2014


                  2014



                  friday13th @ 2015


                  2015



                  And for this year, I get



                  friday13th @ 2019


                  2019







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 4 at 19:52









                  m_goldbergm_goldberg

                  87.4k872198




                  87.4k872198






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Mathematica Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      Use MathJax to format equations. MathJax reference.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192605%2fhow-to-count-occurrences-of-friday-13th%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                      ComboBox Display Member on multiple fields

                      Is it possible to collect Nectar points via Trainline?