Barcode Inspection and Verification (# 60)
After scanning the barcode, it is a 13-digit numerical string. To cope with scanning errors, barcodes have a "check and verify" method used to verify whether the barcode is correct. The specific calculation rules are:
Extract the first 12 digits of a 13-digit string, add the odd digits to obtain S1, add the even digits to obtain S2, subtract S2 from S1, then get the remainder of division by 10, and finally take the absolute value. The resulting number should be equal to the 13th digit barcode. If they are not equal, it is an incorrect barcode.
Please calculate the correctness of the given barcode.
Convert the 13 digits of the given barcode into a sequence, calculate the sum of the first 12 odd digits in the sequence, then calculate the sum of even digits. Subtract the two obtained values, get the remainder of the difference divided by 10, and take the absolute value. Finally, determine whether the obtained value is equal to the last digit of the barcode.
A |
|
1 |
'1234567890123 |
2 |
=A1.split@p() |
3 |
=A2.to(12).step(2,1).sum() |
4 |
=A2.step(2,2).sum() |
5 |
=abs((A3-A4)%10) |
6 |
=A5==A2.m(-1) |
A1 fills in the barcode, starting with 'because it requires the barcode to be a string. Constant cells starting with' in SPL will be parsed as strings.
A2 splits the barcode character by character into a sequence, and after adding the @p option, it will parse each member's string into the corresponding data type. Here, they will be converted into integers:
A3 calculates the sum of the first 12 odd digits S1, while A4 calculates the sum of even digits S2. A5 calculates the verification value. A6 determines whether the verification value is equal to the 13th digit:
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProcSPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/2bkGwqTj
Youtube 👉 https://www.youtube.com/@esProc_SPL
Chinese version