Browse files

Integer#exceptional?/ordinary?: Add

  • Loading branch information...
1 parent 28364f5 commit 6d6b14180768986e5e4c3207aa3e0d72c66aeabd @runpaint committed Mar 28, 2010
Showing with 49 additions and 0 deletions.
  1. +13 −0 lib/numb/divisors.rb
  2. +36 −0 spec/numb/exceptional_spec.rb
View
13 lib/numb/divisors.rb
@@ -422,4 +422,17 @@ def ramanujan_tau
k**2 * (35 * k**2 - 52 * k * n + 18 * n**2) * k.σ * (n-k).σ
end.reduce(:+)
end
+
+ def ordinary?
+ return true if self == 1
+ pf = prime_factors.sort.reverse
+ Prime.first(pf.size).
+ zip(pf).
+ map{|b,e| b**(e-1)}.
+ reduce(:*) == first_with_n_divisors
+ end
+
+ def exceptional?
+ not ordinary?
+ end
end
View
36 spec/numb/exceptional_spec.rb
@@ -0,0 +1,36 @@
+# coding: utf-8
+
+# A072066
+A072066 = [8,16,24,32,48,64,72,80,96,108,112,128,144,160,
+ 162,176,192,208,216,224,243,256,272,288,304,320,
+ 324,352,368,384,416,432,448,464,480,486,496,512,
+ 544,576,592,608,640,648,656,672,688,704,729,736,
+ 752,768,832,848]
+
+describe Integer, "#exceptional?" do
+ A072066.sample(10).each do |n|
+ it "returns true for exceptional number #{n}" do
+ n.should be_exceptional
+ end
+ end
+
+ ([*(1..7)] + A072066.to_seq.invert.to_a).sample(10).each do |n|
+ it "returns false for ordinary number #{n}" do
+ n.should_not be_exceptional
+ end
+ end
+end
+
+describe Integer, "#ordinary?" do
+ ([*(1..7)] + A072066.to_seq.invert.to_a).sample(10).each do |n|
+ it "returns true for ordinary number #{n}" do
+ n.should be_ordinary
+ end
+ end
+
+ A072066.sample(10).each do |n|
+ it "returns false for exceptional number #{n}" do
+ n.should_not be_ordinary
+ end
+ end
+end

0 comments on commit 6d6b141

Please sign in to comment.