Skip to content

Instantly share code, notes, and snippets.

@aiwas
Created March 4, 2019 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aiwas/f74620671f333b47084c1596385bea1f to your computer and use it in GitHub Desktop.
Save aiwas/f74620671f333b47084c1596385bea1f to your computer and use it in GitHub Desktop.
モジュラス10 ウェイト3 の再発明
<?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