Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Palindrome-dates/Swift/palindrome-dates.swift
Normal file
25
Task/Palindrome-dates/Swift/palindrome-dates.swift
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import Foundation
|
||||
|
||||
func isPalindrome(_ string: String) -> Bool {
|
||||
let chars = string.lazy
|
||||
return chars.elementsEqual(chars.reversed())
|
||||
}
|
||||
|
||||
let format = DateFormatter()
|
||||
format.dateFormat = "yyyyMMdd"
|
||||
|
||||
let outputFormat = DateFormatter()
|
||||
outputFormat.dateFormat = "yyyy-MM-dd"
|
||||
|
||||
var count = 0
|
||||
let limit = 15
|
||||
let calendar = Calendar.current
|
||||
var date = Date()
|
||||
|
||||
while count < limit {
|
||||
if isPalindrome(format.string(from: date)) {
|
||||
print(outputFormat.string(from: date))
|
||||
count += 1
|
||||
}
|
||||
date = calendar.date(byAdding: .day, value: 1, to: date)!
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue