Advertisement
Radeen10-_

PRIME => EMIRP (Backwards Prime Read)

Aug 20th, 2021
1,221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. Examples:
  2. 13 17 31 37 71 73 ... are Backwards Read Primes
  3. >> 13 is such because its prime and read from right to left writes 31 which is prime too. Same for the others.
  4. >>pallidrome prime should not be taken
  5.  
  6.  
  7. backwardsPrime(2, 100) => [13, 17, 31, 37, 71, 73, 79, 97]
  8. backwardsPrime(501, 599) => [] || return empty list
  9. --------------------------------------------------------------------------------------------------------------------------------------
  10.  
  11. def backwardsPrime(start,stop):
  12.     list1=[]
  13.     for i in range(start,stop):
  14.         if i > 1:
  15.             for j in list(range(2,i)):
  16.                 if(i%j==0):
  17.                      break
  18.             else:
  19.                 reversed=int(str(i)[::-1])
  20.                 for item in range(2,reversed):
  21.                     if reversed%item==0:
  22.                          break
  23.                 else:
  24.                     if i!=reversed:
  25.                         list1.append(i)
  26.     return list1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement