Introduction
This challenge is to test the logical ability and does not have any resemblance with real time problem. The task is to generate the palindrome primes from 10 to 1000 and count the number of occurrences of each digit in them
A number that reads the same from left to right and vice versa is a palindrome number, for example 121 or 65456. Primes numbers are those that are divisible only by 1 and the number itself, for example 2 or 5.
Sample Data
Expected Results
PalindromPrimes 0 1 2 3 4 5 6 7 8 9
--------------- -- -- -- -- -- -- -- -- -- --
11 - 2 - - - - - - - -
101 1 2 - - - - - - - -
131 - 2 - 1 - - - - - -
151 - 2 - - - 1 - - - -
181 - 2 - - - - - - 1 -
191 - 2 - - - - - - - 1
313 - 1 - 2 - - - - - -
353 - - - 2 - 1 - - - -
373 - - - 2 - - - 1 - -
383 - - - 2 - - - - 1 -
727 - - 1 - - - - 2 - -
757 - - - - - 1 - 2 - -
787 - - - - - - - 2 1 -
797 - - - - - - - 2 - 1
919 - 1 - - - - - - - 2
929 - - 1 - - - - - - 2
11 is a palindrome prime number and hence it is listed in the output. 11 has the number "1" twice and therefore the column "1" shows 2. Another palindrome prime, "101" has one zero and two ones. That is why the column "0" shows 1 and the column "1" shows 2.
Rules
- The code should run in SQL SERVER 2005 and later versions.
- The code should generate the palindrome prime numbers. It should not read from a
static table/cte/view.
- Output should be sorted by the first column(Palindrome Primes) in ascending order.
Sample Script
Restrictions
- The solution should be a single query that starts with a "SELECT" or “;WITH”.
Notes
Tags:Puzzles, TSQL Beginners Challenge, TC, TSQL Beginners Challenge 7