Skip to content

Instantly share code, notes, and snippets.

@JamalK
Last active August 29, 2015 14:12
Show Gist options
  • Save JamalK/1fc90aac0a9eb1551f45 to your computer and use it in GitHub Desktop.
Save JamalK/1fc90aac0a9eb1551f45 to your computer and use it in GitHub Desktop.
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