Created
March 13, 2023 12:34
-
-
Save erdemildiz/77a118aec1cca8eb6719273233d159f0 to your computer and use it in GitHub Desktop.
Turkish Identify Number Control in Swift
This file contains hidden or 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
import Foundation | |
let tcNumber = "{TC_NUMBER}}" | |
let lastDigitOfTCNumber = "\(tcNumber)".suffix(1) | |
let totalOfNumbers = tcNumber.prefix(10).reduce(0) { Int($0) + (Int("\($1)") ?? 0) } | |
let lastDigitOfTotalNumber = "\(totalOfNumbers)".suffix(1) | |
if | |
tcNumber.count == 11, | |
lastDigitOfTCNumber == lastDigitOfTotalNumber { | |
print("Right!") | |
} else { | |
print("Wrong!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment