You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import Foundation
extensionInt{func isPrime()->Bool{
for possibleFactor in 2...Int(sqrt(Double(self)))+1{
if self% possibleFactor ==0{return false
}}return true
}func numberOfDigits()->Int{varcount=0varn=self
while n >0{
n /=10
count +=1}return count
}func readBackwards()->Int{varn=selfvarplaceNumber=self.numberOfDigits()-1varbackwardsInt=0
while n >0{
backwardsInt +=(n %10)* Int(pow(10.0,Double(placeNumber)))
placeNumber -=1
n /=10}return backwardsInt
}}func backwardsPrimes(from lowerBound:Int, to upperBound:Int)->[Int]{letarr=Array(lowerBound...upperBound)varprimes=[Int]()
for num in arr {letbackwardsNum= num.readBackwards()
if num != backwardsNum {
if num.isPrime() && backwardsNum.isPrime(){
primes.append(num)}}}return primes
//return Array(lowerBound...upperBound).filter{ $0.isPrime() && $0.readBackwards().isPrime() && $0 != $0.readBackwards() }
}