WolframLanguage (Mathematica) 187 bytes
There may be some reduction in size to be found.
Explanation to follow...
t=ToString;p=PadLeft;d=DateObject;Cases[""<>{t/@p[#,If[Length@#<5,4, 5]],t/@ p[#2,2],t/@p[#3,2]}&@@@(IntegerDigits/@#[[1]]&/@DayRange[d@#,d@#2]),x_/;PalindromeQ@x&&PrimeQ@ToExpression@x]&
Test cases
t = ToString; p = PadLeft; d = DateObject;
Cases["" <> {t /@ p[#, If[Length@# < 5, 4, 5]], t /@ p[#2, 2],
t /@ p[#3, 2]} & @@@ (IntegerDigits /@ #[[1]] & /@ DayRange[d@#, d@#2]),
x_ /; PalindromeQ@x && PrimeQ@ToExpression@x] &[{10011, 10, 1}, {10017, 1, 1}]
(* {"100111001", "100131001", "100161001"} *)
Explanation of code
DayRange[d@#,d@#2]
returns all of the dates between {10011, 10, 1}
and {10017, 1, 1}
. In this case, it returns approximately 5 years, 4 months of dates (precisely 1920 dates). Leap years are taken into account.
The dates are returned in Wolfram-standard formatting. For example, the first date will appear as DateObject[List[1,1,1],"Day","Gregorian",-5.
]`
#[[1]] & /@
will remove the part of the date, in each date, that concerns us. In the example, DateObject[List[1,3,7],"Day","Gregorian",-5.]
returns the abbreviated date, {1,3,7}
.
t/@p[#3,2]}
or ToString/@Padleft[#3,2]
pads the third element, namely, the 7 standing "for 7th day of the month" as "07"
. Similar padding is provided for the single digit symbol for the month of March, namely, 3
is returned as "03"
.
p[#, If[Length@# < 5, 4, 5]]
pads the year with zeros to reach the length of a 4 or 5 digit string. In this case, January, namely 1
, is returned as `"00001"'.
"" <>...
joins the strings. In this case, it returns "000010307"
.
Cases[...x_ /; PalindromeQ@x && PrimeQ@ToExpression@x]
returns those cases, among the 1920 dates, that are palindromes and primes.
Rule:
02-29
only exists for years that are divisible by 400 or (divisible by 4 and not divisible by 100). – user202729 – 2018-01-15T12:57:21.603@user202729 Yeah, I think so, for example I don't think 2017-02-29, 2018-02-29 and 1900-02-29 can be considered "dates". – Erik the Outgolfer – 2018-01-15T13:43:50.770
4
There aren't any 8-digit palindromic dates that are also primes. Here is a pastebin the list we are supposed to return/print (197 in total). Is this correct @Plarsen?
– Kevin Cruijssen – 2018-01-15T13:45:34.8131
Should we allow 30th Feb? > https://www.timeanddate.com/date/february-30.html
– jrtapsell – 2018-01-15T14:49:06.0803Year 0000 never happened – Jonathan Allan – 2018-01-15T16:32:44.807
@KevinCruijssen Seems correct! – Plarsen – 2018-01-16T11:25:40.787
@jrtapsell Yes, but I doubt any of the known ones is both prime and palindromic – Plarsen – 2018-01-16T11:27:47.373
Can we just hardcode the output? – Poke – 2018-01-16T20:11:21.613
@poke Yes, that is one valid way of fulfilling the task – Plarsen – 2018-01-17T14:30:36.917