numb 0.152.0 → 0.170.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/numb/bell.rb +9 -12
- data/lib/numb/bernoulli.rb +7 -8
- data/lib/numb/catalan.rb +1 -5
- data/lib/numb/divisors/abundant.rb +58 -0
- data/lib/numb/divisors/aliquot.rb +31 -0
- data/lib/numb/divisors/amicable.rb +38 -0
- data/lib/numb/divisors/perfect.rb +73 -0
- data/lib/numb/divisors.rb +389 -0
- data/lib/numb/entringer.rb +2 -0
- data/lib/numb/figurate.rb +138 -0
- data/lib/numb/in_sequence.rb +11 -0
- data/lib/numb/jacobsthal_lucas.rb +5 -6
- data/lib/numb/knuth.rb +1 -4
- data/lib/numb/lucas.rb +5 -5
- data/lib/numb/lucas2.rb +11 -0
- data/lib/numb/lychrel.rb +0 -4
- data/lib/numb/palindrome.rb +8 -0
- data/lib/numb/pell_lucas.rb +9 -0
- data/lib/numb/primes.rb +164 -0
- data/lib/numb/pronic.rb +1 -0
- data/lib/numb/q.rb +13 -0
- data/lib/numb/schr/303/266der.rb +20 -0
- data/lib/numb/segmented.rb +29 -0
- data/lib/numb/stirling.rb +9 -0
- data/lib/numb/stirling2.rb +9 -0
- data/lib/numb/strictly_non_palindromic.rb +1 -5
- data/lib/numb/super_catalan.rb +17 -0
- data/lib/numb/super_d.rb +6 -0
- data/lib/numb/takeuchi.rb +18 -0
- data/lib/numb/unhappy.rb +2 -0
- data/lib/numb.rb +1 -53
- data/spec/numb/first_with_n_divisors_spec.rb +15 -0
- data/spec/numb/highly_composite_spec.rb +1 -1
- data/spec/numb/jacobsthal_lucas_spec.rb +19 -11
- data/spec/numb/lucas2_spec.rb +30 -0
- data/spec/numb/lucas_spec.rb +17 -9
- data/spec/numb/minimal_spec.rb +1 -1
- data/spec/numb/near_square_spec.rb +54 -0
- data/spec/numb/octahedral_spec.rb +29 -0
- data/spec/numb/palindrome_spec.rb +43 -0
- data/spec/numb/pell_lucas_spec.rb +28 -0
- data/spec/numb/pentatope_spec.rb +15 -0
- data/spec/numb/primitive_abundant_spec.rb +21 -0
- data/spec/numb/pyramidal_spec.rb +42 -0
- data/spec/numb/q_spec.rb +31 -0
- data/spec/numb/schr/303/266der_spec.rb +28 -0
- data/spec/numb/segmented_spec.rb +29 -0
- data/spec/numb/square_part_spec.rb +15 -0
- data/spec/numb/star_spec.rb +29 -0
- data/spec/numb/stella_octangula_spec.rb +29 -0
- data/spec/numb/stirling2_spec.rb +23 -0
- data/spec/numb/stirling_spec.rb +23 -0
- data/spec/numb/super_catalan_spec.rb +29 -0
- data/spec/numb/super_d_spec.rb +68 -0
- data/spec/numb/takeuchi_spec.rb +28 -0
- data/spec/numb/tetrahedral_spec.rb +15 -0
- metadata +63 -100
- data/lib/numb/abundancy.rb +0 -8
- data/lib/numb/abundant.rb +0 -20
- data/lib/numb/achilles.rb +0 -15
- data/lib/numb/aliquot_sequence.rb +0 -13
- data/lib/numb/almost_perfect.rb +0 -8
- data/lib/numb/almost_prime.rb +0 -6
- data/lib/numb/amicable.rb +0 -6
- data/lib/numb/aspiring.rb +0 -8
- data/lib/numb/augmented_amicable.rb +0 -7
- data/lib/numb/balanced_prime.rb +0 -10
- data/lib/numb/betrothed.rb +0 -8
- data/lib/numb/breeder.rb +0 -9
- data/lib/numb/brilliant.rb +0 -7
- data/lib/numb/centered_cube.rb +0 -7
- data/lib/numb/centered_hexagonal.rb +0 -6
- data/lib/numb/centered_n_gonal.rb +0 -9
- data/lib/numb/centered_pentagonal.rb +0 -6
- data/lib/numb/centered_square.rb +0 -5
- data/lib/numb/centered_triangular.rb +0 -5
- data/lib/numb/composite.rb +0 -5
- data/lib/numb/coprime.rb +0 -9
- data/lib/numb/cube.rb +0 -5
- data/lib/numb/d.rb +0 -6
- data/lib/numb/decagonal.rb +0 -5
- data/lib/numb/deficient.rb +0 -19
- data/lib/numb/dihedral_prime.rb +0 -26
- data/lib/numb/dodecagonal.rb +0 -5
- data/lib/numb/e_divisors.rb +0 -10
- data/lib/numb/e_perfect.rb +0 -7
- data/lib/numb/economical.rb +0 -16
- data/lib/numb/emrip.rb +0 -15
- data/lib/numb/equidigital.rb +0 -18
- data/lib/numb/extravagant.rb +0 -18
- data/lib/numb/fermat_pseudoprime.rb +0 -9
- data/lib/numb/friendly.rb +0 -9
- data/lib/numb/full_reptend_prime.rb +0 -5
- data/lib/numb/giuga.rb +0 -7
- data/lib/numb/harshad.rb +0 -9
- data/lib/numb/heptagonal.rb +0 -5
- data/lib/numb/hexagonal.rb +0 -6
- data/lib/numb/highly_abundant.rb +0 -7
- data/lib/numb/highly_composite.rb +0 -12
- data/lib/numb/hoax.rb +0 -7
- data/lib/numb/hyperperfect.rb +0 -7
- data/lib/numb/impolite.rb +0 -6
- data/lib/numb/infinitary_divisors.rb +0 -15
- data/lib/numb/infinitary_perfect.rb +0 -6
- data/lib/numb/interprime.rb +0 -6
- data/lib/numb/k_perfect.rb +0 -8
- data/lib/numb/mersenne_prime.rb +0 -5
- data/lib/numb/minimal.rb +0 -8
- data/lib/numb/multiamicable.rb +0 -7
- data/lib/numb/myriagonal.rb +0 -5
- data/lib/numb/n_gonal.rb +0 -7
- data/lib/numb/next_prev_prime.rb +0 -13
- data/lib/numb/nth_prime.rb +0 -17
- data/lib/numb/number_of_divisors.rb +0 -22
- data/lib/numb/octagonal.rb +0 -5
- data/lib/numb/ore.rb +0 -8
- data/lib/numb/pentagonal.rb +0 -5
- data/lib/numb/perfect.rb +0 -8
- data/lib/numb/perfect_power.rb +0 -9
- data/lib/numb/polite.rb +0 -7
- data/lib/numb/powerful.rb +0 -10
- data/lib/numb/practical.rb +0 -26
- data/lib/numb/prime_count.rb +0 -16
- data/lib/numb/prime_signature.rb +0 -5
- data/lib/numb/primitive_pseudoperfect.rb +0 -5
- data/lib/numb/rhonda.rb +0 -6
- data/lib/numb/rough.rb +0 -5
- data/lib/numb/safe_prime.rb +0 -5
- data/lib/numb/semiperfect.rb +0 -20
- data/lib/numb/semiprime.rb +0 -6
- data/lib/numb/smith.rb +0 -7
- data/lib/numb/smooth.rb +0 -5
- data/lib/numb/sociable.rb +0 -6
- data/lib/numb/sophie_germain_prime.rb +0 -5
- data/lib/numb/square.rb +0 -7
- data/lib/numb/square_free.rb +0 -6
- data/lib/numb/square_triangular.rb +0 -5
- data/lib/numb/squared_triangular.rb +0 -5
- data/lib/numb/sublime.rb +0 -6
- data/lib/numb/sum_of_e_divisors.rb +0 -10
- data/lib/numb/sum_of_infinitary_divisors.rb +0 -9
- data/lib/numb/sum_of_unitary_divisors.rb +0 -5
- data/lib/numb/super_poulet.rb +0 -5
- data/lib/numb/superabundant.rb +0 -18
- data/lib/numb/superperfect.rb +0 -6
- data/lib/numb/triangular.rb +0 -6
- data/lib/numb/twin_prime.rb +0 -5
- data/lib/numb/unitary_amicable.rb +0 -7
- data/lib/numb/unitary_divisor.rb +0 -5
- data/lib/numb/unitary_perfect.rb +0 -7
- data/lib/numb/unitary_sociable.rb +0 -7
- data/lib/numb/untouchable.rb +0 -14
- data/lib/numb/unusual.rb +0 -5
- data/lib/numb/weird.rb +0 -8
- data/lib/numb/wieferich.rb +0 -6
@@ -1,20 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
2147483647].to_seq
|
1
|
+
# A014551
|
2
|
+
JACOBSTHAL_LUCAS = [2,1,5,7,17,31,65,127,257,511,1025,2047,4097,8191,
|
3
|
+
16385,32767,65537,131071,262145,524287,1048577,
|
4
|
+
2097151,4194305,8388607,16777217,33554431,
|
5
|
+
67108865,134217727,268435457,536870911,1073741825,
|
6
|
+
2147483647]
|
8
7
|
|
9
|
-
|
10
|
-
|
8
|
+
describe Integer, "#jacobsthal_lucas?" do
|
9
|
+
JACOBSTHAL_LUCAS.each do |n|
|
10
|
+
it "returns true for Jacobsthal-Lucas number #{n}" do
|
11
11
|
n.should be_jacobsthal_lucas
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
it "
|
15
|
+
JACOBSTHAL_LUCAS.to_seq.invert.sample(10).each do |n|
|
16
|
+
it "returns false for non-Jacobsthal-Lucas number #{n}" do
|
17
17
|
n.should_not be_jacobsthal_lucas
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
describe Integer, "#jacobsthal_lucas" do
|
23
|
+
JACOBSTHAL_LUCAS.each_with_index do |l, n|
|
24
|
+
it "returns #{l} for the #{n}#{n.ordinal} Jacobsthal-Lucas number" do
|
25
|
+
n.jacobsthal_lucas.should == l
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
describe Integer, "#lucas2" do
|
3
|
+
@seq = {
|
4
|
+
# A000204
|
5
|
+
[1, -1] => [2]+[1,3,4,7,11,18,29,47,76,123,199,322,521,843,1364,
|
6
|
+
2207,3571,5778,9349,15127,24476,39603,64079,
|
7
|
+
103682,167761,271443,439204,710647,1149851,
|
8
|
+
1860498,3010349,4870847,7881196,12752043],
|
9
|
+
# A002203
|
10
|
+
[2, -1] => [2,2,6,14,34,82,198,478,1154,2786,6726,16238,
|
11
|
+
39202,94642,228486,551614,1331714,3215042,7761798,
|
12
|
+
18738638,45239074,109216786,263672646,636562078,
|
13
|
+
1536796802,3710155682,8957108166,21624372014,
|
14
|
+
52205852194],
|
15
|
+
# A014551
|
16
|
+
[1, -2] => [2,1,5,7,17,31,65,127,257,511,1025,2047,4097,8191,
|
17
|
+
16385,32767,65537,131071,262145,524287,1048577,
|
18
|
+
2097151,4194305,8388607,16777217,33554431,
|
19
|
+
67108865,134217727,268435457,536870911,1073741825,
|
20
|
+
2147483647]
|
21
|
+
}
|
22
|
+
|
23
|
+
@seq.each do |(p, q), seq|
|
24
|
+
seq.each_with_index do |l, n|
|
25
|
+
it "returns #{l} for the #{n}#{n.ordinal} Lucas number of the 2nd kind (#{p}, #{q})" do
|
26
|
+
n.lucas2(p, q).should == l
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/numb/lucas_spec.rb
CHANGED
@@ -1,20 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
33385282].to_seq
|
1
|
+
# A000032
|
2
|
+
LUCAS = [2,1,3,4,7,11,18,29,47,76,123,199,322,521,843,
|
3
|
+
1364,2207,3571,5778,9349,15127,24476,39603,64079,
|
4
|
+
103682,167761,271443,439204,710647,1149851,
|
5
|
+
1860498,3010349,4870847,7881196,12752043,20633239,
|
6
|
+
33385282]
|
8
7
|
|
9
|
-
|
8
|
+
describe Integer, "#lucas?" do
|
9
|
+
LUCAS.each do |n|
|
10
10
|
it "returns true for Lucas number #{n}" do
|
11
11
|
n.should be_lucas
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
LUCAS.to_seq.invert.sample(10).each do |n|
|
16
16
|
it "returns false for non-Lucas number #{n}" do
|
17
17
|
n.should_not be_lucas
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
describe Integer, "#lucas" do
|
23
|
+
LUCAS.each_with_index do |l, n|
|
24
|
+
it "returns #{l} for the #{n}#{n.ordinal} Lucas number" do
|
25
|
+
n.lucas.should == l
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/numb/minimal_spec.rb
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
describe Integer, "#near_square?" do
|
3
|
+
@seq = {
|
4
|
+
# A028875
|
5
|
+
-5 => [4,11,20,31,44,59,76,95,116,139,164,191,220,251,
|
6
|
+
284,319,356,395,436,479,524,571,620,671,724,779,
|
7
|
+
836,895,956,1019,1084,1151,1220,1291,1364,1439,
|
8
|
+
1516,1595,1676,1759,1844,1931,2020,2111,2204,2299,
|
9
|
+
2396],
|
10
|
+
# A028347
|
11
|
+
-4 => [0,5,12,21,32,45,60,77,96,117,140,165,192,221,252,
|
12
|
+
285,320,357,396,437,480,525,572,621,672,725,780,
|
13
|
+
837,896,957,1020,1085,1152,1221,1292,1365,1440,
|
14
|
+
1517,1596,1677,1760,1845],
|
15
|
+
# A028872
|
16
|
+
-3 => [1,6,13,22,33,46,61,78,97,118,141,166,193,222,253,
|
17
|
+
286,321,358,397,438,481,526,573,622,673,726,781,
|
18
|
+
838,897,958,1021,1086,1153,1222,1293,1366,1441,
|
19
|
+
1518,1597,1678,1761,1846,1933,2022,2113,2206,
|
20
|
+
2301],
|
21
|
+
# A117950
|
22
|
+
3 => [3,4,7,12,19,28,39,52,67,84,103,124,147,172,199,
|
23
|
+
228,259,292,327,364,403,444,487,532,579,628,679,
|
24
|
+
732,787,844,903,964,1027,1092,1159,1228,1299,1372,
|
25
|
+
1447,1524,1603,1684,1767,1852,1939,2028,2119,2212,
|
26
|
+
2307,2404,2503],
|
27
|
+
# A087475
|
28
|
+
4 => [4,5,8,13,20,29,40,53,68,85,104,125,148,173,200,
|
29
|
+
229,260,293,328,365,404,445,488,533,580,629,680,
|
30
|
+
733,788,845,904,965,1028,1093,1160,1229,1300,1373,
|
31
|
+
1448,1525,1604,1685,1768,1853,1940,2029,2120,2213,
|
32
|
+
2308,2405,2504],
|
33
|
+
# A117951
|
34
|
+
5 => [5,6,9,14,21,30,41,54,69,86,105,126,149,174,201,
|
35
|
+
230,261,294,329,366,405,446,489,534,581,630,681,
|
36
|
+
734,789,846,905,966,1029,1094,1161,1230,1301,1374,
|
37
|
+
1449,1526,1605,1686,1769,1854,1941,2030,2121,2214,
|
38
|
+
2309,2406,2505]
|
39
|
+
}
|
40
|
+
|
41
|
+
@seq.each do |k, values|
|
42
|
+
values.each do |n|
|
43
|
+
it "returns true for #{n}^2 #{'+' if k > 0}#{k}" do
|
44
|
+
n.should be_near_square(k)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
values.to_seq.invert.sample(100).each do |n|
|
49
|
+
it "returns false for #{n}^2 #{'+' if k > 0}#{k}" do
|
50
|
+
n.should_not be_near_square(k)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# A005900
|
3
|
+
OCTAHEDRAL = [0,1,6,19,44,85,146,231,344,489,670,891,1156,1469,
|
4
|
+
1834,2255,2736,3281,3894,4579,5340,6181,7106,8119,
|
5
|
+
9224,10425,11726,13131,14644,16269,18010,19871,
|
6
|
+
21856,23969,26214,28595,31116,33781,36594,39559,
|
7
|
+
42680]
|
8
|
+
|
9
|
+
describe Integer, "#octahedral" do
|
10
|
+
OCTAHEDRAL.each_with_index do |o,n|
|
11
|
+
it "returns #{o} as the #{n}#{n.ordinal} octahedral number" do
|
12
|
+
n.octahedral.should == o
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Integer, "#octahedral?" do
|
18
|
+
OCTAHEDRAL.each do |n|
|
19
|
+
it "returns true for octahedral number #{n}" do
|
20
|
+
n.should be_octahedral
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
OCTAHEDRAL.to_seq.invert.sample(100).each do |n|
|
25
|
+
it "returns false for non-octahedral number #{n}" do
|
26
|
+
n.should_not be_octahedral
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
describe Integer, "#palindrome?" do
|
3
|
+
@seq = {
|
4
|
+
# A057148
|
5
|
+
2 => [0,1,0b11,0b101,0b111,0b1001,0b1111,0b10001,0b10101,0b11011,0b11111,
|
6
|
+
0b100001,0b101101,0b110011,0b111111,0b1000001,0b1001001,
|
7
|
+
0b1010101,0b1011101,0b1100011,0b1101011,0b1110111,0b1111111,
|
8
|
+
0b10000001,0b10011001,0b10100101,0b10111101,0b11000011,
|
9
|
+
0b11011011],
|
10
|
+
# A014190
|
11
|
+
3 => [0,1,2,4,8,10,13,16,20,23,26,28,40,52,56,68,80,82,
|
12
|
+
91,100,112,121,130,142,151,160,164,173,182,194,
|
13
|
+
203,212,224,233,242,244,280,316,328,364,400,412,
|
14
|
+
448,484,488,524,560,572,608,644,656,692,728,730,
|
15
|
+
757,784,820,847,874,910],
|
16
|
+
# A014192
|
17
|
+
4 => [0,1,2,3,5,10,15,17,21,25,29,34,38,42,46,51,55,59,
|
18
|
+
63,65,85,105,125,130,150,170,190,195,215,235,255,
|
19
|
+
257,273,289,305,325,341,357,373,393,409,425,441,
|
20
|
+
461,477,493,509,514,530,546,562,582,598,614,630,
|
21
|
+
650,666,682,698,718,734],
|
22
|
+
# A002113
|
23
|
+
10 => [0,1,2,3,4,5,6,7,8,9,11,22,33,44,55,66,77,88,99,
|
24
|
+
101,111,121,131,141,151,161,171,181,191,202,212,
|
25
|
+
222,232,242,252,262,272,282,292,303,313,323,333,
|
26
|
+
343,353,363,373,383,393,404,414,424,434,444,454,
|
27
|
+
464,474,484,494,505,515]
|
28
|
+
}
|
29
|
+
|
30
|
+
@seq.each do |base, ns|
|
31
|
+
ns.each do |n|
|
32
|
+
it "returns true for base-#{base} palindrome #{n}" do
|
33
|
+
n.should be_palindrome(base)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
ns.to_seq.invert.sample(10).each do |n|
|
38
|
+
it "returns false for non-base-#{base} palindrome #{n}" do
|
39
|
+
n.should_not be_palindrome(base)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# A002203
|
2
|
+
PELL_LUCAS = [2,2,6,14,34,82,198,478,1154,2786,6726,16238,
|
3
|
+
39202,94642,228486,551614,1331714,3215042,7761798,
|
4
|
+
18738638,45239074,109216786,263672646,636562078,
|
5
|
+
1536796802,3710155682,8957108166,21624372014,
|
6
|
+
52205852194]
|
7
|
+
|
8
|
+
describe Integer, "#pell_lucas?" do
|
9
|
+
PELL_LUCAS.each do |n|
|
10
|
+
it "returns true for Pell-Lucas number #{n}" do
|
11
|
+
n.should be_pell_lucas
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
PELL_LUCAS.to_seq.invert.sample(10).each do |n|
|
16
|
+
it "returns false for non-Pell-Lucas number #{n}" do
|
17
|
+
n.should_not be_pell_lucas
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe Integer, "#pell_lucas" do
|
23
|
+
PELL_LUCAS.each_with_index do |l, n|
|
24
|
+
it "returns #{l} for the #{n}#{n.ordinal} Pell-Lucas number" do
|
25
|
+
n.pell_lucas.should == l
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
describe Integer, "#pentatope" do
|
3
|
+
# A000332
|
4
|
+
@seq = [0,0,0,0,1,5,15,35,70,126,210,330,495,715,1001,
|
5
|
+
1365,1820,2380,3060,3876,4845,5985,7315,8855,
|
6
|
+
10626,12650,14950,17550,20475,23751,27405,31465,
|
7
|
+
35960,40920,46376,52360,58905,66045,73815,82251,
|
8
|
+
91390,101270,111930,123410][3..-1]
|
9
|
+
|
10
|
+
@seq.each_with_index do |pe, n|
|
11
|
+
it "returns #{pe} for the #{n}#{n.ordinal} pentatope number" do
|
12
|
+
n.pentatope.should == pe
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
describe Integer, "#primitive_abundant?" do
|
3
|
+
# A071395
|
4
|
+
@seq = [20,70,88,104,272,304,368,464,550,572,650,748,836,
|
5
|
+
945,1184,1312,1376,1430,1504,1575,1696,1870,1888,
|
6
|
+
1952,2002,2090,2205,2210,2470,2530,2584,2990,3128,
|
7
|
+
3190,3230,3410,3465,3496,3770,3944,4030,4070,4095,
|
8
|
+
4216,4288]
|
9
|
+
|
10
|
+
@seq.each do |n|
|
11
|
+
it "returns true for primitive abundant number #{n}" do
|
12
|
+
n.should be_primitive_abundant
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
@seq.to_seq.invert.sample(100).each do |n|
|
17
|
+
it "returns false for non-primitive abundant number #{n}" do
|
18
|
+
n.should_not be_primitive_abundant
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
describe Integer, "#pyramidal" do
|
3
|
+
@seq = {
|
4
|
+
# A002411
|
5
|
+
5 => [0,1,6,18,40,75,126,196,288,405,550,726,936,1183,
|
6
|
+
1470,1800,2176,2601,3078,3610,4200,4851,5566,6348,
|
7
|
+
7200,8125,9126,10206,11368,12615,13950,15376,
|
8
|
+
16896,18513,20230,22050,23976,26011,28158,30420,
|
9
|
+
32800,35301][1..-1],
|
10
|
+
# A002413
|
11
|
+
7 => [1,8,26,60,115,196,308,456,645,880,1166,1508,1911,
|
12
|
+
2380,2920,3536,4233,5016,5890,6860,7931,9108,
|
13
|
+
10396,11800,13325,14976,16758,18676,20735,22940,
|
14
|
+
25296,27808,30481,33320,36330,39516,42883,46436,
|
15
|
+
50180,54120],
|
16
|
+
# A002414
|
17
|
+
8 => [1,9,30,70,135,231,364,540,765,1045,1386,1794,
|
18
|
+
2275,2835,3480,4216,5049,5985,7030,8190,9471,
|
19
|
+
10879,12420,14100,15925,17901,20034,22330,24795,
|
20
|
+
27435,30256,33264,36465,39865,43470,47286,51319,
|
21
|
+
55575,60060,64780],
|
22
|
+
# A007586
|
23
|
+
11 => [0,1,12,42,100,195,336,532,792,1125,1540,2046,
|
24
|
+
2652,3367,4200,5160,6256,7497,8892,10450,12180,
|
25
|
+
14091,16192,18492,21000,23725,26676,29862,33292,
|
26
|
+
36975,40920,45136,49632,54417,59500][1..-1],
|
27
|
+
# A130566
|
28
|
+
47 => [1,48,186,460,915,1596,2548,3816,5445,7480,9966,
|
29
|
+
12948,16471,20580,25320,30736,36873,43776,51490,
|
30
|
+
60060,69531,79948,91356,103800,117325,131976,
|
31
|
+
147798,164836,183135,202740,223696,246048,269841,
|
32
|
+
295120,321930,350316,380323]
|
33
|
+
}
|
34
|
+
|
35
|
+
@seq.each do |k, ns|
|
36
|
+
ns.to_enum.with_index(1).each do |py, n|
|
37
|
+
it "returns #{py} for #{k}-pyramidal number #{n}" do
|
38
|
+
n.pyramidal(k).should == py
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/spec/numb/q_spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# A005185
|
3
|
+
Q = [1,1,2,3,3,4,5,5,6,6,6,8,8,8,10,9,10,11,11,12,12,
|
4
|
+
12,12,16,14,14,16,16,16,16,20,17,17,20,21,19,20,
|
5
|
+
22,21,22,23,23,24,24,24,24,24,32,24,25,30,28,26,
|
6
|
+
30,30,28,32,30,32,32,32,32,40,33,31,38,35,33,39,
|
7
|
+
40,37,38,40,39]
|
8
|
+
|
9
|
+
describe Integer, "#q" do
|
10
|
+
Q.to_enum.with_index(1).each do |q, n|
|
11
|
+
it "returns #{q} for #{n}" do
|
12
|
+
n.q.should == q
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Integer, "#q?" do
|
18
|
+
Q.each do |n|
|
19
|
+
it "returns true for Q-number #{n}" do
|
20
|
+
n.should be_q
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# This is unsatisfactory because the abscence of a term in A005185 does not
|
25
|
+
# imply the sequence does not contain it...
|
26
|
+
Q.to_seq.invert.each do |n|
|
27
|
+
it "returns false for non-Q-number #{n}" do
|
28
|
+
n.should_not be_q
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
SCHRODER = [1,2,6,22,90,394,1806,8558,41586,206098,1037718,
|
3
|
+
5293446,27297738,142078746,745387038,3937603038,
|
4
|
+
20927156706,111818026018,600318853926,
|
5
|
+
3236724317174,17518619320890,95149655201962,
|
6
|
+
518431875418926]
|
7
|
+
|
8
|
+
describe Integer, "#schröder" do
|
9
|
+
SCHRODER.each_with_index do |s, n|
|
10
|
+
it "returns #{s} as the #{n}#{n.ordinal} Schröder number" do
|
11
|
+
n.schröder.should == s
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Integer, "#schröder?" do
|
17
|
+
SCHRODER.each do |n|
|
18
|
+
it "returns true for Schröder number #{n}" do
|
19
|
+
n.should be_schröder
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
SCHRODER.to_seq.invert.sample(100) do |n|
|
24
|
+
it "returns false for non-Schröder number #{n}" do
|
25
|
+
n.should_not be_schröder
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# A002048
|
3
|
+
SEGMENTED = [1,2,4,5,8,10,14,15,16,21,22,25,26,28,33,34,35,36,
|
4
|
+
38,40,42,46,48,49,50,53,57,60,62,64,65,70,77,80,
|
5
|
+
81,83,85,86,90,91,92,100,104,107,108,116,119,124,
|
6
|
+
127,132,133,137,141,144,145,148,150,151,154,158,
|
7
|
+
159,163,165]
|
8
|
+
|
9
|
+
describe Integer, "#segmented" do
|
10
|
+
SEGMENTED.to_enum.with_index(1).each do |s, n|
|
11
|
+
it "returns #{s} as the #{n}#{n.ordinal} segmented number" do
|
12
|
+
n.segmented.should == s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Integer, "#segmented?" do
|
18
|
+
SEGMENTED.each do |n|
|
19
|
+
it "returns true for segmented number #{n}" do
|
20
|
+
n.should be_segmented
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
SEGMENTED.to_seq.invert.sample(20).each do |n|
|
25
|
+
it "returns false for non-segmented number #{n}" do
|
26
|
+
n.should_not be_segmented
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
describe Integer, "#square_part" do
|
3
|
+
# A008833
|
4
|
+
@seq = [1,1,1,4,1,1,1,4,9,1,1,4,1,1,1,16,1,9,1,4,1,1,1,4,
|
5
|
+
25,1,9,4,1,1,1,16,1,1,1,36,1,1,1,4,1,1,1,4,9,1,1,
|
6
|
+
16,49,25,1,4,1,9,1,4,1,1,1,4,1,1,9,64,1,1,1,4,1,1,
|
7
|
+
1,36,1,1,25,4,1,1,1,16,81,1,1,4,1,1,1,4,1,9,1,4,1,
|
8
|
+
1,1,16,1]
|
9
|
+
|
10
|
+
@seq.to_enum.with_index(1).each do |sp, n|
|
11
|
+
it "returns #{sp} as the square part of #{n}" do
|
12
|
+
n.square_part.should == sp
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# A003154
|
3
|
+
STAR = [1,13,37,73,121,181,253,337,433,541,661,793,937,
|
4
|
+
1093,1261,1441,1633,1837,2053,2281,2521,2773,3037,
|
5
|
+
3313,3601,3901,4213,4537,4873,5221,5581,5953,6337,
|
6
|
+
6733,7141,7561,7993,8437,8893,9361,9841,10333,
|
7
|
+
10837]
|
8
|
+
|
9
|
+
describe Integer, "#star" do
|
10
|
+
STAR.to_enum.with_index(1).each do |s, n|
|
11
|
+
it "returns #{s} as the #{n}#{n.ordinal} star number" do
|
12
|
+
n.star.should == s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Integer, "#star?" do
|
18
|
+
STAR.each do |n|
|
19
|
+
it "returns true for star number #{n}" do
|
20
|
+
n.should be_star
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
STAR.to_seq.invert.sample(100).each do |n|
|
25
|
+
it "returns false for non-star number #{n}" do
|
26
|
+
n.should_not be_star
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# A007588
|
3
|
+
STELLA_OCTANGULA = [0,1,14,51,124,245,426,679,1016,1449,1990,2651,
|
4
|
+
3444,4381,5474,6735,8176,9809,11646,13699,15980,
|
5
|
+
18501,21274,24311,27624,31225,35126,39339,43876,
|
6
|
+
48749,53970,59551,65504,71841,78574,85715,93276,
|
7
|
+
101269]
|
8
|
+
|
9
|
+
describe Integer, "#stella_octangula" do
|
10
|
+
STELLA_OCTANGULA.each_with_index do |o,n|
|
11
|
+
it "returns #{o} as the #{n}#{n.ordinal} stella octangula number" do
|
12
|
+
n.stella_octangula.should == o
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Integer, "#stella_octangula?" do
|
18
|
+
STELLA_OCTANGULA.each do |n|
|
19
|
+
it "returns true for stella octangula number #{n}" do
|
20
|
+
n.should be_stella_octangula
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
STELLA_OCTANGULA.to_seq.invert.sample(100).each do |n|
|
25
|
+
it "returns false for non-stella-octangula number #{n}" do
|
26
|
+
n.should_not be_stella_octangula
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
describe Integer, "#stirling2" do
|
3
|
+
@seq = [
|
4
|
+
[1],
|
5
|
+
[1, 1],
|
6
|
+
[1, 3, 1],
|
7
|
+
[1, 7, 6, 1],
|
8
|
+
[1, 15, 25, 10, 1],
|
9
|
+
[1, 31, 90, 65, 15, 1],
|
10
|
+
[1, 63, 301, 350, 140, 21, 1],
|
11
|
+
[1, 127, 966, 1701, 1050, 266, 28, 1],
|
12
|
+
[1, 255, 3025, 7770, 6951, 2646, 462, 36, 1],
|
13
|
+
[1, 511, 9330, 34105, 42525, 22827, 5880, 750, 45, 1]
|
14
|
+
]
|
15
|
+
|
16
|
+
@seq.to_enum.with_index(1).each do |row, n|
|
17
|
+
row.to_enum.with_index(1).each do |s, m|
|
18
|
+
it "returns #{s} as the #{n}#{n.ordinal} Stirling number of the 2nd kind (m = #{m})" do
|
19
|
+
n.stirling2(m).should == s
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
describe Integer, "#stirling" do
|
3
|
+
@seq = [
|
4
|
+
[ 1 ],
|
5
|
+
[ -1, 1 ],
|
6
|
+
[ 2, -3, 1 ],
|
7
|
+
[ -6, 11, -6, 1 ],
|
8
|
+
[ 24, -50, 35, -10, 1 ],
|
9
|
+
[ -120, 274, -225, 85, -15, 1 ],
|
10
|
+
[ 720, -1764, 1624, -735, 175, -21, 1 ],
|
11
|
+
[-5040, 13068, -13132, 6769, -1960, 322, -28, 1 ],
|
12
|
+
[40320, -109584, 118124, -67284, 22449, -4536, 546, -36, 1 ],
|
13
|
+
[-362880, 1026576 ]
|
14
|
+
]
|
15
|
+
|
16
|
+
@seq.to_enum.with_index(1).each do |row, n|
|
17
|
+
row.to_enum.with_index(1).each do |s, m|
|
18
|
+
it "returns #{s} as the #{n}#{n.ordinal} Stirling number of the 1st kind (m = #{m})" do
|
19
|
+
n.stirling(m).should == s
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# A001003
|
3
|
+
SUPER_CATALAN = [1,1,3,11,45,197,903,4279,20793,103049,518859,
|
4
|
+
2646723,13648869,71039373,372693519,1968801519,
|
5
|
+
10463578353,55909013009,300159426963,
|
6
|
+
1618362158587,8759309660445,47574827600981,
|
7
|
+
259215937709463,1416461675464871]
|
8
|
+
|
9
|
+
describe Integer, "#super_catalan" do
|
10
|
+
SUPER_CATALAN.to_enum.with_index(1).each do |s, n|
|
11
|
+
it "returns #{s} as the #{n}#{n.ordinal} super-Catalan number" do
|
12
|
+
n.super_catalan.should == s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Integer, "#super_catalan?" do
|
18
|
+
SUPER_CATALAN.each do |n|
|
19
|
+
it "returns true for super-Catalan number #{n}" do
|
20
|
+
n.should be_super_catalan
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
SUPER_CATALAN.to_seq.invert.sample(100).each do |n|
|
25
|
+
it "returns false for non-super-Catalan number #{n}" do
|
26
|
+
n.should_not be_super_catalan
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
describe Integer, "#super_d?" do
|
3
|
+
@seq = {
|
4
|
+
# A032743
|
5
|
+
2 => [19,31,69,81,105,106,107,119,127,131,169,181,190,
|
6
|
+
219,231,247,269,281,310,318,319,331,332,333,334,
|
7
|
+
335,336,337,338,339,348,369,381,419,431,454,469,
|
8
|
+
481,511,519,531,558,569,581,601,619,631,669,679,
|
9
|
+
681,690,715],
|
10
|
+
# A014569
|
11
|
+
3 => [261,462,471,481,558,753,1036,1046,1471,1645,1752,
|
12
|
+
1848,1923,1926,1968,2031,2231,2232,2363,2395,2471,
|
13
|
+
2591,2610,3058,3087,3148,3163,3172,3181,3471,3494,
|
14
|
+
3542,3851,3884,4143,4269,4314,4471,4527,4554,4620,
|
15
|
+
4710,4732],
|
16
|
+
# A032744
|
17
|
+
4 => [1168,4972,7423,7752,8431,10267,11317,11487,11549,
|
18
|
+
11680,16588,16664,16837,18257,18597,19784,19933,
|
19
|
+
22217,22504,22819,22829,24078,24331,24514,25296,
|
20
|
+
25698,26685,26738,27812,27973,28988,32466,32467,
|
21
|
+
32735],
|
22
|
+
# A032745
|
23
|
+
5 => [4602,5517,7539,12955,14555,20137,20379,26629,
|
24
|
+
32767,35689,35825,37706,46020,46715,51988,55170,
|
25
|
+
66344,73338,73974,75390,76157,86025,91497,105852,
|
26
|
+
114488,129550,132234,145550,146399,158651,160897,
|
27
|
+
171673,174782],
|
28
|
+
# A032746
|
29
|
+
6 => [27257,272570,302693,323576,364509,502785,513675,
|
30
|
+
537771,676657,678146,731378,831122,836553,913797,
|
31
|
+
920456,921269,1045361,1144983,1169054,1283069,
|
32
|
+
1288697,1292673,1343642,1346117,1472078,1523993,
|
33
|
+
1640026],
|
34
|
+
# A032747
|
35
|
+
7 => [140997,490996,1184321,1259609,1409970,1783166,
|
36
|
+
1886654,1977538,2457756,2714763,2750425,2980991,
|
37
|
+
3043607,3283057,3689639,4191601,4258476,4642725,
|
38
|
+
4909960,4973029,5242829,5349973,5444788,5523544,
|
39
|
+
5682065],
|
40
|
+
# A032748
|
41
|
+
8 => [185423,641519,1551728,1854230,6415190,12043464,
|
42
|
+
12147605,15517280,16561735,18542300,26908132,
|
43
|
+
29242698,33491333,34982204,35866945,37584428,
|
44
|
+
44263715,45980752,54555936,56148739,60883944,
|
45
|
+
64151900],
|
46
|
+
# A032749
|
47
|
+
9 => [17546133,32613656,93568867,107225764,109255734,
|
48
|
+
113315082,121251742,175461330,180917907,182557181,
|
49
|
+
190215626,227366552,267791979,297981691,298002027,
|
50
|
+
301321202,321541434,326136560,326687646,329178946,
|
51
|
+
351038353]
|
52
|
+
}
|
53
|
+
|
54
|
+
@seq.each do |d, values|
|
55
|
+
values.each do |n|
|
56
|
+
it "returns true for super-#{d} number #{n}" do
|
57
|
+
n.should be_super_d(d)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
values.to_seq.invert.sample(100).each do |n|
|
62
|
+
it "returns false for non-super-#{d} number #{n}" do
|
63
|
+
n.should_not be_super_d(d)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|