Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7930a64

Browse files
author
uuk020
committed
13的可分性规则 thirt
1 parent 434745b commit 7930a64

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

‎thirt/thirt.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* 13的可分性规则
4+
* When you divide the successive powers of 10 by 13 you get the following remainders of the integer divisions:1, 10, 9, 12, 3, 4.
5+
* Then the whole pattern repeats.
6+
* Hence the following method: Multiply the right most digit of the number with the left most number in the sequence shown above,
7+
* the second right most digit to the second left most digit of the number in the sequence. The cycle goes on and you sum all these products.
8+
* Repeat this process until the sequence of sums is stationary.
9+
* Example: What is the remainder when 1234567 is divided by 13?
10+
* 7×ばつかける1 +たす 6×ばつかける10 +たす 5×ばつかける9 +たす 4×ばつかける12 +たす 3×ばつかける3 +たす 2×ばつかける4 +たす 1×ばつかける1 = 178
11+
* We repeat the process with 178:
12+
* 8x1 + 7x10 + 1x9 = 87 and again with 87: 7x1 + 8x10 = 87
13+
*/
14+
function thirt($n) {
15+
$sequence = [1,10,9,12,3,4];
16+
$sum = 0;
17+
// 将字符串转换为数组, 再把数组相反
18+
$arr = array_reverse(str_split($n));
19+
// 循环数组
20+
for ($i = 0; $i < count($arr); $i++) {
21+
// 通过余数来循环出$sequence数组的值 因为$sequence有6个所以除于6求余数.
22+
$sum += $arr[$i] * $sequence[$i % 6];
23+
}
24+
// 判断$n 是否等于$sum, 第一次是不想等, 递归调用 thirt函数, 此时形参$n等于$sum.
25+
return ($n === $sum) ? $n : thirt($sum);
26+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /