Last active
October 29, 2021 17:25
-
-
Save MrBogomips/8715832d1f868c5e74bab8e2b3305205 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
static readonly byte[] _oddMap = new byte[] { 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 }; | |
static bool PartitaIvaCheckSum(string value) | |
{ | |
Debug.Assert(value is not null); | |
Debug.Assert(value.Length == 11); | |
// ASSERT: value is a string of digits | |
var c0 = (byte) '0'; | |
int acc = 0; | |
byte[] codes = Encoding.ASCII.GetBytes(value); | |
for (var pos = 0; pos < 11; ++pos) | |
{ | |
var ci = codes[pos] - c0; | |
if (pos % 2 == 0) acc += ci; | |
else acc += _oddMap[ci]; | |
} | |
return acc % 10 == 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment