Created
October 5, 2016 15:27
-
-
Save oluies/9ca391a3408bb1ee789a71a971f4bf40 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
def checkSEPnr(pnr:String) = { | |
val chars = pnr.toList | |
val removeMinus = chars.view.filter(_ != '-') | |
val charToInt = removeMinus.view.map(_ - '0') | |
val lunsum: Int = charToInt.take(9).foldLeft( (0,2) ){ | |
(r,c) => | |
(r._1 + (c * r._2) / 10 + (c * r._2) % 10, if (r._2 == 2) 1 else 2) | |
}._1 % 10 | |
val checkSum = if(lunsum == 0) 0 else 10 - lunsum | |
checkSum == removeUndescore.last - '0' | |
} | |
checkSEPnr("711127-5868") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment