numb 0.84.0 → 0.89.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. data/Rakefile +3 -10
  2. data/VERSION +1 -1
  3. data/lib/numb/dihedral_prime.rb +8 -2
  4. data/lib/numb/goldbach.rb +6 -0
  5. data/lib/numb/nivenmorphic.rb +1 -1
  6. data/lib/numb/nonhypotenuse.rb +7 -0
  7. data/lib/numb/safe_prime.rb +5 -0
  8. data/lib/numb/st/303/270rmer.rb +6 -0
  9. data/lib/numb/unusual.rb +5 -0
  10. data/spec/{dihedral_prime_spec.rb → numb/dihedral_prime_spec.rb} +1 -1
  11. data/spec/numb/goldbach_spec.rb +23 -0
  12. data/spec/{nivenmorphic_spec.rb → numb/nivenmorphic_spec.rb} +7 -7
  13. data/spec/numb/nonhypotenuse_spec.rb +20 -0
  14. data/spec/{perfect_spec.rb → numb/perfect_spec.rb} +0 -2
  15. data/spec/numb/safe_prime_spec.rb +20 -0
  16. data/spec/numb/st/303/270rmer_spec.rb +21 -0
  17. data/spec/numb/unusual_spec.rb +20 -0
  18. data/spec/spec_helper.rb +1 -5
  19. metadata +289 -276
  20. data/spec/01_spec.rb +0 -1
  21. /data/spec/{abundancy_spec.rb → numb/abundancy_spec.rb} +0 -0
  22. /data/spec/{abundant_spec.rb → numb/abundant_spec.rb} +0 -0
  23. /data/spec/{achilles_spec.rb → numb/achilles_spec.rb} +0 -0
  24. /data/spec/{almost_perfect_spec.rb → numb/almost_perfect_spec.rb} +0 -0
  25. /data/spec/{almost_prime_spec.rb → numb/almost_prime_spec.rb} +0 -0
  26. /data/spec/{amicable_spec.rb → numb/amicable_spec.rb} +0 -0
  27. /data/spec/{apocalyptic_spec.rb → numb/apocalyptic_spec.rb} +0 -0
  28. /data/spec/{aspiring_spec.rb → numb/aspiring_spec.rb} +0 -0
  29. /data/spec/{augmented_amicable_spec.rb → numb/augmented_amicable_spec.rb} +0 -0
  30. /data/spec/{automorphic_spec.rb → numb/automorphic_spec.rb} +0 -0
  31. /data/spec/{balanced_prime_spec.rb → numb/balanced_prime_spec.rb} +0 -0
  32. /data/spec/{base_spec.rb → numb/base_spec.rb} +0 -0
  33. /data/spec/{binomial_spec.rb → numb/binomial_spec.rb} +0 -0
  34. /data/spec/{biquadratic_spec.rb → numb/biquadratic_spec.rb} +0 -0
  35. /data/spec/{breeder_spec.rb → numb/breeder_spec.rb} +0 -0
  36. /data/spec/{brown_spec.rb → numb/brown_spec.rb} +0 -0
  37. /data/spec/{carmichael_spec.rb → numb/carmichael_spec.rb} +0 -0
  38. /data/spec/{carol_spec.rb → numb/carol_spec.rb} +0 -0
  39. /data/spec/{centered_n_gonal_spec.rb → numb/centered_n_gonal_spec.rb} +0 -0
  40. /data/spec/{centered_triangular_spec.rb → numb/centered_triangular_spec.rb} +0 -0
  41. /data/spec/{composite_spec.rb → numb/composite_spec.rb} +0 -0
  42. /data/spec/{congruum_spec.rb → numb/congruum_spec.rb} +0 -0
  43. /data/spec/{coprime_spec.rb → numb/coprime_spec.rb} +0 -0
  44. /data/spec/{core_spec.rb → numb/core_spec.rb} +0 -0
  45. /data/spec/{cube_spec.rb → numb/cube_spec.rb} +0 -0
  46. /data/spec/{d_spec.rb → numb/d_spec.rb} +0 -0
  47. /data/spec/{decagonal_spec.rb → numb/decagonal_spec.rb} +0 -0
  48. /data/spec/{deficient_spec.rb → numb/deficient_spec.rb} +0 -0
  49. /data/spec/{digital_sum_spec.rb → numb/digital_sum_spec.rb} +0 -0
  50. /data/spec/{divides_spec.rb → numb/divides_spec.rb} +0 -0
  51. /data/spec/{dodecagonal_spec.rb → numb/dodecagonal_spec.rb} +0 -0
  52. /data/spec/{dudeney_spec.rb → numb/dudeney_spec.rb} +0 -0
  53. /data/spec/{economical_spec.rb → numb/economical_spec.rb} +0 -0
  54. /data/spec/{emrip_spec.rb → numb/emrip_spec.rb} +0 -0
  55. /data/spec/{equidigital_spec.rb → numb/equidigital_spec.rb} +0 -0
  56. /data/spec/{evil_spec.rb → numb/evil_spec.rb} +0 -0
  57. /data/spec/{extravagant_spec.rb → numb/extravagant_spec.rb} +0 -0
  58. /data/spec/{factorial_spec.rb → numb/factorial_spec.rb} +0 -0
  59. /data/spec/{factorion_spec.rb → numb/factorion_spec.rb} +0 -0
  60. /data/spec/{fermat_pseudoprime_spec.rb → numb/fermat_pseudoprime_spec.rb} +0 -0
  61. /data/spec/{fibonacci_spec.rb → numb/fibonacci_spec.rb} +0 -0
  62. /data/spec/{friendly_spec.rb → numb/friendly_spec.rb} +0 -0
  63. /data/spec/{frugal_spec.rb → numb/frugal_spec.rb} +0 -0
  64. /data/spec/{happy_spec.rb → numb/happy_spec.rb} +0 -0
  65. /data/spec/{harshad_spec.rb → numb/harshad_spec.rb} +0 -0
  66. /data/spec/{heptagonal_spec.rb → numb/heptagonal_spec.rb} +0 -0
  67. /data/spec/{hexagonal_spec.rb → numb/hexagonal_spec.rb} +0 -0
  68. /data/spec/{highly_abundant_spec.rb → numb/highly_abundant_spec.rb} +0 -0
  69. /data/spec/{highly_composite_spec.rb → numb/highly_composite_spec.rb} +0 -0
  70. /data/spec/{hilbert_spec.rb → numb/hilbert_spec.rb} +0 -0
  71. /data/spec/{hyperperfect_spec.rb → numb/hyperperfect_spec.rb} +0 -0
  72. /data/spec/{idoneal_spec.rb → numb/idoneal_spec.rb} +0 -0
  73. /data/spec/{integer_p_spec.rb → numb/integer_p_spec.rb} +0 -0
  74. /data/spec/{interprime_spec.rb → numb/interprime_spec.rb} +0 -0
  75. /data/spec/{jacobsthal_lucas_spec.rb → numb/jacobsthal_lucas_spec.rb} +0 -0
  76. /data/spec/{k_perfect.rb → numb/k_perfect_spec.rb} +0 -0
  77. /data/spec/{kaprekar_spec.rb → numb/kaprekar_spec.rb} +0 -0
  78. /data/spec/{keith_spec.rb → numb/keith_spec.rb} +0 -0
  79. /data/spec/{knodel_spec.rb → numb/knodel_spec.rb} +0 -0
  80. /data/spec/{kynea_spec.rb → numb/kynea_spec.rb} +0 -0
  81. /data/spec/{leonardo_spec.rb → numb/leonardo_spec.rb} +0 -0
  82. /data/spec/{leyland_spec.rb → numb/leyland_spec.rb} +0 -0
  83. /data/spec/{lucas_carmichael_spec.rb → numb/lucas_carmichael_spec.rb} +0 -0
  84. /data/spec/{lucas_spec.rb → numb/lucas_spec.rb} +0 -0
  85. /data/spec/{maris_mcgwire_sosa_pair_spec.rb → numb/maris_mcgwire_sosa_pair_spec.rb} +0 -0
  86. /data/spec/{mersenne_prime_spec.rb → numb/mersenne_prime_spec.rb} +0 -0
  87. /data/spec/{minimal_spec.rb → numb/minimal_spec.rb} +0 -0
  88. /data/spec/{mobius_spec.rb → numb/mobius_spec.rb} +0 -0
  89. /data/spec/{myriagonal_spec.rb → numb/myriagonal_spec.rb} +0 -0
  90. /data/spec/{narcissistic_spec.rb → numb/narcissistic_spec.rb} +0 -0
  91. /data/spec/{noncototient_spec.rb → numb/noncototient_spec.rb} +0 -0
  92. /data/spec/{nth_prime_spec.rb → numb/nth_prime_spec.rb} +0 -0
  93. /data/spec/{number_of_distinct_prime_factors_spec.rb → numb/number_of_distinct_prime_factors_spec.rb} +0 -0
  94. /data/spec/{number_of_prime_factors_spec.rb → numb/number_of_prime_factors_spec.rb} +0 -0
  95. /data/spec/{octagonal_spec.rb → numb/octagonal_spec.rb} +0 -0
  96. /data/spec/{odious_spec.rb → numb/odious_spec.rb} +0 -0
  97. /data/spec/{ordinal_spec.rb → numb/ordinal_spec.rb} +0 -0
  98. /data/spec/{ore_spec.rb → numb/ore_spec.rb} +0 -0
  99. /data/spec/{parasitic_spec.rb → numb/parasitic_spec.rb} +0 -0
  100. /data/spec/{pentagonal_spec.rb → numb/pentagonal_spec.rb} +0 -0
  101. /data/spec/{perfect_power_spec.rb → numb/perfect_power_spec.rb} +0 -0
  102. /data/spec/{polite_spec.rb → numb/polite_spec.rb} +0 -0
  103. /data/spec/{politeness_spec.rb → numb/politeness_spec.rb} +0 -0
  104. /data/spec/{polydivisible_spec.rb → numb/polydivisible_spec.rb} +0 -0
  105. /data/spec/{positive_spec.rb → numb/positive_spec.rb} +0 -0
  106. /data/spec/{poulet_spec.rb → numb/poulet_spec.rb} +0 -0
  107. /data/spec/{powerful_spec.rb → numb/powerful_spec.rb} +0 -0
  108. /data/spec/{practical_spec.rb → numb/practical_spec.rb} +0 -0
  109. /data/spec/{prime_count_spec.rb → numb/prime_count_spec.rb} +0 -0
  110. /data/spec/{prime_signature_spec.rb → numb/prime_signature_spec.rb} +0 -0
  111. /data/spec/{primitive_pseudoperfect_spec.rb → numb/primitive_pseudoperfect_spec.rb} +0 -0
  112. /data/spec/{primorial_spec.rb → numb/primorial_spec.rb} +0 -0
  113. /data/spec/{pronic_spec.rb → numb/pronic_spec.rb} +0 -0
  114. /data/spec/{proth_spec.rb → numb/proth_spec.rb} +0 -0
  115. /data/spec/{quarticfree_spec.rb → numb/quarticfree_spec.rb} +0 -0
  116. /data/spec/{refactorable_spec.rb → numb/refactorable_spec.rb} +0 -0
  117. /data/spec/{repunit_spec.rb → numb/repunit_spec.rb} +0 -0
  118. /data/spec/{rhonda_spec.rb → numb/rhonda_spec.rb} +0 -0
  119. /data/spec/{rough_spec.rb → numb/rough_spec.rb} +0 -0
  120. /data/spec/{self_descriptive_spec.rb → numb/self_descriptive_spec.rb} +0 -0
  121. /data/spec/{self_spec.rb → numb/self_spec.rb} +0 -0
  122. /data/spec/{semi_perfect_spec.rb → numb/semi_perfect_spec.rb} +0 -0
  123. /data/spec/{semiprime_spec.rb → numb/semiprime_spec.rb} +0 -0
  124. /data/spec/{smarandache_wellin_spec.rb → numb/smarandache_wellin_spec.rb} +0 -0
  125. /data/spec/{smith_spec.rb → numb/smith_spec.rb} +0 -0
  126. /data/spec/{smooth_spec.rb → numb/smooth_spec.rb} +0 -0
  127. /data/spec/{sociable_spec.rb → numb/sociable_spec.rb} +0 -0
  128. /data/spec/{sophie_germain_prime_spec.rb → numb/sophie_germain_prime_spec.rb} +0 -0
  129. /data/spec/{sphenic_spec.rb → numb/sphenic_spec.rb} +0 -0
  130. /data/spec/{square_free_spec.rb → numb/square_free_spec.rb} +0 -0
  131. /data/spec/{square_spec.rb → numb/square_spec.rb} +0 -0
  132. /data/spec/{sublime_spec.rb → numb/sublime_spec.rb} +0 -0
  133. /data/spec/{sum_of_squares.rb → numb/sum_of_squares_spec.rb} +0 -0
  134. /data/spec/{sum_of_unitary_divisors_spec.rb → numb/sum_of_unitary_divisors_spec.rb} +0 -0
  135. /data/spec/{superabundant_spec.rb → numb/superabundant_spec.rb} +0 -0
  136. /data/spec/{superperfect_spec.rb → numb/superperfect_spec.rb} +0 -0
  137. /data/spec/{totient_spec.rb → numb/totient_spec.rb} +0 -0
  138. /data/spec/{triangular_spec.rb → numb/triangular_spec.rb} +0 -0
  139. /data/spec/{trimorphic_spec.rb → numb/trimorphic_spec.rb} +0 -0
  140. /data/spec/{twin_prime_spec.rb → numb/twin_prime_spec.rb} +0 -0
  141. /data/spec/{undulating_spec.rb → numb/undulating_spec.rb} +0 -0
  142. /data/spec/{unhappy_spec.rb → numb/unhappy_spec.rb} +0 -0
  143. /data/spec/{unitary_amicable_spec.rb → numb/unitary_amicable_spec.rb} +0 -0
  144. /data/spec/{unitary_divisor_spec.rb → numb/unitary_divisor_spec.rb} +0 -0
  145. /data/spec/{unitary_perfect.rb → numb/unitary_perfect_spec.rb} +0 -0
  146. /data/spec/{unitary_sociable.rb → numb/unitary_sociable_spec.rb} +0 -0
  147. /data/spec/{untouchable_spec.rb → numb/untouchable_spec.rb} +0 -0
  148. /data/spec/{vampire_spec.rb → numb/vampire_spec.rb} +0 -0
  149. /data/spec/{weird_spec.rb → numb/weird_spec.rb} +0 -0
  150. /data/spec/{wieferich_prime_spec.rb → numb/wieferich_prime_spec.rb} +0 -0
  151. /data/spec/{woodall_spec.rb → numb/woodall_spec.rb} +0 -0
  152. /data/spec/{zeisel_spec.rb → numb/zeisel_spec.rb} +0 -0
  153. /data/spec/{zerofree_spec.rb → numb/zerofree_spec.rb} +0 -0
data/Rakefile CHANGED
@@ -21,16 +21,9 @@ rescue LoadError
21
21
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
22
22
  end
23
23
 
24
- require 'spec/rake/spectask'
25
- Spec::Rake::SpecTask.new(:spec) do |spec|
26
- spec.libs << 'lib' << 'spec'
27
- spec.spec_files = FileList['spec/spec_helper.rb', 'spec/**/*_spec.rb']
28
- end
29
-
30
- Spec::Rake::SpecTask.new(:rcov) do |spec|
31
- spec.libs << 'lib' << 'spec'
32
- spec.pattern = 'spec/**/*_spec.rb'
33
- spec.rcov = true
24
+ require 'rspec/core/rake_task'
25
+ Rspec::Core::RakeTask.new do |spec|
26
+ spec.ruby_opts = '-r./spec/spec_helper'
34
27
  end
35
28
 
36
29
  begin
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.84.0
1
+ 0.89.0
@@ -19,7 +19,13 @@ class Integer
19
19
  # 7.dihedral_prime? #=> false
20
20
  #
21
21
  def dihedral_prime?
22
- return false unless prime?
23
- !!to_s.match(/^[01825][018253]*$/)
22
+ return false unless prime? and to_s.match(/^[01825]+$/)
23
+ mirror = ->(n){ n.to_s.gsub(/([25])/){|orig| orig == '2' ? '5' : '2'}.to_i }
24
+ [upside_down, mirror[self], mirror[upside_down]].all?(&:prime?)
25
+ end
26
+
27
+ private
28
+ def upside_down
29
+ to_s.reverse.to_i
24
30
  end
25
31
  end
@@ -0,0 +1,6 @@
1
+ class Integer
2
+ def goldbach?
3
+ return false unless even? and self > 2
4
+ downto(2).any?{|n| n.prime? and (self - n).prime?}
5
+ end
6
+ end
@@ -3,7 +3,7 @@ class Integer
3
3
  def nivenmorphic?
4
4
  return true if self == 0
5
5
  return false unless positive?
6
- niven? && self.to_s.end_with?(digital_sum.to_s)
6
+ niven? && to_s.end_with?(digital_sum.to_s)
7
7
  end
8
8
  alias :harshadmorphic? :nivenmorphic?
9
9
  end
@@ -0,0 +1,7 @@
1
+ class Integer
2
+ def nonhypotenuse?
3
+ # Shanks, Daniel Non-hypotenuse numbers. Fibonacci Quart. 13 (1975), no.
4
+ # 4, 319-321.
5
+ prime_factors.none?{|f| (f - 1).divides?(4) }
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class Integer
2
+ def safe_prime?
3
+ prime? and odd? and ((self - 1) / 2).prime?
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ # coding: utf-8
2
+ class Integer
3
+ def størmer?
4
+ ((self ** 2) + 1).prime_factors.max >= 2 * self
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class Integer
2
+ def unusual?
3
+ prime_factors.max > Math.sqrt(self)
4
+ end
5
+ end
@@ -18,7 +18,7 @@ describe Integer, "#dihedral_prime?" do
18
18
  end
19
19
  end
20
20
 
21
- @seq.invert.sample(10).each do |n|
21
+ @seq.invert.sample(100).each do |n|
22
22
  it "returns false for non-Dihedral-prime #{n}" do
23
23
  n.should_not be_dihedral_prime
24
24
  end
@@ -0,0 +1,23 @@
1
+ describe Integer, "#goldbach?" do
2
+ it "returns false for numbers less than or equal to 2" do
3
+ (0..2).each{|n| n.should_not be_goldbach}
4
+ end
5
+
6
+ it "returns false for any odd number" do
7
+ prng = Random.new
8
+ 100.times do
9
+ n = prng.rand(3..100000001)
10
+ redo if n.even?
11
+ n.should_not be_goldbach
12
+ end
13
+ end
14
+
15
+ it "returns true for any even number that is the sum of two primes" do
16
+ prng = Random.new
17
+ 100.times do
18
+ n = prng.rand(4..100000001)
19
+ redo if n.odd?
20
+ n.should be_goldbach
21
+ end
22
+ end
23
+ end
@@ -1,12 +1,12 @@
1
1
  describe Integer, "#nivenmorphic?" do
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
2
+ # A070938
3
+ @seq = [1,2,3,4,5,6,7,8,9,910,912,915,918,1810,1812,1815,
4
+ 1818,2710,2712,2715,2718,3610,3612,3615,3616,3618,
5
+ 4510,4512,4515,4518,5410,5412,5415,5418,6310,6312,
6
+ 6314,6315,6318,7210,7212,7215,7216,7218,8110,8112,
7
+ 8115,8118].to_seq
8
8
 
9
- @seq.sample(10).each do |n|
9
+ @seq.each do |n|
10
10
  it "returns true for Nivenmorphic number #{n}" do
11
11
  n.should be_nivenmorphic
12
12
  end
@@ -0,0 +1,20 @@
1
+ describe Integer, "#nonhypotenuse" do
2
+ # A004144
3
+ @seq = [1,2,3,4,6,7,8,9,11,12,14,16,18,19,21,22,23,24,27,
4
+ 28,31,32,33,36,38,42,43,44,46,47,48,49,54,56,57,
5
+ 59,62,63,64,66,67,69,71,72,76,77,79,81,83,84,86,
6
+ 88,92,93,94,96,98,99,103,107,108,112,114,118,121,
7
+ 124,126,127]
8
+
9
+ @seq.each do |n|
10
+ it "should return true for nonhypotenuse number #{n}" do
11
+ n.should be_nonhypotenuse
12
+ end
13
+ end
14
+
15
+ @seq.to_seq.invert.each do |n|
16
+ it "should return false for nonhypotenuse number #{n}" do
17
+ n.should_not be_nonhypotenuse
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,3 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
1
  describe Integer, "#perfect?" do
4
2
  it "returns true for the first 7 perfect numbers" do
5
3
  [6, 28, 496, 8128, 33550336, 8589869056, 137438691328].each do |n|
@@ -0,0 +1,20 @@
1
+ describe Integer, "#safe_prime?" do
2
+ # A005385
3
+ @seq = [5,7,11,23,47,59,83,107,167,179,227,263,347,359,
4
+ 383,467,479,503,563,587,719,839,863,887,983,1019,
5
+ 1187,1283,1307,1319,1367,1439,1487,1523,1619,1823,
6
+ 1907,2027,2039,2063,2099,2207,2447,2459,2579,2819,
7
+ 2879,2903]
8
+
9
+ @seq.each do |n|
10
+ it "returns true for safe prime #{n}" do
11
+ n.should be_safe_prime
12
+ end
13
+ end
14
+
15
+ @seq.to_seq.invert.sample(100).each do |n|
16
+ it "returns false for non-safe prime #{n}" do
17
+ n.should_not be_safe_prime
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ describe Integer, "#størmer?" do
3
+ # A005528
4
+ @seq = [1,2,4,5,6,9,10,11,12,14,15,16,19,20,22,23,24,25,
5
+ 26,27,28,29,33,34,35,36,37,39,40,42,44,45,48,49,
6
+ 51,52,53,54,56,58,59,60,61,62,63,64,65,66,67,69,
7
+ 71,74,77,78,79,80,81,82,84,85,86,87,88,89,90,92,
8
+ 94,95,96]
9
+
10
+ @seq.each do |n|
11
+ it "returns true for Størmer number #{n}" do
12
+ n.should be_størmer
13
+ end
14
+ end
15
+
16
+ @seq.to_seq.invert.each do |n|
17
+ it "returns false for non-Størmer number #{n}" do
18
+ n.should_not be_størmer
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ describe Integer, "#unusual?" do
2
+ # A064052
3
+ @seq = [2,3,5,6,7,10,11,13,14,15,17,19,20,21,22,23,26,28,
4
+ 29,31,33,34,35,37,38,39,41,42,43,44,46,47,51,52,
5
+ 53,55,57,58,59,61,62,65,66,67,68,69,71,73,74,76,
6
+ 77,78,79,82,83,85,86,87,88,89,91,92,93,94,95,97,
7
+ 99,101,102]
8
+
9
+ @seq.each do |n|
10
+ it "returns true for unusual number #{n}" do
11
+ n.should be_unusual
12
+ end
13
+ end
14
+
15
+ @seq.to_seq.invert.each do |n|
16
+ it "returns false for non-unusual number #{n}" do
17
+ n.should_not be_unusual
18
+ end
19
+ end
20
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
- require 'spec'
2
+ require 'rspec/core'
3
3
 
4
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
5
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -57,7 +57,3 @@ class Array
57
57
  Seq.new *self
58
58
  end
59
59
  end
60
-
61
- Spec::Runner.configure do |config|
62
-
63
- end