numb 0.21.0 → 0.63.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/Rakefile +3 -2
  2. data/VERSION +1 -1
  3. data/lib/numb/abundancy.rb +6 -0
  4. data/lib/numb/abundant.rb +1 -1
  5. data/lib/numb/almost_perfect.rb +6 -0
  6. data/lib/numb/amicable.rb +8 -0
  7. data/lib/numb/aspiring.rb +19 -0
  8. data/lib/numb/centered_n_gonal.rb +9 -0
  9. data/lib/numb/centered_triangular.rb +5 -0
  10. data/lib/numb/congruum.rb +13 -0
  11. data/lib/numb/coprime.rb +9 -0
  12. data/lib/numb/core.rb +7 -0
  13. data/lib/numb/cototient.rb +7 -0
  14. data/lib/numb/d.rb +6 -0
  15. data/lib/numb/deficient.rb +1 -1
  16. data/lib/numb/fermat_pseudoprime.rb +9 -0
  17. data/lib/numb/friendly.rb +9 -0
  18. data/lib/numb/hexagonal.rb +1 -2
  19. data/lib/numb/highly_abundant.rb +7 -0
  20. data/lib/numb/highly_composite.rb +10 -0
  21. data/lib/numb/hyperperfect.rb +1 -1
  22. data/lib/numb/idoneal.rb +65 -0
  23. data/lib/numb/integer_p.rb +11 -0
  24. data/lib/numb/interprime.rb +6 -0
  25. data/lib/numb/jacobsthal_lucas.rb +10 -0
  26. data/lib/numb/k_perfect.rb +8 -0
  27. data/lib/numb/knodel.rb +12 -0
  28. data/lib/numb/leonardo.rb +13 -0
  29. data/lib/numb/leyland.rb +13 -0
  30. data/lib/numb/lucas_carmichael.rb +1 -1
  31. data/lib/numb/mersenne_prime.rb +5 -0
  32. data/lib/numb/minimal.rb +8 -0
  33. data/lib/numb/mobius.rb +5 -6
  34. data/lib/numb/n_gonal.rb +1 -2
  35. data/lib/numb/next_prev_prime.rb +13 -0
  36. data/lib/numb/noncototient.rb +9 -0
  37. data/lib/numb/nth_prime.rb +17 -0
  38. data/lib/numb/number_of_divisors.rb +21 -0
  39. data/lib/numb/octagonal.rb +0 -3
  40. data/lib/numb/ore.rb +8 -0
  41. data/lib/numb/perfect.rb +1 -3
  42. data/lib/numb/perfect_power.rb +1 -1
  43. data/lib/numb/poulet.rb +5 -0
  44. data/lib/numb/powerful.rb +1 -1
  45. data/lib/numb/prime_count.rb +16 -0
  46. data/lib/numb/prime_signature.rb +5 -0
  47. data/lib/numb/primitive_pseudoperfect.rb +1 -1
  48. data/lib/numb/primorial.rb +26 -0
  49. data/lib/numb/proth.rb +12 -0
  50. data/lib/numb/refactorable.rb +7 -0
  51. data/lib/numb/repunit.rb +5 -0
  52. data/lib/numb/rough.rb +5 -0
  53. data/lib/numb/semiperfect.rb +3 -3
  54. data/lib/numb/semiprime.rb +1 -1
  55. data/lib/numb/smooth.rb +5 -0
  56. data/lib/numb/sphenic.rb +1 -3
  57. data/lib/numb/square.rb +1 -2
  58. data/lib/numb/square_free.rb +1 -1
  59. data/lib/numb/sublime.rb +6 -0
  60. data/lib/numb/sum_of_squares.rb +116 -0
  61. data/lib/numb/superabundant.rb +8 -0
  62. data/lib/numb/superperfect.rb +6 -0
  63. data/lib/numb/totient.rb +10 -0
  64. data/lib/numb/unitary_divisor.rb +5 -0
  65. data/lib/numb/unitary_perfect.rb +7 -0
  66. data/lib/numb/untouchable.rb +14 -0
  67. data/lib/numb/zeisel.rb +13 -0
  68. data/lib/numb.rb +35 -28
  69. data/spec/abundancy_spec.rb +20 -0
  70. data/spec/abundant_spec.rb +15 -15
  71. data/spec/achilles_spec.rb +15 -15
  72. data/spec/almost_perfect_spec.rb +20 -0
  73. data/spec/amicable_spec.rb +25 -0
  74. data/spec/aspiring_spec.rb +16 -0
  75. data/spec/automorphic_spec.rb +106 -202
  76. data/spec/balanced_prime_spec.rb +14 -9
  77. data/spec/carmichael_spec.rb +7 -7
  78. data/spec/carol_spec.rb +11 -10
  79. data/spec/centered_n_gonal_spec.rb +66 -0
  80. data/spec/centered_triangular_spec.rb +20 -0
  81. data/spec/composite_spec.rb +13 -12
  82. data/spec/congruum_spec.rb +20 -0
  83. data/spec/coprime_spec.rb +26 -0
  84. data/spec/core_spec.rb +14 -0
  85. data/spec/cube_spec.rb +17 -13
  86. data/spec/d_spec.rb +21 -0
  87. data/spec/decagonal_spec.rb +13 -9
  88. data/spec/deficient_spec.rb +14 -14
  89. data/spec/dihedral_prime_spec.rb +24 -24
  90. data/spec/{factor_spec.rb → divides_spec.rb} +7 -7
  91. data/spec/dodecagonal_spec.rb +10 -8
  92. data/spec/dudeney_spec.rb +9 -7
  93. data/spec/economical_spec.rb +23 -20
  94. data/spec/emrip_spec.rb +12 -12
  95. data/spec/equidigital_spec.rb +15 -15
  96. data/spec/extravagant_spec.rb +12 -12
  97. data/spec/fermat_pseudoprime_spec.rb +78 -0
  98. data/spec/fibonacci_spec.rb +7 -7
  99. data/spec/friendly_spec.rb +38 -0
  100. data/spec/frugal_spec.rb +12 -12
  101. data/spec/happy_spec.rb +14 -14
  102. data/spec/harshad_spec.rb +17 -18
  103. data/spec/heptagonal_spec.rb +14 -9
  104. data/spec/hexagonal_spec.rb +13 -9
  105. data/spec/highly_abundant_spec.rb +20 -0
  106. data/spec/highly_composite_spec.rb +20 -0
  107. data/spec/hilbert_spec.rb +13 -14
  108. data/spec/hyperperfect_spec.rb +25 -55
  109. data/spec/idoneal_spec.rb +20 -0
  110. data/spec/integer_p_spec.rb +21 -0
  111. data/spec/interprime_spec.rb +21 -0
  112. data/spec/jacobsthal_lucas_spec.rb +20 -0
  113. data/spec/k_perfect.rb +40 -0
  114. data/spec/kaprekar_spec.rb +12 -11
  115. data/spec/keith_spec.rb +12 -12
  116. data/spec/knodel_spec.rb +49 -0
  117. data/spec/kynea_spec.rb +11 -11
  118. data/spec/leonardo_spec.rb +20 -0
  119. data/spec/leyland_spec.rb +20 -0
  120. data/spec/lucas_carmichael_spec.rb +14 -8
  121. data/spec/lucas_spec.rb +12 -10
  122. data/spec/maris_mcgwire_sosa_pair_spec.rb +12 -12
  123. data/spec/mersenne_prime_spec.rb +26 -0
  124. data/spec/minimal_spec.rb +19 -0
  125. data/spec/mobius_spec.rb +22 -37
  126. data/spec/myriagonal_spec.rb +9 -7
  127. data/spec/narcissistic_spec.rb +13 -11
  128. data/spec/nivenmorphic_spec.rb +21 -15
  129. data/spec/noncototient_spec.rb +19 -0
  130. data/spec/nth_prime_spec.rb +8 -0
  131. data/spec/number_of_distinct_prime_factors_spec.rb +21 -17
  132. data/spec/number_of_prime_factors_spec.rb +10 -16
  133. data/spec/ore_spec.rb +21 -0
  134. data/spec/perfect_spec.rb +10 -10
  135. data/spec/poulet_spec.rb +20 -0
  136. data/spec/prime_count_spec.rb +13 -0
  137. data/spec/prime_signature_spec.rb +70 -0
  138. data/spec/primorial_spec.rb +30 -0
  139. data/spec/proth_spec.rb +21 -0
  140. data/spec/refactorable_spec.rb +20 -0
  141. data/spec/repunit_spec.rb +25 -0
  142. data/spec/rough_spec.rb +70 -0
  143. data/spec/smooth_spec.rb +72 -0
  144. data/spec/spec_helper.rb +51 -1
  145. data/spec/square_free_spec.rb +2 -0
  146. data/spec/sublime_spec.rb +18 -0
  147. data/spec/sum_of_squares.rb +24 -0
  148. data/spec/superabundant_spec.rb +20 -0
  149. data/spec/superperfect_spec.rb +17 -0
  150. data/spec/totient_spec.rb +13 -0
  151. data/spec/unitary_divisor_spec.rb +32 -0
  152. data/spec/unitary_perfect.rb +14 -0
  153. data/spec/untouchable_spec.rb +19 -0
  154. data/spec/zeisel_spec.rb +20 -0
  155. metadata +144 -10
  156. data/lib/numb/prime.rb +0 -495
  157. data/lib/numb/ruby1.8.rb +0 -9
  158. data/lib/numb/ruby1.9.rb +0 -8
@@ -1,20 +1,20 @@
1
1
  describe Integer, "#maris_mcgwire_sosa_pair?" do
2
+ # A045759
3
+ @seq = [7,14,43,50,61,63,67,80,84,118,122,134,137,163,
4
+ 196,212,213,224,241,273,274,277,279,283,351,352,
5
+ 373,375,390,398,421,457,462,474,475,489,495,510,
6
+ 516,523,526,537,547,555,558,577,584,590,592,616,
7
+ 638,644,660,673,687,691]
2
8
 
3
- MMS = [7,14,43,50,61,63,67,80,84,118,122,134,137,163,
4
- 196,212,213,224,241,273,274,277,279,283,351,352,
5
- 373,375,390,398,421,457,462,474,475,489,495,510,
6
- 516,523,526,537,547,555,558,577,584,590,592,616,
7
- 638,644,660,673,687,691]
8
-
9
- it "returns true for Maris-McGwire-Sosa pairs" do
10
- MMS.each do |number|
11
- number.maris_mcgwire_sosa_pair?(number+1).should be_true
9
+ @seq.each do |n|
10
+ it "returns true for Maris-McGwire-Sosa pair #{n}, #{n+1}" do
11
+ n.maris_mcgwire_sosa_pair?(n+1).should be_true
12
12
  end
13
13
  end
14
14
 
15
- it "returns false for non-Maris-McGwire-Sosa pairs" do
16
- ((1..200).to_a - MMS).each do |number|
17
- number.maris_mcgwire_sosa_pair?(number+1).should be_false
15
+ @seq.map{|e| [e, e+1]}.flatten.to_seq.invert.sample(10).each do |n|
16
+ it "returns true for non-Maris-McGwire-Sosa pair #{n}, #{n+1}" do
17
+ n.maris_mcgwire_sosa_pair?(n+1).should be_false
18
18
  end
19
19
  end
20
20
  end
@@ -0,0 +1,26 @@
1
+ describe Integer, "#mersenne_prime?" do
2
+ # A000668
3
+ @seq = [3,7,31,127,8191,131071,524287,2147483647,
4
+ 2305843009213693951,618970019642690137449562111,
5
+ 162259276829213363391578010288127,
6
+ 170141183460469231731687303715884105727].to_seq
7
+
8
+ @seq.first(6).each do |n|
9
+ it "should return true for Mersenne prime #{n}" do
10
+ n.should be_mersenne_prime
11
+ end
12
+ end
13
+
14
+ @seq.invert.first(500).sample(10).each do |n|
15
+ it "should return false for non-Mersenne prime #{n}" do
16
+ n.should_not be_mersenne_prime
17
+ end
18
+ end
19
+
20
+ (Prime.first(12).to_a - @seq.to_a).each do |n|
21
+ it "should return false for a prime which isn't Mersenne: #{n}" do
22
+ n.should_not be_mersenne_prime
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,19 @@
1
+ describe Integer, "#minimal?" do
2
+ # A007416
3
+ @seq = [1,2,4,6,12,16,24,36,48,60,64,120,144,180,192,240,
4
+ 360,576,720,840,900,960,1024,1260,1296,1680,2520,
5
+ 2880,3072,3600,4096,5040,5184,6300,6480,6720,7560,
6
+ 9216,10080].to_seq
7
+
8
+ @seq.first(20).sample(10).each do |n|
9
+ it "should return true for minimal number #{n}" do
10
+ n.should be_minimal
11
+ end
12
+ end
13
+
14
+ @seq.invert.sample(10).each do |n|
15
+ it "should return false for non-minimal number #{n}" do
16
+ n.should_not be_minimal
17
+ end
18
+ end
19
+ end
data/spec/mobius_spec.rb CHANGED
@@ -1,52 +1,37 @@
1
1
  # coding: utf-8
2
2
  describe Integer, "#mobius" do
3
- # http://www.research.att.com/~njas/sequences/A008683
4
- MOBIUS = [1,-1,-1,0,-1,1,-1,0,0,1,-1,0,-1,1,1,0,-1,0,-1,0,
5
- 1,1,-1,0,0,1,0,0,-1,-1,-1,0,1,1,1,0,-1,1,1,0,-1,
6
- -1,-1,0,0,1,-1,0,0,0,1,0,-1,0,1,0,1,1,-1,0,-1,1,0,
7
- 0,1,-1,-1,0,1,-1,-1,0,-1,1,0,0,1]
3
+ # A008683
4
+ @seq = [1,-1,-1,0,-1,1,-1,0,0,1,-1,0,-1,1,1,0,-1,0,-1,0,
5
+ 1,1,-1,0,0,1,0,0,-1,-1,-1,0,1,1,1,0,-1,1,1,0,-1,
6
+ -1,-1,0,0,1,-1,0,0,0,1,0,-1,0,1,0,1,1,-1,0,-1,1,0,
7
+ 0,1,-1,-1,0,1,-1,-1,0,-1,1,0,0,1].to_seq
8
8
 
9
- it "returns 1 if n is a square-free positive integer with an even number of distinct prime factors" do
10
- MOBIUS.each_with_index do |value, idx|
11
- next unless value == 1
12
- (idx + 1).mobius.should == 1
9
+ @seq.each_with_index do |i, n|
10
+ it "should return #{i} for #{n}" do
11
+ n.succ.mobius.should == i
13
12
  end
14
- end
15
13
 
16
- it "returns −1 if n is a square-free positive integer with an odd number of distinct prime factors" do
17
- MOBIUS.each_with_index do |value, idx|
18
- next unless value == -1
19
- (idx + 1).mobius.should == -1
14
+ it "should return nil for negative number #{-n}" do
15
+ (-n.succ).mobius.should be_nil
20
16
  end
21
17
  end
22
18
 
23
19
  it "returns −1 if n is prime" do
24
- Prime.each(200).each do |prime|
25
- next if MOBIUS.size < prime
26
- prime.mobius.should == -1
20
+ Prime.first(10).each do |n|
21
+ n.mobius.should == -1
27
22
  end
28
23
  end
29
24
 
30
- it "returns 0 iff n is not square-free." do
31
- MOBIUS.each_with_index do |value, idx|
32
- next unless value == 0
33
- (idx + 1).mobius.should == 0
34
- end
35
-
36
- # http://www.research.att.com/~njas/sequences/A013929
37
- [4,8,9,12,16,18,20,24,25,27,28,32,36,40,44,45,48,
38
- 49,50,52,54,56,60,63,64,68,72,75,76,80,81,84,88,
39
- 90,92,96,98,99,100,104,108,112,116,117,120,121,
40
- 124,125,126,128,132,135,136,140,144,147,148,150,
41
- 152,153,156,160].each do |number|
42
- next if MOBIUS.size < number
43
- number.mobius.should == 0
25
+
26
+ # A013929
27
+ @seq = [4,8,9,12,16,18,20,24,25,27,28,32,36,40,44,45,48,
28
+ 49,50,52,54,56,60,63,64,68,72,75,76,80,81,84,88,
29
+ 90,92,96,98,99,100,104,108,112,116,117,120,121,
30
+ 124,125,126,128,132,135,136,140,144,147,148,150,
31
+ 152,153,156,160]
32
+ @seq.sample(10).each do |n|
33
+ it "should return 0 for non-square-free number #{n}" do
34
+ n.mobius.should == 0
44
35
  end
45
36
  end
46
-
47
- it "returns nil if n is not a positive integer" do
48
- (0..25).each do |number|
49
- (-number).mobius.should be_nil
50
- end
51
- end
52
37
  end
@@ -1,15 +1,17 @@
1
1
  describe Integer, "#myriagonal?" do
2
2
 
3
- MYRIAGONAL = [0, 1, 10000, 29997, 59992, 99985, 149976, 209965, 279952,
4
- 359937, 449920, 549901, 659880, 779857, 909832, 1049805,
5
- 1199776, 1359745, 1529712, 1709677, 1899640, 2099601]
3
+ @spec = [0, 1, 10000, 29997, 59992, 99985, 149976, 209965, 279952,
4
+ 359937, 449920, 549901, 659880, 779857, 909832, 1049805,
5
+ 1199776, 1359745, 1529712, 1709677, 1899640, 2099601].to_seq
6
6
 
7
- it "should return true for myriagonal numbers" do
8
- MYRIAGONAL.shuffle.first(2).each{|n| n.should be_myriagonal}
7
+ @spec.each do |n|
8
+ it "should return true for myriagonal number #{n}" do
9
+ n.should be_myriagonal
10
+ end
9
11
  end
10
12
 
11
- it "should return false for non-myriagonal numbers" do
12
- ((0..MYRIAGONAL.last).to_a - MYRIAGONAL).shuffle.first(2).each do |n|
13
+ @spec.invert.sample(10).each do |n|
14
+ it "should return false for non-myriagonal number #{n}" do
13
15
  n.should_not be_myriagonal
14
16
  end
15
17
  end
@@ -1,18 +1,20 @@
1
1
  describe Integer, "#narcissistic?" do
2
- NARCISSISTIC = [1,2,3,4,5,6,7,8,9,153,370,371,407,1634,8208,9474,
3
- 54748,92727,93084,548834,1741725,4210818,9800817,
4
- 9926315,24678050,24678051,88593477,146511208,
5
- 472335975,534494836,912985153,4679307774,
6
- 32164049650,32164049651]
7
- it "returns true for narcissistic numbers" do
8
- NARCISSISTIC.each do |number|
9
- number.should be_narcissistic
2
+ # A005188
3
+ @seq =[1,2,3,4,5,6,7,8,9,153,370,371,407,1634,8208,9474,
4
+ 54748,92727,93084,548834,1741725,4210818,9800817,
5
+ 9926315,24678050,24678051,88593477,146511208,
6
+ 472335975,534494836,912985153,4679307774,
7
+ 32164049650,32164049651].to_seq
8
+
9
+ @seq.sample(10).each do |n|
10
+ it "returns true for narcissistic number #{n}" do
11
+ n.should be_narcissistic
10
12
  end
11
13
  end
12
14
 
13
- it "returns false for non-narcissistic numbers" do
14
- [10,30,100,178762628].each do |number|
15
- number.should_not be_narcissistic
15
+ @seq.invert.sample(10).each do |n|
16
+ it "returns false for non-narcissistic number #{n}" do
17
+ n.should_not be_narcissistic
16
18
  end
17
19
  end
18
20
  end
@@ -1,24 +1,30 @@
1
1
  describe Integer, "#nivenmorphic?" do
2
- NIVENMORPHIC = [1,2,3,4,5,6,7,8,9,910,0,912,11713,6314,915,3616,
3
- 15317,918,17119,9920,18921,9922,82823,19824,9925,
4
- 46826,18927,18928,78329,99930,585931,388832,
5
- 1098933,198934,289835,99936,99937,478838,198939,
6
- 1999840]
7
- it "returns true for Nivenmorphic numbers" do
8
- NIVENMORPHIC.each do |number|
9
- number.should be_nivenmorphic
2
+ # A075154
3
+ @seq = [1,2,3,4,5,6,7,8,9,910,0,912,11713,6314,915,3616,
4
+ 15317,918,17119,9920,18921,9922,82823,19824,9925,
5
+ 46826,18927,18928,78329,99930,585931,388832,
6
+ 1098933,198934,289835,99936,99937,478838,198939,
7
+ 1999840].to_seq
8
+
9
+ @seq.sample(10).each do |n|
10
+ it "returns true for Nivenmorphic number #{n}" do
11
+ n.should be_nivenmorphic
10
12
  end
11
- end
12
13
 
13
- it "returns false for non-Nivenmorphic numbers" do
14
- ((1..300).to_a - NIVENMORPHIC).each do |number|
15
- number.should_not be_nivenmorphic
14
+ next if n.zero?
15
+ it "returns false for negative Nivenmorphic number #{-n}" do
16
+ (-n).should_not be_nivenmorphic
16
17
  end
17
18
  end
18
19
 
19
- it "returns false for negative numbers" do
20
- (1..300).each do |number|
21
- (-number).should_not be_nivenmorphic
20
+ @seq.invert.sample(10).each do |n|
21
+ next if n.zero?
22
+ it "returns false for non-Nivenmorphic number #{n}" do
23
+ n.should_not be_nivenmorphic
24
+ end
25
+
26
+ it "returns false for negative non-Nivenmorphic number #{-n}" do
27
+ (-n).should_not be_nivenmorphic
22
28
  end
23
29
  end
24
30
  end
@@ -0,0 +1,19 @@
1
+ describe Integer, "#noncototient?" do
2
+ # A005278
3
+ @seq = [10,26,34,50,52,58,86,100,116,122,130,134,146,154,
4
+ 170,172,186,202,206,218,222,232,244,260,266,268,
5
+ 274,290,292,298,310,326,340,344,346,362,366,372,
6
+ 386,394,404,412,436,466,470,474,482,490,518,520].to_seq
7
+
8
+ @seq.sample(10).each do |n|
9
+ it "should return true for noncototient number #{n}" do
10
+ n.should be_noncototient
11
+ end
12
+ end
13
+
14
+ @seq.invert.sample(10).each do |n|
15
+ it "should return false for cototient number #{n}" do
16
+ n.should_not be_noncototient
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ describe Integer, "#nth_prime" do
2
+ Prime.first(20).each_with_index do |prime, n|
3
+ n = n.succ
4
+ it "should return #{prime} as the #{n}#{n.ordinal} prime" do
5
+ n.nth_prime.should == prime
6
+ end
7
+ end
8
+ end
@@ -1,28 +1,32 @@
1
1
  # coding: utf-8
2
2
  describe Integer, "#number_of_distinct_prime_factors" do
3
- # http://www.research.att.com/~njas/sequences/A001221
4
- OMEGA = [0,1,1,1,1,2,1,1,1,2,1,2,1,2,2,1,1,2,1,2,2,2,1,2,
5
- 1,2,1,2,1,3,1,1,2,2,2,2,1,2,2,2,1,3,1,2,2,2,1,2,1,
6
- 2,2,2,1,2,2,2,2,2,1,3,1,2,2,1,2,3,1,2,2,3,1,2,1,2,
7
- 2,2,2,3,1,2,1,2,1,3,2,2,2,2,1,3,2,2,2,2,2,2,1,2,2,
8
- 2,1,3,1,2,3,2,1,2,1,3,2]
3
+ # A001221
4
+ @seq = [0,1,1,1,1,2,1,1,1,2,1,2,1,2,2,1,1,2,1,2,2,2,1,2,
5
+ 1,2,1,2,1,3,1,1,2,2,2,2,1,2,2,2,1,3,1,2,2,2,1,2,1,
6
+ 2,2,2,1,2,2,2,2,2,1,3,1,2,2,1,2,3,1,2,2,3,1,2,1,2,
7
+ 2,2,2,3,1,2,1,2,1,3,2,2,2,2,1,3,2,2,2,2,2,2,1,2,2,
8
+ 2,1,3,1,2,3,2,1,2,1,3,2].to_seq
9
9
 
10
- it "returns the number of distinct prime factors of self" do
11
- OMEGA.each_with_index do |omega, number|
12
- (number + 1).number_of_distinct_prime_factors.should == omega
10
+ @seq.each_with_index do |omega, n|
11
+ it "should return #{omega} for #{n}" do
12
+ n.succ.number_of_distinct_prime_factors.should == omega
13
13
  end
14
+ end
14
15
 
15
- # http://www.research.att.com/~njas/sequences/A046386
16
- [210,330,390,462,510,546,570,690,714,770,798,858,
17
- 870,910,930,966,1110,1122,1155,1190,1218,1230,
18
- 1254,1290,1302,1326,1330,1365,1410,1430,1482,1518,
19
- 1554,1590,1610,1722,1770,1785,1794,1806,1830,1870,
20
- 1914,1938,1974].each do |number|
21
- number.number_of_distinct_prime_factors.should == 4
16
+ # A046386
17
+ @seq = [210,330,390,462,510,546,570,690,714,770,798,858,
18
+ 870,910,930,966,1110,1122,1155,1190,1218,1230,
19
+ 1254,1290,1302,1326,1330,1365,1410,1430,1482,1518,
20
+ 1554,1590,1610,1722,1770,1785,1794,1806,1830,1870,
21
+ 1914,1938,1974].to_seq
22
+
23
+ @seq.each do |n|
24
+ it "should return 4 for #{n}" do
25
+ n.number_of_distinct_prime_factors.should == 4
22
26
  end
23
27
  end
24
28
 
25
- it "does not count any factor more than once" do
29
+ it "should not count factors with multiplicity" do
26
30
  [4, 8, 9, 12, 16, 18, 20, 24, 25, 27, 28, 32, 36, 40, 44, 45, 48, 49,
27
31
  50, 52, 54, 56, 60, 63, 64, 68, 72, 75, 76, 80, 81, 84, 88, 90, 92,
28
32
  96, 98, 99, 100, 104, 108, 112, 116, 117, 120, 121, 124, 125, 126, 128,
@@ -1,25 +1,19 @@
1
1
  # coding: utf-8
2
2
  describe Integer, "#number_of_prime_factors" do
3
- # http://www.research.att.com/~njas/sequences/A001222
4
- BIGOMEGA = [0,1,1,2,1,2,1,3,2,2,1,3,1,2,2,4,1,3,1,3,2,2,1,4,
5
- 2,2,3,3,1,3,1,5,2,2,2,4,1,2,2,4,1,3,1,3,3,2,1,5,2,
6
- 3,2,3,1,4,2,4,2,2,1,4,1,2,3,6,2,3,1,3,2,3,1,5,1,2,
7
- 3,3,2,3,1,5,4,2,1,4,2,2,2,4,1,4,2,3,2,2,2,6,1,3,3,
8
- 4,1,3,1,4,3,2,1,5,1,3,2]
3
+ # A001222
4
+ @seq = [0,1,1,2,1,2,1,3,2,2,1,3,1,2,2,4,1,3,1,3,2,2,1,4,
5
+ 2,2,3,3,1,3,1,5,2,2,2,4,1,2,2,4,1,3,1,3,3,2,1,5,2,
6
+ 3,2,3,1,4,2,4,2,2,1,4,1,2,3,6,2,3,1,3,2,3,1,5,1,2,
7
+ 3,3,2,3,1,5,4,2,1,4,2,2,2,4,1,4,2,3,2,2,2,6,1,3,3,
8
+ 4,1,3,1,4,3,2,1,5,1,3,2].to_seq
9
9
 
10
- it "returns the number of prime factors (counted with multiplicity) of self" do
11
- BIGOMEGA.each_with_index do |bigomega, number|
12
- (number + 1).number_of_prime_factors.should == bigomega
10
+ @seq.each_with_index do |bigomega, n|
11
+ it "should return #{bigomega} for #{n.succ}" do
12
+ n.succ.number_of_prime_factors.should == bigomega
13
13
  end
14
14
  end
15
15
 
16
- it "is >= ω" do
17
- BIGOMEGA.each_with_index do |bigomega, number|
18
- (number + 1).number_of_prime_factors.should >= (number + 1).number_of_distinct_prime_factors
19
- end
20
- end
21
-
22
- it "counts factors more than once" do
16
+ it "should count factors with multiplicity" do
23
17
  [4, 8, 9, 12, 16, 18, 20, 24, 25, 27, 28, 32, 36, 40, 44, 45, 48, 49,
24
18
  50, 52, 54, 56, 60, 63, 64, 68, 72, 75, 76, 80, 81, 84, 88, 90, 92,
25
19
  96, 98, 99, 100, 104, 108, 112, 116, 117, 120, 121, 124, 125, 126, 128,
data/spec/ore_spec.rb ADDED
@@ -0,0 +1,21 @@
1
+ describe Integer, "#ore?" do
2
+ # A001599
3
+ ORE = [1,6,28,140,270,496,672,1638,2970,6200,8128,8190,
4
+ 18600,18620,27846,30240,32760,55860,105664,117800,
5
+ 167400,173600,237510,242060,332640,360360,539400,
6
+ 695520,726180,753480,950976,1089270,1421280,
7
+ 1539720]
8
+
9
+ ORE.each do |n|
10
+ it "returns true for Ore number #{n}" do
11
+ n.should be_ore
12
+ end
13
+ end
14
+
15
+ (1..1_000).each do |n|
16
+ next if ORE.include? n
17
+ it "returns false for non-Ore number #{n}" do
18
+ n.should_not be_ore
19
+ end
20
+ end
21
+ end
data/spec/perfect_spec.rb CHANGED
@@ -43,41 +43,41 @@ describe Integer, "#perfect?" do
43
43
  end
44
44
  end
45
45
 
46
- describe Integer, "#proper_positive_divisors" do
46
+ describe Integer, "#proper_divisors" do
47
47
  it "returns an Array" do
48
- 6.proper_positive_divisors.should be_an_instance_of(Array)
48
+ 6.proper_divisors.should be_an_instance_of(Array)
49
49
  end
50
50
 
51
51
  it "returns integers that divide into self with no remainder" do
52
- 6.proper_positive_divisors.should include(2, 3)
52
+ 6.proper_divisors.should include(2, 3)
53
53
  end
54
54
 
55
55
  it "doesn't return integers that divide into self with a remainder" do
56
- 6.proper_positive_divisors.should_not include(4, 5)
56
+ 6.proper_divisors.should_not include(4, 5)
57
57
  end
58
58
 
59
59
  it "doesn't return itself as a divisor" do
60
- 9.proper_positive_divisors.should_not include(9)
60
+ 9.proper_divisors.should_not include(9)
61
61
  end
62
62
 
63
63
  it "returns all of the proper divisors of self" do
64
- 33.proper_positive_divisors.sort.should == [1, 3, 11]
64
+ 33.proper_divisors.sort.should == [1, 3, 11]
65
65
  end
66
66
 
67
67
  it "returns [] for 1" do
68
- 1.proper_positive_divisors.should == []
68
+ 1.proper_divisors.should == []
69
69
  end
70
70
 
71
71
  it "returns [] for 0" do
72
- 0.proper_positive_divisors.should == []
72
+ 0.proper_divisors.should == []
73
73
  end
74
74
 
75
75
  it "returns [] for -1" do
76
- -1.proper_positive_divisors.should == []
76
+ -1.proper_divisors.should == []
77
77
  end
78
78
 
79
79
  it "returns [] when self is negative" do
80
- -32.proper_positive_divisors.should == []
80
+ -32.proper_divisors.should == []
81
81
  end
82
82
  end
83
83
 
@@ -0,0 +1,20 @@
1
+ describe Integer, "#poulet?" do
2
+ # A001567
3
+ @seq = [341,561,645,1105,1387,1729,1905,2047,2465,2701,
4
+ 2821,3277,4033,4369,4371,4681,5461,6601,7957,8321,
5
+ 8481,8911,10261,10585,11305,12801,13741,13747,
6
+ 13981,14491,15709,15841,16705,18705,18721,19951,
7
+ 23001,23377,25761,29341].to_seq
8
+
9
+ @seq.each do |n|
10
+ it "should return true for Poulet number #{n}" do
11
+ n.should be_poulet
12
+ end
13
+ end
14
+
15
+ @seq.invert.sample(10).each do |n|
16
+ it "should false true for non-Poulet number #{n}" do
17
+ n.should_not be_poulet
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ describe Integer, "#prime_count" do
2
+ # A000720
3
+ PRIME_COUNT = [0,1,2,2,3,3,4,4,4,4,5,5,6,6,6,6,7,7,8,8,8,8,9,9,
4
+ 9,9,9,9,10,10,11,11,11,11,11,11,12,12,12,12,13,13,
5
+ 14,14,14,14,15,15,15,15,15,15,16,16,16,16,16,16,
6
+ 17,17,18,18,18,18,18,18,19,19,19,19,20,20,21,21,
7
+ 21,21,21,21]
8
+ PRIME_COUNT.each_with_index do |count, n|
9
+ it "should return #{count} for #{n.succ}" do
10
+ n.succ.prime_count.should == count
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,70 @@
1
+ describe Integer, "#prime_signature" do
2
+ SIGNATURES = {
3
+ # A000040
4
+ [1] => [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,
5
+ 61,67,71,73,79,83,89,97,101,103,107,109,113,127,
6
+ 131,137,139,149,151,157,163,167,173,179,181,191,
7
+ 193,197,199,211,223,227,229,233,239,241,251,257,
8
+ 263,269,271],
9
+ # A001248
10
+ [2] => [4,9,25,49,121,169,289,361,529,841,961,1369,1681,
11
+ 1849,2209,2809,3481,3721,4489,5041,5329,6241,6889,
12
+ 7921,9409,10201,10609,11449,11881,12769,16129,
13
+ 17161,18769,19321,22201],
14
+ # A006881
15
+ [1,1] => [6,10,14,15,21,22,26,33,34,35,38,39,46,51,55,57,
16
+ 58,62,65,69,74,77,82,85,86,87,91,93,94,95,106,111,
17
+ 115,118,119,122,123,129,133,134,141,142,143,145,
18
+ 146,155,158,159,161,166,177,178,183,185,187,194,
19
+ 201,202,203,205],
20
+ # A030078
21
+ [3] => [8,27,125,343,1331,2197,4913,6859,12167,24389,
22
+ 29791,50653,68921,79507,103823,148877,205379,
23
+ 226981,300763,357911,389017,493039,571787,704969,
24
+ 912673,1030301,1092727,1225043,1295029,1442897],
25
+ # A054753
26
+ [2,1] => [12,18,20,28,44,45,50,52,63,68,75,76,92,98,99,116,
27
+ 117,124,147,148,153,164,171,172,175,188,207,212,
28
+ 236,242,244,245,261,268,275,279,284,292,316,325,
29
+ 332,333,338,356,363,369,387,388,404,412,423,425,
30
+ 428,436,452],
31
+ # A030514
32
+ [4] => [16,81,625,2401,14641,28561,83521,130321,279841,
33
+ 707281,923521,1874161,2825761,3418801,4879681,
34
+ 7890481,12117361,13845841,20151121,25411681,
35
+ 28398241,38950081,47458321,62742241,88529281,
36
+ 104060401],
37
+ # A065036
38
+ [3,1] => [24,40,54,56,88,104,135,136,152,184,189,232,248,
39
+ 250,296,297,328,344,351,375,376,424,459,472,488,
40
+ 513,536,568,584,621,632,664,686,712,776,783,808,
41
+ 824,837,856,872,875,904,999,1016,1029,1048,1096,
42
+ 1107,1112],
43
+ # A007304
44
+ [1,1,1] => [30,42,66,70,78,102,105,110,114,130,138,154,165,
45
+ 170,174,182,186,190,195,222,230,231,238,246,255,
46
+ 258,266,273,282,285,286,290,310,318,322,345,354,
47
+ 357,366,370,374,385,399,402,406,410,418,426,429,
48
+ 430,434,435,438],
49
+ # A050997
50
+ [5] => [32,243,3125,16807,161051,371293,1419857,2476099,
51
+ 6436343,20511149,28629151,69343957,115856201,
52
+ 147008443,229345007,418195493,714924299,844596301,
53
+ 1350125107,1804229351,2073071593,3077056399,
54
+ 3939040643],
55
+ # A085986
56
+ [2,2] => [36,100,196,225,441,484,676,1089,1156,1225,1444,
57
+ 1521,2116,2601,3025,3249,3364,3844,4225,4761,5476,
58
+ 5929,6724,7225,7396,7569,8281,8649,8836,9025,
59
+ 11236,12321,13225,13924,14161,14884,15129,16641,
60
+ 17689,17956,19881]
61
+ }
62
+
63
+ SIGNATURES.each do |sig, members|
64
+ members.each do |n|
65
+ it "should return #{sig} for #{n}" do
66
+ n.prime_signature.should == sig
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,30 @@
1
+ # A034386
2
+ PRIMORIAL = [1,2,6,6,30,30,210,210,210,210,2310,2310,30030,
3
+ 30030,30030,30030,510510,510510,9699690,9699690,
4
+ 9699690,9699690,223092870,223092870,223092870,
5
+ 223092870,223092870,223092870,6469693230,
6
+ 6469693230]
7
+
8
+ describe Integer, "#primorial" do
9
+
10
+ PRIMORIAL.each_with_index do |n,i|
11
+ i = i.succ
12
+ it "should return #{n} for #{i}" do
13
+ i.primorial.should == n
14
+ end
15
+ end
16
+ end
17
+
18
+ describe Integer, "#primorial?" do
19
+ PRIMORIAL.uniq.each do |n|
20
+ it "should return true for primorial number #{n}" do
21
+ n.should be_primorial
22
+ end
23
+ end
24
+
25
+ ((1..PRIMORIAL.last).first(20) - PRIMORIAL).uniq.each do |n|
26
+ it "should return false for non-primorial number #{n}" do
27
+ n.should_not be_primorial
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,21 @@
1
+ describe Integer, "#proth?" do
2
+ # A080075
3
+ PROTH = [3,5,9,13,17,25,33,41,49,57,65,81,97,113,129,145,
4
+ 161,177,193,209,225,241,257,289,321,353,385,417,
5
+ 449,481,513,545,577,609,641,673,705,737,769,801,
6
+ 833,865,897,929,961,993,1025,1089,1153,1217,1281,
7
+ 1345,1409]
8
+
9
+ PROTH.each do |n|
10
+ it "should return true for Proth number #{n}" do
11
+ n.should be_proth
12
+ end
13
+ end
14
+
15
+ (1..PROTH.last).each do |n|
16
+ next if PROTH.include? n
17
+ it "should return false for non-Proth number #{n}" do
18
+ n.should_not be_proth
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ describe Integer, "#refactorable?" do
2
+ # A033950
3
+ REFACTORABLE = [1,2,8,9,12,18,24,36,40,56,60,72,80,84,88,96,104,
4
+ 108,128,132,136,152,156,180,184,204,225,228,232,
5
+ 240,248,252,276,288,296,328,344,348,360,372,376,
6
+ 384,396,424,441,444,448,450,468,472,480,488,492,
7
+ 504,516,536]
8
+
9
+ (1..REFACTORABLE.last).each do |n|
10
+ if REFACTORABLE.include?(n)
11
+ it "should return true for refactorable number #{n}" do
12
+ n.should be_refactorable
13
+ end
14
+ else
15
+ it "should return false for non-refactorable number #{n}" do
16
+ n.should_not be_refactorable
17
+ end
18
+ end
19
+ end
20
+ end