Last active
August 29, 2015 14:12
-
-
Save JamalK/1fc90aac0a9eb1551f45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
public func reverse () -> String { | |
return String(Array(self).reverse()) | |
} | |
public func isPalindrome () -> Bool { | |
return (self == self.reverse()) | |
} | |
} | |
extension Int { | |
public func isPalindromeYear() -> Bool { | |
let yearStr = String(self, radix: 2) | |
return (yearStr.reverse() == yearStr) | |
} | |
} | |
func palindromicYears (starting : Int, to : Int) -> [Int] { | |
var yearsArray = [Int]() | |
for year in starting...to-1 { | |
if year.isPalindromeYear(){ | |
yearsArray.append(year) | |
} | |
} | |
return yearsArray | |
} | |
let years = palindromicYears(2000,2100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment