Skip to content

Instantly share code, notes, and snippets.

@oluies
Created October 5, 2016 15:27
Show Gist options
  • Save oluies/9ca391a3408bb1ee789a71a971f4bf40 to your computer and use it in GitHub Desktop.
Save oluies/9ca391a3408bb1ee789a71a971f4bf40 to your computer and use it in GitHub Desktop.
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