List all palindromic prime dates between 0000-01-01 and 99999-12-31 You know what a palindrome, a prime and a date are. 


  Your task is to list all dates in 100 thousands of years that fulfill
  all three characteristics.


Nevermind anything but the numbers, use the following formats: YYYYMMDD and YYYYYMMDD.

Dates between 0000-01-01 and 9999-12-31 should be printed as 8 digit palindromes dates (If there is any?) and dates between 10000-01-01 and 99999-12-31 should be printed as 9 digit palindromes.

It's not mandatory to list the dates in chronological order.

Example part of valid output.

First three 9 digit prime palindromic dates:

...
100111001
100131001
100161001
...


Rules

Standard loopholes apply.
Ruby, 144 141 bytes (134+7 for the -rprime flag)

Saved 3 bytes thanks to benj2240!



('01'..'12').map{|m|('01'..'31').map{|d|(?0..?9).map{|k|q=m+d
y=q.reverse+k
r=y+q
Time.new(y,m,d).day==d.to_i&amp;&amp;r.to_i.prime?&amp;&amp;(p r)}}}


Try it online!

The algorithm:


generate all possible MMDD combinations, from "0101" to "1231"
generate all years for that date that would result in a palindrome, by reversing the MMDD string and adding in the middle, in turn, all chars in the (0..9) range
check if that is a valid date by creating a Time instance with the given y, m, d values. If the resulting time object has a #day value equal to d, then that was a valid date. Otherwise, it would shift the date (for example, Time.new 2018,2,30 returns 2018-03-02).
check if the valid palindrome date is also a prime and display it if it is.


The inner loop was initially a function that was called for each element in the (?0..?9) range, as well as for the empty string.

Since the empty string produced no results (there are no valid 8 digit prime palindromes), I decided to remove it and refactor to this version.