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
@@ -0,0 +1,25 @@
1
+ describe Integer, "#repunit?" do
2
+ REPUNITS = {
3
+ 10 => [1, 11, 111, 1111, 11111, 111111, 1111111, 11111111, 111111111],
4
+ 9 => [1, 10, 91, 820, 7381, 66430, 597871, 5380840, 48427561, 435848050],
5
+ 8 => [1, 9, 73, 585, 4681, 37449, 299593, 2396745, 19173961, 153391689],
6
+ 7 => [1, 8, 57, 400, 2801, 19608, 137257, 960800, 6725601, 47079208],
7
+ 6 => [1, 7, 43, 259, 1555, 9331, 55987, 335923, 2015539, 12093235],
8
+ 5 => [1, 6, 31, 156, 781, 3906, 19531, 97656, 488281, 2441406],
9
+ 4 => [1, 5, 21, 85, 341, 1365, 5461, 21845, 87381, 349525],
10
+ 3 => [1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524],
11
+ 2 => [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],
12
+ }
13
+ REPUNITS.each do |base, members|
14
+ members.each do |n|
15
+ it "should return true for #{n} when base = #{base}" do
16
+ n.repunit?(base).should be_true
17
+ end
18
+
19
+ m = n.odd? ? n - 1 : n + 2
20
+ it "should return false for #{m} when base = #{base}" do
21
+ m.repunit?(base).should be_false
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,70 @@
1
+ describe Integer, "#rough?" do
2
+
3
+ ROUGH = {
4
+ # A000027
5
+ 2 => [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
6
+ 20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,
7
+ 36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,
8
+ 52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,
9
+ 68,69,70,71,72,73,74,75,76,77],
10
+ # A005408
11
+ 3 => [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,
12
+ 37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,
13
+ 69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99,
14
+ 101,103,105,107,109,111,113,115,117,119,121,123,
15
+ 125,127,129,131],
16
+ # A007310
17
+ 5 => [1,5,7,11,13,17,19,23,25,29,31,35,37,41,43,47,49,
18
+ 53,55,59,61,65,67,71,73,77,79,83,85,89,91,95,97,
19
+ 101,103,107,109,113,115,119,121,125,127,131,133,
20
+ 137,139,143,145,149],
21
+ # A007775
22
+ 7 => [1,7,11,13,17,19,23,29,31,37,41,43,47,49,53,59,61,
23
+ 67,71,73,77,79,83,89,91,97,101,103,107,109,113,
24
+ 119,121,127,131,133,137,139,143,149,151,157,161,
25
+ 163,167,169,173,179,181,187,191,193,197,199,203,
26
+ 209],
27
+ # A008364
28
+ 11 => [1,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,
29
+ 71,73,79,83,89,97,101,103,107,109,113,121,127,131,
30
+ 137,139,143,149,151,157,163,167,169,173,179,181,
31
+ 187,191,193,197,199,209,211,221,223,227,229,233,
32
+ 239,241,247],
33
+ # A008365
34
+ 13 => [1,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,
35
+ 73,79,83,89,97,101,103,107,109,113,127,131,137,
36
+ 139,149,151,157,163,167,169,173,179,181,191,193,
37
+ 197,199,211,221,223,227,229,233,239,241,247,251,
38
+ 257,263,269],
39
+ # A008366
40
+ 17 => [1,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,
41
+ 79,83,89,97,101,103,107,109,113,127,131,137,139,
42
+ 149,151,157,163,167,173,179,181,191,193,197,199,
43
+ 211,223,227,229,233,239,241,251,257,263,269,271,
44
+ 277,281,283],
45
+ # A166061
46
+ 19 => [1,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,
47
+ 83,89,97,101,103,107,109,113,127,131,137,139,149,
48
+ 151,157,163,167,173,179,181,191,193,197,199,211,
49
+ 223,227,229,233,239,241,251,257,263,269,271],
50
+ # A166063
51
+ 23 => [1,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,
52
+ 89,97,101,103,107,109,113,127,131,137,139,149,151,
53
+ 157,163,167,173,179,181,191,193,197,199,211,223,
54
+ 227,229,233,239,241,251,257,263,269,271]
55
+ }
56
+
57
+ ROUGH.each do |base, members|
58
+ (members.first..members.last).each do |n|
59
+ if members.include?(n)
60
+ it "should return true for rough number #{n} when k=#{base}" do
61
+ n.rough?(base).should be_true
62
+ end
63
+ else
64
+ it "should return false for non-rough number #{n} when k=#{base}" do
65
+ n.rough?(base).should be_false
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,72 @@
1
+ describe Integer, "#smooth?" do
2
+ SMOOTH = {
3
+ # A000079
4
+ 2 => [1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,
5
+ 16384,32768,65536,131072,262144,524288,1048576,
6
+ 2097152,4194304,8388608,16777216,33554432,
7
+ 67108864,134217728,268435456,536870912,1073741824,
8
+ 2147483648,4294967296,8589934592],
9
+ # A003586
10
+ 3 => [1,2,3,4,6,8,9,12,16,18,24,27,32,36,48,54,64,72,
11
+ 81,96,108,128,144,162,192,216,243,256,288,324,384,
12
+ 432,486,512,576,648,729,768,864,972,1024,1152,
13
+ 1296,1458,1536,1728,1944,2048,2187,2304,2592,2916,
14
+ 3072,3456,3888],
15
+ # A051037
16
+ 5 => [1,2,3,4,5,6,8,9,10,12,15,16,18,20,24,25,27,30,32,
17
+ 36,40,45,48,50,54,60,64,72,75,80,81,90,96,100,108,
18
+ 120,125,128,135,144,150,160,162,180,192,200,216,
19
+ 225,240,243,250,256,270,288,300,320,324,360,375,
20
+ 384,400,405],
21
+ # A002473
22
+ 7 => [1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,25,
23
+ 27,28,30,32,35,36,40,42,45,48,49,50,54,56,60,63,
24
+ 64,70,72,75,80,81,84,90,96,98,100,105,108,112,120,
25
+ 125,126,128,135,140,144,147,150,160,162,168,175,
26
+ 180,189,192],
27
+ # A051038
28
+ 11 => [1,2,3,4,5,6,7,8,9,10,11,12,14,15,16,18,20,21,22,
29
+ 24,25,27,28,30,32,33,35,36,40,42,44,45,48,49,50,
30
+ 54,55,56,60,63,64,66,70,72,75,77,80,81,84,88,90,
31
+ 96,98,99,100,105,108,110,112,120,121,125,126,128,
32
+ 132,135,140],
33
+ # A080197
34
+ 13 => [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,20,21,
35
+ 22,24,25,26,27,28,30,32,33,35,36,39,40,42,44,45,
36
+ 48,49,50,52,54,55,56,60,63,64,65,66,70,72,75,77,
37
+ 78,80,81,84,88,90,91,96,98,99,100,104,105,108,110,
38
+ 112,117,120],
39
+ # A080681
40
+ 17 => [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,20,
41
+ 21,22,24,25,26,27,28,30,32,33,34,35,36,39,40,42,
42
+ 44,45,48,49,50,51,52,54,55,56,60,63,64,65,66,68,
43
+ 70,72,75,77,78,80,81,84,85,88,90,91,96,98,99,100,
44
+ 102,104,105],
45
+ # A080682
46
+ 19 => [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
47
+ 20,21,22,24,25,26,27,28,30,32,33,34,35,36,38,39,
48
+ 40,42,44,45,48,49,50,51,52,54,55,56,57,60,63,64,
49
+ 65,66,68,70,72,75,76,77,78,80,81,84,85,88,90,91,
50
+ 95,96,98,99,100],
51
+ # A080683
52
+ 23 => [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
53
+ 20,21,22,23,24,25,26,27,28,30,32,33,34,35,36,38,
54
+ 39,40,42,44,45,46,48,49,50,51,52,54,55,56,57,60,
55
+ 63,64,65,66,68,69,70,72,75,76,77,78,80,81,84,85,
56
+ 88,90,91,92,95]
57
+ }
58
+
59
+ SMOOTH.each do |base, members|
60
+ 20.times.map{ Random.new.rand(members.first..members.last) }.each do |n|
61
+ if members.include?(n)
62
+ it "should return true for #{base}-smooth number #{n}" do
63
+ n.smooth?(base).should be_true
64
+ end
65
+ else
66
+ it "should return false for non-#{base}-rough number #{n}" do
67
+ n.smooth?(base).should be_false
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,59 @@
1
+ # coding: utf-8
1
2
  require 'spec'
2
3
 
3
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
4
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
6
  require 'numb'
6
7
 
8
+
9
+ class Seq
10
+ include Enumerable
11
+ attr_accessor :exclude, :include
12
+ def initialize(*args)
13
+ @include = args.first?
14
+ @exclude = []
15
+ end
16
+
17
+ def each
18
+ @include.each do |e|
19
+ next if @exclude.include?(e)
20
+ yield e
21
+ end
22
+ end
23
+
24
+ def invert
25
+ Seq.new(self.begin..self.end).tap{|s| s.exclude = @include }
26
+ end
27
+
28
+ def begin
29
+ @include.respond_to?(:begin) ? @include.begin : @include.min
30
+ end
31
+
32
+ def end
33
+ @include.respond_to?(:end) ? @include.end : @include.max
34
+ end
35
+
36
+ def sample(n=nil)
37
+ return @include.sample(n) if @include.respond_to?(:sample)
38
+ prng = Random.new
39
+ (n||1).times.map do
40
+ r = prng.rand(@include)
41
+ redo if @exclude.include?(r)
42
+ r
43
+ end.tap{|a| return a.first unless n}
44
+ end
45
+ end
46
+
47
+ class Array
48
+ def first?
49
+ size <= 1 ? first : self
50
+ end
51
+
52
+ def to_seq
53
+ Seq.new *self
54
+ end
55
+ end
56
+
7
57
  Spec::Runner.configure do |config|
8
-
58
+
9
59
  end
@@ -1,3 +1,5 @@
1
+ # coding: utf-8
2
+
1
3
  describe Integer, "#square_free?" do
2
4
  # http://www.research.att.com/~njas/sequences/A005117
3
5
  SQUARE_FREE = [1,2,3,5,6,7,10,11,13,14,15,17,19,21,22,23,26,29,
@@ -0,0 +1,18 @@
1
+ describe Integer, "#sublime?" do
2
+ # A081357
3
+ SUBLIME = [12,
4
+ 6086555670238378989670371734243169622657830773351885970528324860512791691264]
5
+
6
+ SUBLIME.first(1).each do |n|
7
+ it "should return true for sublime number #{n}" do
8
+ n.should be_sublime
9
+ end
10
+ end
11
+
12
+ (1..100).each do |n|
13
+ next if SUBLIME.include?(n)
14
+ it "should return false for non-sublime number #{n}" do
15
+ n.should_not be_sublime
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ describe Integer, "#sum_of_squares" do
2
+
3
+ SOS = [1, # [0, 0, 0, 1]
4
+ 2, # [0, 0, 1, 1]
5
+ 3, # [0, 1, 1, 1]
6
+ 7, # [1, 1, 1, 2]
7
+ 9, # Square number
8
+ 11,# Prime number
9
+ 58, 9634, # Special cases
10
+ 123456789, # Large number
11
+ ] + 1000.times.map { Random.new.rand(10..1000_000)} # Random numbers
12
+ SOS.each do |n|
13
+ squares = n.sum_of_squares
14
+ it "should return an Array of 4 Integers for #{n}" do
15
+ squares.should be_kind_of(Array)
16
+ squares.size.should == 4
17
+ squares.all?{|e| e.should be_kind_of(Integer)}
18
+ end
19
+
20
+ it "should return integers whose squares sum to give the receiver: #{n}" do
21
+ squares.map{|i| i**2}.reduce(:+).should == n
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ describe Integer, "#superabundant?" do
2
+ # A004394
3
+ SUPERABUNDANT = [1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,
4
+ 1260,1680,2520,5040,10080,15120,25200,27720,55440,
5
+ 110880,166320,277200,332640,554400,665280,720720,
6
+ 1441440,2162160,3603600,4324320,7207200,8648640,
7
+ 10810800]
8
+
9
+ SUPERABUNDANT.first(20).each do |n|
10
+ it "should return true for superabundant number #{n}" do
11
+ n.should be_superabundant
12
+ end
13
+ end
14
+
15
+ ((1..SUPERABUNDANT.last).first(20) - SUPERABUNDANT).each do |n|
16
+ it "should return false for non-superabundant number #{n}" do
17
+ n.should_not be_superabundant
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ describe Integer, "#superperfect?" do
2
+ # A019279
3
+ SUPERPERFECT = [2,4,16,64,4096,65536,262144,1073741824,
4
+ 1152921504606846976]
5
+
6
+ SUPERPERFECT[0..-2].each do |n|
7
+ it "returns true for superperfect number #{n}" do
8
+ n.should be_superperfect
9
+ end
10
+ end
11
+
12
+ [1, 3, 5, 78789, 4097].each do |n|
13
+ it "returns false for non-superperfect number #{n}" do
14
+ n.should_not be_superperfect
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ describe Integer, "#totient" do
2
+ # A000010
3
+ TOTIENT = [1,1,2,2,4,2,6,4,6,4,10,4,12,6,8,8,16,6,18,8,12,
4
+ 10,22,8,20,12,18,12,28,8,30,16,20,16,24,12,36,18,
5
+ 24,16,40,12,42,20,24,22,46,16,42,20,32,24,52,18,
6
+ 40,24,36,28,58,16,60,30,36,32,48,20,66,32,44]
7
+
8
+ TOTIENT.each_with_index do |totient, i|
9
+ it "should return #{totient} for #{i.succ}" do
10
+ i.succ.totient.should == totient
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ describe Integer, "#unitary_divisor?" do
2
+ # A034460
3
+ UNITARY_DIVISORS = [0,1,1,1,1,6,1,1,1,8,1,8,1,10,9,1,1,12,1,10,11,14,
4
+ 1,12,1,16,1,12,1,42,1,1,15,20,13,14,1,22,17,14,1,
5
+ 54,1,16,15,26,1,20,1,28,21,18,1,30,17,16,23,32,1,
6
+ 60,1,34,17,1,19,78,1,22,27,74,1,18,1,40,29,24,19,
7
+ 90,1,22,1,44]
8
+
9
+ UNITARY_DIVISORS.each_with_index do |sum, i|
10
+ i = i.succ
11
+ it "should return true for the unitary divisors of #{i}" do
12
+ got = (i.proper_divisors.
13
+ select{|d| i.unitary_divisor?(d)}.
14
+ reduce(:+)) || 0
15
+ sum.should == got
16
+ end
17
+ end
18
+
19
+ it "should return true for 60 and 5" do
20
+ 60.unitary_divisor?(5).should be_true
21
+ end
22
+
23
+ (10..20).each do |n|
24
+ it "returns true when the argument is 1" do
25
+ n.unitary_divisor?(1).should be_true
26
+ end
27
+ end
28
+
29
+ it "should return false for 60 and 6" do
30
+ 60.unitary_divisor?(6).should be_false
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ describe Integer, "#unitary_perfect?" do
2
+ UNITARY_PERFECT = [6,60,90,87360,146361946186458562560000]
3
+
4
+ UNITARY_PERFECT.first(4).each do |n|
5
+ it "should return true for unitary perfect number #{n}" do
6
+ n.should be_unitary_perfect
7
+ end
8
+
9
+ m = n + 7
10
+ it "should return false for non-unitary-perfect number #{m}" do
11
+ m.should_not be_unitary_perfect
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ describe Integer, "#untouchable?" do
2
+ UNTOUCHABLE = [2,5,52,88,96,120,124,146,162,188,206,210,216,238,
3
+ 246,248,262,268,276,288,290,292,304,306,322,324,
4
+ 326,336,342,372,406,408,426,430,448,472,474,498,
5
+ 516,518,520,530,540,552,556,562,576,584,612,624,
6
+ 626,628,658]
7
+
8
+ UNTOUCHABLE.first(5).each do |n|
9
+ it "should return true for untouchable number #{n}" do
10
+ n.should be_untouchable
11
+ end
12
+ end
13
+
14
+ ((1..UNTOUCHABLE.last).to_a - UNTOUCHABLE).first(5).each do |n|
15
+ it "should return false for non-untouchable number #{n}" do
16
+ n.should_not be_untouchable
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ describe Integer, "#zeisel?" do
2
+ # A051015
3
+ ZEISEL = [105,1419,1729,1885,4505,5719,15387,24211,25085,
4
+ 27559,31929,54205,59081,114985,207177,208681,
5
+ 233569,287979,294409,336611,353977,448585,507579,
6
+ 721907,982513,1012121,1073305,1242709,1485609,
7
+ 2089257,2263811,2953711,3077705,3506371,3655861,
8
+ 3973085,4648261,5069629,6173179,6253085,6985249,
9
+ 7355239,7355671,7558219,8011459,8413179,8444431,
10
+ 8712985,9271805,9773731,15411785,18175361,
11
+ 18578113,19827641,20771801,23691481,26000605,
12
+ 26758057]
13
+
14
+ # 721907 appears to be in this sequence by error...
15
+ (ZEISEL - [721907]).each do |n|
16
+ it "should return true for Zeisel number #{n}" do
17
+ n.should be_zeisel
18
+ end
19
+ end
20
+ end