Created
March 4, 2019 08:15
-
-
Save aiwas/f74620671f333b47084c1596385bea1f to your computer and use it in GitHub Desktop.
モジュラス10 ウェイト3 の再発明
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
<?php | |
function mod10w3(string $numeric) { | |
$num_array = array_reverse(str_split($numeric)); | |
$sum_odd = array_sum(array_map('current', array_chunk(array_slice($num_array, 0), 2))); | |
$sum_even = array_sum(array_map('current', array_chunk(array_slice($num_array, 1), 2))); | |
$sum_all = ($sum_odd * 3) + $sum_even; | |
$mod = $sum_all % 10; | |
$cd = ($mod == 0) ? 0 : (10 - $mod); | |
return $cd; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment