19
1
(Inspired by last week's Riddler on FiveThirtyEight.com. Sandbox post.)
Given a year between 2001 and 2099, calculate and return the number of days during that calendar year where mm * dd = yy
(where yy
is the 2-digit year).
2018, for example, has 5:
- January 18th (1 * 18 = 18)
- February 9th (2 * 9 = 18)
- March 6th (3 * 6 = 18)
- June 3rd (6 * 3 = 18)
- September 2nd (9 * 2 = 18)
Input can be a 2 or 4-digit numeric year.
Output should be an integer. Optional trailing space or return is fine.
Complete input/output list:
Input = Output
2001 = 1 2021 = 3 2041 = 0 2061 = 0 2081 = 2
2002 = 2 2022 = 3 2042 = 4 2062 = 0 2082 = 0
2003 = 2 2023 = 1 2043 = 0 2063 = 3 2083 = 0
2004 = 3 2024 = 7 2044 = 3 2064 = 2 2084 = 5
2005 = 2 2025 = 2 2045 = 3 2065 = 1 2085 = 1
2006 = 4 2026 = 2 2046 = 1 2066 = 3 2086 = 0
2007 = 2 2027 = 3 2047 = 0 2067 = 0 2087 = 1
2008 = 4 2028 = 4 2048 = 6 2068 = 1 2088 = 3
2009 = 3 2029 = 1 2049 = 1 2069 = 1 2089 = 0
2010 = 4 2030 = 6 2050 = 3 2070 = 3 2090 = 5
2011 = 2 2031 = 1 2051 = 1 2071 = 0 2091 = 1
2012 = 6 2032 = 3 2052 = 2 2072 = 6 2092 = 1
2013 = 1 2033 = 2 2053 = 0 2073 = 0 2093 = 1
2014 = 3 2034 = 1 2054 = 4 2074 = 0 2094 = 0
2015 = 3 2035 = 2 2055 = 2 2075 = 2 2095 = 1
2016 = 4 2036 = 6 2056 = 4 2076 = 1 2096 = 4
2017 = 1 2037 = 0 2057 = 1 2077 = 2 2097 = 0
2018 = 5 2038 = 1 2058 = 0 2078 = 2 2098 = 1
2019 = 1 2039 = 1 2059 = 0 2079 = 0 2099 = 2
2020 = 5 2040 = 5 2060 = 6 2080 = 4
This is a code-golf challenge, lowest byte count in each language wins.
Pre-calculating and simply looking up the answers is normally excluded per our loophole rules, but I'm explicitly allowing it for this challenge. It allows for some interesting alternate strategies, although its not likely a 98 99-item lookup list is going to be shortest.
If it makes it any easier in your language, the answer will be the same regardless of century; 1924 and 2124 have the same number of days as 2024. – BradC – 2018-04-13T14:41:13.813
if the the result of mm*dd is bigger than 100 it is automatically filtered? – DanielIndie – 2018-04-13T16:03:21.503
@DanielIndie Correct, no "wraparound" dates should be counted. In other words, Dec 12, 2044 doesn't count, even though 12 * 12 = 144. – BradC – 2018-04-13T16:13:10.110
As we need only handle a limited number of inputs, I've edited them all in. Feel free to rollback or reformat. – Shaggy – 2018-04-13T17:20:49.320
I believe 2078 should be 2 and 2087 should be 1 – Asone Tuhid – 2018-04-13T17:58:03.300
@Arnauld Oops, off-by-one error. Same reason I submitted the wrong answer on the original 538.com puzzler. – BradC – 2018-04-13T18:01:21.453
That's fine, @Shaggy, I fixed the errors mentioned by Asone (which I also verified). – BradC – 2018-04-13T18:06:26.130
Does
Input can be a 2 or 4-digit numeric year
mean that the submitter can decide or that the program needs to accept both as valid? – 640KB – 2019-02-04T18:57:22.6701@gwaugh Just that you can decide which to accept as valid input (so you don't have to spend extra characters converting between the two). – BradC – 2019-02-04T20:06:54.097