numb 0.114.0 → 0.125.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.114.0
1
+ 0.125.0
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
  class Integer
3
- def aliquot_sequence(max_iterations=(self > 100 ? 10 : Math.sqrt(self)),
3
+ def aliquot_sequence(max_iterations=(self > 100 ? 10 : sqrt),
4
4
  summatory_function=->(n){ n.aliquot_sum })
5
5
  sequence = [self]
6
6
  max_iterations.floor.times do |limit|
@@ -5,4 +5,18 @@ class Integer
5
5
  (self - 1).remainder(p - 1) == 0
6
6
  end
7
7
  end
8
+
9
+ def carmichael
10
+ case self
11
+ when 1, 2 then 1
12
+ when 4 then 2
13
+ else
14
+ if primaries.size == 1
15
+ p, a = primaries.first
16
+ return totient if p.odd?
17
+ return totient/2 if p == 2 and a >= 3
18
+ end
19
+ primaries.map{|p| p.reduce(:**)}.map(&:carmichael).reduce(&:lcm)
20
+ end
21
+ end
8
22
  end
@@ -0,0 +1,6 @@
1
+ class Integer
2
+ def centered_pentagonal?
3
+ n = self - 1
4
+ n.divides?(5) and (n/5).triangular?
5
+ end
6
+ end
data/lib/numb/cube.rb CHANGED
@@ -1,8 +1,5 @@
1
1
  class Integer
2
2
  def cube?
3
- y = self < 0 ? (-self) : self
4
- x = Math.cbrt(y)
5
- # The hack below is seemingly needed for 1.8 compatibility
6
- x.ceil.to_f.to_s == x.to_s
3
+ Math.cbrt(self).integer?
7
4
  end
8
5
  end
@@ -0,0 +1,7 @@
1
+ class Integer
2
+ def cullen?
3
+ return true if self == 1
4
+ factors = (self - 1).divisors.sort
5
+ factors.first(factors.size/2).any?{|n| n * 2**n + 1 == self}
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ class Integer
2
+ def cyclic?
3
+ return true if zero?
4
+ return false unless digits.size >= 6
5
+ nzd = nonzero_digits.sort
6
+ (1...digits.size).all?{|n| (self * n).nonzero_digits.sort == nzd}
7
+ end
8
+
9
+ def nonzero_digits
10
+ digits.reject(&:zero?)
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ class Integer
2
+ def delannoy?
3
+ return true if self == 1
4
+ max_a, max_b = self/2, self/2
5
+ (1..max_a).each do |a|
6
+ (1..max_b).each do |b|
7
+ d = a.delannoy(b)
8
+ return true if d == self
9
+ if d > self
10
+ max_b = b
11
+ max_a = a
12
+ break
13
+ end
14
+ end
15
+ break if a > max_a
16
+ end
17
+ false
18
+ end
19
+
20
+ def delannoy(b)
21
+ a = self
22
+ return 1 if b.zero? or a.zero?
23
+ [(a - 1).delannoy(b), a.delannoy(b - 1), (a - 1).delannoy(b - 1)].reduce(:+)
24
+ end
25
+ end
data/lib/numb/demlo.rb ADDED
@@ -0,0 +1,9 @@
1
+ class Integer
2
+ def demlo
3
+ repunit ** 2
4
+ end
5
+
6
+ def demlo?
7
+ square? and isqrt.repunit?(10)
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ class Integer
2
+ def full_reptend_prime?
3
+ prime? and primitive_root?(10)
4
+ end
5
+ end
@@ -6,6 +6,6 @@ end
6
6
 
7
7
  class Float
8
8
  def integer?
9
- self == to_i
9
+ round(10) == to_i
10
10
  end
11
11
  end
data/lib/numb/leyland.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class Integer
2
2
  def leyland?
3
- (2..Math.sqrt(self)).each do |x|
4
- (x..Math.sqrt(self)).each do |y|
3
+ (2..sqrt).each do |x|
4
+ (x..sqrt).each do |y|
5
5
  sum = x**y + y**x
6
6
  return true if sum == self
7
7
  break if sum > self
@@ -0,0 +1,12 @@
1
+ class Integer
2
+ def modulo_order(n)
3
+ return 0 if n < 1
4
+ return 1 if self == 2 and n == 1
5
+ (1..n.totient).each{|e| return e if (self**e).modulo(n) == 1}
6
+ 0
7
+ end
8
+ alias :haupt_exponent :modulo_order
9
+ alias :multiplicative_order :modulo_order
10
+ # TODO: Add Rational#period for calculating the period of the decimal
11
+ # expansion of the rational in terms the multiplicative order of 10
12
+ end
@@ -2,7 +2,7 @@
2
2
  class Integer
3
3
  def noncototient?
4
4
  return false if self < 10 or odd?
5
- (Math.sqrt(self).floor..(2 * self)).none? do |m|
5
+ (isqrt..(2 * self)).none? do |m|
6
6
  m.cototient == self
7
7
  end
8
8
  end
@@ -7,11 +7,10 @@ class Integer
7
7
  def τ
8
8
  n = self
9
9
  return @nod if defined?(@nod)
10
- square_root = Math.sqrt(n)
11
- @nod = (1..square_root.floor).
10
+ @nod = (1..isqrt).
12
11
  map {|i| n.quo(i).to_i - (n - 1).quo(i).to_i }.
13
12
  reduce(:+) * 2
14
- @nod -= 1 if square_root.integer?
13
+ @nod -= 1 if square?
15
14
  @nod
16
15
  end
17
16
 
@@ -0,0 +1,15 @@
1
+ class Integer
2
+ def primitive_root?(g=nil)
3
+ if g
4
+ return true if g.zero? and self == 1
5
+ coprime?(g) and g.modulo_order(self) == totient
6
+ else
7
+ return true if [1, 2, 4].include?(self)
8
+ prime_factors.select(&:odd?).any? do |p|
9
+ [1,2].any? do |x|
10
+ Math.log(self / x, p).integer?
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ class Integer
2
+ def primitive_roots
3
+ return [] unless primitive_root?
4
+ (0..self).select{|n| primitive_root?(n)}
5
+ end
6
+ end
data/lib/numb/pronic.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  class Integer
2
2
  def pronic?
3
3
  return false unless even? and (positive? or zero?)
4
- (Math.sqrt(succ).round - Math.sqrt(self).round) == 1
4
+ (Math.sqrt(succ).round - sqrt.round) == 1
5
5
  end
6
6
  end
data/lib/numb/repunit.rb CHANGED
@@ -2,4 +2,8 @@ class Integer
2
2
  def repunit?(base)
3
3
  !!to_s(base).match(/^1+$/)
4
4
  end
5
+
6
+ def repunit
7
+ (10 ** self) / 9
8
+ end
5
9
  end
data/lib/numb/square.rb CHANGED
@@ -2,6 +2,6 @@
2
2
  class Integer
3
3
  def square?
4
4
  return false if self < 0
5
- Math.sqrt(self).integer?
5
+ sqrt.integer?
6
6
  end
7
7
  end
@@ -1,5 +1,5 @@
1
1
  class Integer
2
2
  def squared_triangular?
3
- square? and Math.sqrt(self).to_i.triangular?
3
+ square? and sqrt.to_i.triangular?
4
4
  end
5
5
  end
@@ -5,6 +5,6 @@ end
5
5
  class Integer
6
6
  def strictly_non_palindromic?
7
7
  return true if (0..4).include?(self) or self == 6
8
- prime? and (2..(Math.sqrt(self).floor)).none?{|base| base(base).palindrome?}
8
+ prime? and (2..(isqrt)).none?{|base| base(base).palindrome?}
9
9
  end
10
10
  end
data/lib/numb/unusual.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class Integer
2
2
  def unusual?
3
- prime_factors.max > Math.sqrt(self)
3
+ prime_factors.max > sqrt
4
4
  end
5
5
  end
data/lib/numb.rb CHANGED
@@ -22,6 +22,14 @@ class Integer
22
22
  divisors.select{|d| d > 1}.select{|d| d.odd?}.size
23
23
  end
24
24
 
25
+ def sqrt
26
+ Math.sqrt(self)
27
+ end
28
+
29
+ def isqrt
30
+ sqrt.floor
31
+ end
32
+
25
33
  def proper_divisors
26
34
  divisors.reject {|d| d == self }
27
35
  end
@@ -29,8 +37,8 @@ class Integer
29
37
  def divisors
30
38
  return [] unless positive?
31
39
  return [1, self] if prime?
32
- (1..Math.sqrt(self).floor).select { |n| (self % n).zero? }.
33
- map {|n| [n, self/n]}.flatten.uniq
40
+ (1..isqrt).select { |n| (self % n).zero? }.
41
+ map {|n| [n, self/n]}.flatten.uniq
34
42
  end
35
43
 
36
44
  def sum_of_divisors
@@ -64,4 +72,8 @@ end
64
72
 
65
73
  require 'prime'
66
74
 
75
+ class Integer
76
+ alias :primaries :prime_division
77
+ end
78
+
67
79
  Dir.glob(File.dirname(__FILE__) + '/numb/*.rb').each {|file| require file}
@@ -18,3 +18,18 @@ describe Integer, "#carmichael?" do
18
18
  end
19
19
  end
20
20
  end
21
+
22
+ describe Integer, "#carmichael" do
23
+ # A002322
24
+ @seq = [1,1,2,2,4,2,6,2,6,4,10,2,12,6,4,4,16,6,18,4,6,10,
25
+ 22,2,20,12,18,6,28,4,30,8,10,16,12,6,36,18,12,4,
26
+ 40,6,42,10,12,22,46,4,42,20,16,12,52,18,20,6,18,
27
+ 28,58,4,60,30,6,16,12,10,66,16,22,12,70,6,72,36,
28
+ 20,18,30,12,78,4,54]
29
+
30
+ @seq.to_enum.with_index(1).each do |c,n|
31
+ it "returns #{c} for #{n}" do
32
+ n.carmichael.should == c
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,20 @@
1
+ describe Integer, "#centered_pentagonal?" do
2
+ # A005891
3
+ @seq = [1,6,16,31,51,76,106,141,181,226,276,331,391,456,
4
+ 526,601,681,766,856,951,1051,1156,1266,1381,1501,
5
+ 1626,1756,1891,2031,2176,2326,2481,2641,2806,2976,
6
+ 3151,3331,3516,3706,3901,4101,4306,4516,4731,4951,
7
+ 5176,5406]
8
+
9
+ @seq.each do |n|
10
+ it "returns true for centered pentagonal #{n}" do
11
+ n.should be_centered_pentagonal
12
+ end
13
+ end
14
+
15
+ @seq.to_seq.invert.sample(100).each do |n|
16
+ it "returns false for non-centered-pentagonal #{n}" do
17
+ n.should_not be_centered_pentagonal
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ describe Integer, "#cullen?" do
2
+ # A002064
3
+ @seq = [1,3,9,25,65,161,385,897,2049,4609,10241,22529,
4
+ 49153,106497,229377,491521,1048577,2228225,
5
+ 4718593,9961473,20971521,44040193,92274689,
6
+ 192937985,402653185,838860801,1744830465,
7
+ 3623878657,7516192769]
8
+
9
+ @seq.sample(10).each do |n|
10
+ it "returns true for Cullen number #{n}" do
11
+ n.should be_cullen
12
+ end
13
+ end
14
+
15
+ @seq.to_seq.invert.sample(10).each do |n|
16
+ it "returns false for non-Cullen number #{n}" do
17
+ n.should_not be_cullen
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ describe Integer, "#cyclic?" do
2
+ # A004042
3
+ @seq = [0,142857,5882352941176470,526315789473684210,
4
+ 4347826086956521739130,
5
+ 3448275862068965517241379310,
6
+ 2127659574468085106382978723404255319148936170]
7
+
8
+ @seq.each do |n|
9
+ it "returns true for cyclic number #{n}" do
10
+ n.should be_cyclic
11
+ end
12
+ end
13
+
14
+ @seq.to_seq.invert.sample(100).each do |n|
15
+ it "returns false for non-cyclic number #{n}" do
16
+ n.should_not be_cyclic
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,40 @@
1
+ describe Integer, "#delannoy" do
2
+ # A008288 / http://mathworld.wolfram.com/DelannoyNumber.html
3
+ @seq = [
4
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
5
+ [1, 3, 5, 7, 9, 11, 13, 15, 17],
6
+ [1, 5, 13, 25, 41, 61, 85, 113, 145],
7
+ [1, 7, 25, 63, 129, 231, 377, 575, 833],
8
+ [1, 9, 41, 129, 321, 681, 1289, 2241, 3649],
9
+ [1, 11, 61, 231, 681, 1683, 3653, 7183, 13073],
10
+ ]
11
+
12
+ @seq.each_with_index do |row, a|
13
+ row.each_with_index do |d, b|
14
+ it "returns #{d} for Delannoy(#{a}, #{b})" do
15
+ a.delannoy(b).should == d
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ describe Integer, "#delannoy?" do
22
+ # A008288
23
+ @seq = [1,1,1,1,3,1,1,5,5,1,1,7,13,7,1,1,9,25,25,9,1,1,
24
+ 11,41,63,41,11,1,1,13,61,129,129,61,13,1,1,15,85,
25
+ 231,321,231,85,15,1,1,17,113,377,681,681,377,113,
26
+ 17,1,1,19,145,575,1289,1683,1289,575,145,19,1,1,
27
+ 21,181,833,2241,3653,3653].uniq
28
+
29
+ @seq.each do |n|
30
+ it "returns true for Delannoy number #{n}" do
31
+ n.should be_delannoy
32
+ end
33
+ end
34
+
35
+ [2, 10, 50, 26, 80].each do |n|
36
+ it "returns false for non-Delannoy number #{n}" do
37
+ n.should_not be_delannoy
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,28 @@
1
+ # A002477
2
+ DEMLO = [1,121,12321,1234321,123454321,12345654321,
3
+ 1234567654321,123456787654321,12345678987654321,
4
+ 1234567900987654321,123456790120987654321,
5
+ 12345679012320987654321,
6
+ 1234567901234320987654321]
7
+
8
+ describe Integer, "#demlo" do
9
+ DEMLO.to_enum.with_index(1).each do |demlo, n|
10
+ it "returns #{demlo} for #{n}" do
11
+ n.demlo.should == demlo
12
+ end
13
+ end
14
+ end
15
+
16
+ describe Integer, "#demlo?" do
17
+ DEMLO.each do |n|
18
+ it "returns true for Demlo number #{n}" do
19
+ n.should be_demlo
20
+ end
21
+ end
22
+
23
+ DEMLO.to_seq.invert.sample(500).each do |n|
24
+ it "returns false for non-Demlo number #{n}" do
25
+ n.should_not be_demlo
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ describe Integer, "#full_reptend_prime?" do
2
+ # A001913
3
+ @seq = [7,17,19,23,29,47,59,61,97,109,113,131,149,167,
4
+ 179,181,193,223,229,233,257,263,269,313,337,367,
5
+ 379,383,389,419,433,461,487,491,499,503,509,541,
6
+ 571,577,593,619,647,659,701,709,727,743,811,821,
7
+ 823,857,863,887,937,941]
8
+
9
+ @seq.each do |n|
10
+ it "returns true for full-reptend prime #{n}" do
11
+ n.should be_full_reptend_prime
12
+ end
13
+ end
14
+
15
+ @seq.to_seq.invert.sample(100).each do |n|
16
+ it "returns false for non-full-reptend-prime #{n}" do
17
+ n.should_not be_full_reptend_prime
18
+ end
19
+ end
20
+ end
@@ -18,4 +18,10 @@ describe Float, "#integer?" do
18
18
  n.should_not be_integer
19
19
  end
20
20
  end
21
+
22
+ it "ignores digits past the tenth" do
23
+ 3.00000000001.should be_integer
24
+ 123.0000000000032.should be_integer
25
+ 123.00000000032.should_not be_integer
26
+ end
21
27
  end
@@ -0,0 +1,14 @@
1
+ describe Integer, "#isqrt" do
2
+ # A000196
3
+ @seq = [0,1,1,1,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,
4
+ 4,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,
5
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,
6
+ 8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
7
+ 9,10,10]
8
+
9
+ @seq.each_with_index do |isqrt, n|
10
+ it "returns #{isqrt} for #{n}" do
11
+ n.isqrt.should == isqrt
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,67 @@
1
+ describe Integer, "#modulo_order" do
2
+ @seq = {
3
+ # A002326
4
+ 2 => [1,2,4,3,6,10,12,4,8,18,6,11,20,18,28,5,10,12,36,
5
+ 12,20,14,12,23,21,8,52,20,18,58,60,6,12,66,22,35,
6
+ 9,20,30,39,54,82,8,28,11,12,10,36,48,30,100,51,12,
7
+ 106,36,36,28,44,12,24,110,20,100,7,14,130,18,36,
8
+ 68,138,46,60,28],
9
+ # A050975
10
+ 3 => [1,2,4,6,2,4,5,3,6,4,16,18,4,5,11,20,3,6,28,30,8,
11
+ 16,12,18,18,4,8,42,10,11,23,42,20,6,52,20,6,28,29,
12
+ 10,30,16,12,22,16,12,35,12,18,18,30,78,4,8,41,16,
13
+ 42,10,88,6,22,23,36,48,42,20,100,34,6,52,53,27,20,
14
+ 12],
15
+ # A050976
16
+ 4 => [1,2,3,3,5,6,2,4,9,3,11,10,9,14,5,5,6,18,6,10,7,6,
17
+ 23,21,4,26,10,9,29,30,3,6,33,11,35,9,10,15,39,27,
18
+ 41,4,14,11,6,5,18,24,15,50,51,6,53,18,18,14,22,6,
19
+ 12,55,10,50,7,7,65,9,18,34,69,23,30,14,21,74,15,
20
+ 12,10,26],
21
+ # A050977
22
+ 5 => [1,2,1,2,6,2,6,5,2,4,6,4,16,6,9,6,5,22,2,4,18,6,
23
+ 14,3,8,10,16,6,36,9,4,20,6,42,5,22,46,4,42,16,4,
24
+ 52,18,6,18,14,29,30,3,6,16,10,22,16,22,5,6,72,36,
25
+ 9,30,4,39,54,20,82,6,42,14,10,44,12,22,6,46,8,96,
26
+ 42,30,25,16],
27
+ # A050978
28
+ 6 => [1,2,10,12,16,9,11,5,14,6,2,4,40,3,23,14,26,10,58,
29
+ 60,12,33,35,36,10,78,82,16,88,12,9,12,10,102,106,
30
+ 108,112,11,16,110,25,126,130,18,136,23,60,14,37,
31
+ 150,6,156,22,27,83,156,43,10,178,60,4,80,19,96,14,
32
+ 198,14],
33
+ # A050979
34
+ 7 => [1,1,2,4,1,2,3,4,10,2,12,4,2,16,3,3,4,10,22,2,4,
35
+ 12,9,7,4,15,4,10,16,6,9,3,12,4,40,6,10,12,22,23,2,
36
+ 4,16,12,26,9,20,3,7,29,4,60,15,8,12,10,66,16,22,
37
+ 70,6,24,9,4,6,12,78,4,27,40,41,16,6,7,10,88,12,22,
38
+ 15,23,12],
39
+ # A050980
40
+ 8 => [2,4,1,2,10,4,4,8,6,2,11,20,6,28,5,10,4,12,4,20,
41
+ 14,4,23,7,8,52,20,6,58,20,2,4,22,22,35,3,20,10,13,
42
+ 18,82,8,28,11,4,10,12,16,10,100,17,4,106,12,12,28,
43
+ 44,4,8,110,20,100,7,14,130,6,12,68,46,46,20,28,14,
44
+ 148,5],
45
+ # A050981
46
+ 9 => [1,1,2,3,1,2,5,3,3,2,8,9,2,5,11,10,3,3,14,15,4,8,
47
+ 6,9,9,2,4,21,5,11,23,21,10,3,26,10,3,14,29,5,15,8,
48
+ 6,11,8,6,35,6,9,9,15,39,2,4,41,8,21,5,44,3,11,23,
49
+ 18,24,21,10,50,17,3,26,53,27,10,6,56,22,14,29,24,
50
+ 5,5,15],
51
+ # A002329
52
+ 10 =>[1,6,1,2,6,16,18,6,22,3,28,15,2,3,6,5,21,46,42,16,
53
+ 13,18,58,60,6,33,22,35,8,6,13,9,41,28,44,6,15,96,
54
+ 2,4,34,53,108,3,112,6,48,22,5,42,21,130],
55
+ }
56
+
57
+ @seq.each do |base, values|
58
+ 1.upto(100) do |n|
59
+ mo = base.modulo_order(n)
60
+ value = mo.zero? ? 0 : values.shift
61
+ it "returns #{value} for the multiplicative order of base #{base} (mod #{n})" do
62
+ mo.should == value
63
+ end
64
+ break if values.empty?
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,74 @@
1
+ describe Integer, "#primitive_root?" do
2
+ # A033948
3
+ @seq = [1,2,3,4,5,6,7,9,10,11,13,14,17,18,19,22,23,25,26,
4
+ 27,29,31,34,37,38,41,43,46,47,49,50,53,54,58,59,61,62,
5
+ 67,71,73,74,79,81,82,83,86,89,94,97,98,101,103,106,107,
6
+ 109,113,118,121,122,125,127,131,134,137,139]
7
+
8
+ @seq.sample(10).each do |n|
9
+ it "returns true for #{n} which has a primitive root" do
10
+ n.should be_primitive_root
11
+ end
12
+ end
13
+
14
+ @seq.to_seq.invert.sample(10).each do |n|
15
+ it "returns false for #{n} which doesn't have a primitive root" do
16
+ n.should_not be_primitive_root
17
+ end
18
+ end
19
+ end
20
+
21
+ describe Integer, "#primitive_root? (with argument)" do
22
+ # A046145
23
+ @seq = [0,0,1,2,3,2,5,3,0,2,3,2,0,2,3,0,0,3,5,2,0,0,7,5,
24
+ 0,2,7,2,0,2,0,3,0,0,3,0,0,2,3,0,0,6,0,3,0,0,5,5,0,
25
+ 3,3,0,0,2,5,0,0,0,3,2,0,2,3,0,0,0,0,2,0,0,0,7,0,5,
26
+ 5,0,0,0,0,3,0,2,7,2,0,0,3,0,0,3,0,0,0,0,5,0,0,5,3,
27
+ 0,0]
28
+
29
+ @seq.each_with_index.to_a.sample(5).each do |root,n|
30
+ next if root.zero?
31
+ (1...root).each do |non_root|
32
+ it "returns false for #{n} when given a root of #{non_root}" do
33
+ n.should_not be_primitive_root(non_root)
34
+ end
35
+ end
36
+
37
+ it "returns true for #{n} when given a root of #{root}" do
38
+ n.should be_primitive_root(root)
39
+ end
40
+ end
41
+
42
+ # A001122
43
+ [3,5,11,13,19,29,37,53,59,61,67,83,101,107,131,
44
+ 139,149,163,173,179,181,197,211,227,269,293,317,
45
+ 347,349,373,379,389,419,421,443,461,467,491,509,
46
+ 523,541,547,557,563,587,613,619,653,659,661,677,
47
+ 701,709,757,773,787,797].sample(5).each do |n|
48
+
49
+ it "returns true for #{n} when given a root of 2" do
50
+ n.should be_primitive_root(2)
51
+ end
52
+ end
53
+
54
+ [71,239,241,359,431,499,599,601,919,997,1051,1181,
55
+ 1249,1439,1609,1753,2039,2089,2111,2179,2251,2281,
56
+ 2341,2591,2593,2671,2711,2879,3119,3121,3169,3181,
57
+ 3457,3511,3541,3719,3739,3769,4271,4513,4799,4801,
58
+ 4943,5197].first(10).sample(5).each do |n|
59
+ (1...7).to_a.sample(1).each do |root|
60
+
61
+ it "returns false for #{n} when given a root of #{root}" do
62
+ n.should_not be_primitive_root(root)
63
+ end
64
+ end
65
+
66
+ it "returns true for #{n} when given a root of 7" do
67
+ n.should be_primitive_root(7)
68
+ end
69
+ end
70
+
71
+ it "returns true when asked whether 0 is a primitive root of unity" do
72
+ 1.should be_primitive_root(0)
73
+ end
74
+ end
@@ -0,0 +1,34 @@
1
+ describe Integer, "#primitive_roots" do
2
+ # A046144
3
+ @seq = [1,1,1,1,2,1,2,0,2,2,4,0,4,2,0,0,8,2,6,0,0,4,10,0,
4
+ 8,4,6,0,12,0,8,0,0,8,0,0,12,6,0,0,16,0,12,0,0,10,
5
+ 22,0,12,8,0,0,24,6,0,0,0,12,28,0,16,8,0,0,0,0,20,
6
+ 0,0,0,24,0,24,12,0,0,0,0,24,0,18,16,40,0,0,12,0,0,
7
+ 40,0,0]
8
+
9
+ @seq.to_enum.with_index(1).each do |count,n|
10
+ pr = n.primitive_roots
11
+ it "returns #{count} primitive roots for #{n}" do
12
+ pr.size.should == count
13
+ pr.uniq.size.should == pr.size
14
+ end
15
+
16
+ pr.sample(2).each do |root|
17
+ it "returns actual primitive roots, e.g. #{root} for #{n}" do
18
+ n.primitive_root?(root)
19
+ end
20
+ end
21
+ end
22
+
23
+ # A046146
24
+ @seq = [0,0,1,2,3,3,5,5,0,5,7,8,0,11,5,0,0,14,11,15,0,0,
25
+ 19,21,0,23,19,23,0,27,0,24,0,0,31,0,0,35,33,0,0,
26
+ 35,0,34,0,0,43,45,0,47,47,0,0,51,47,0,0,0,55,56,0,
27
+ 59,55,0,0,0,0,63,0,0,0,69,0,68,69,0,0,0,0,77,0,77,
28
+ 75,80,0,0].each_with_index.to_a.sample(15).each do |largest, n|
29
+ next if largest.zero?
30
+ it "returns #{largest} as the largest primitive root of #{n}" do
31
+ n.primitive_roots.max.should == largest
32
+ end
33
+ end
34
+ end
@@ -23,3 +23,19 @@ describe Integer, "#repunit?" do
23
23
  end
24
24
  end
25
25
  end
26
+
27
+ describe Integer, "#repunit" do
28
+ # A002275
29
+ @seq = [0,1,11,111,1111,11111,111111,1111111,11111111,
30
+ 111111111,1111111111,11111111111,111111111111,
31
+ 1111111111111,11111111111111,111111111111111,
32
+ 1111111111111111,11111111111111111,
33
+ 111111111111111111,1111111111111111111,
34
+ 11111111111111111111]
35
+
36
+ @seq.each_with_index do |repunit, n|
37
+ it "returns #{repunit} for #{n}" do
38
+ n.repunit.should == repunit
39
+ end
40
+ end
41
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: numb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.114.0
4
+ version: 0.125.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Run Paint Run Run
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-14 00:00:00 +00:00
12
+ date: 2010-03-15 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -68,6 +68,7 @@ files:
68
68
  - lib/numb/centered_cube.rb
69
69
  - lib/numb/centered_hexagonal.rb
70
70
  - lib/numb/centered_n_gonal.rb
71
+ - lib/numb/centered_pentagonal.rb
71
72
  - lib/numb/centered_triangular.rb
72
73
  - lib/numb/composite.rb
73
74
  - lib/numb/congruum.rb
@@ -76,9 +77,13 @@ files:
76
77
  - lib/numb/core.rb
77
78
  - lib/numb/cototient.rb
78
79
  - lib/numb/cube.rb
80
+ - lib/numb/cullen.rb
81
+ - lib/numb/cyclic.rb
79
82
  - lib/numb/d.rb
80
83
  - lib/numb/decagonal.rb
81
84
  - lib/numb/deficient.rb
85
+ - lib/numb/delannoy.rb
86
+ - lib/numb/demlo.rb
82
87
  - lib/numb/dihedral_prime.rb
83
88
  - lib/numb/dodecagonal.rb
84
89
  - lib/numb/doubly_even.rb
@@ -96,6 +101,7 @@ files:
96
101
  - lib/numb/fibonacci.rb
97
102
  - lib/numb/friendly.rb
98
103
  - lib/numb/frugal.rb
104
+ - lib/numb/full_reptend_prime.rb
99
105
  - lib/numb/giuga.rb
100
106
  - lib/numb/goldbach.rb
101
107
  - lib/numb/hamming.rb
@@ -127,6 +133,7 @@ files:
127
133
  - lib/numb/minimal.rb
128
134
  - lib/numb/mms_pair.rb
129
135
  - lib/numb/mobius.rb
136
+ - lib/numb/modulo_order.rb
130
137
  - lib/numb/myriagonal.rb
131
138
  - lib/numb/n_gonal.rb
132
139
  - lib/numb/narcissistic.rb
@@ -155,6 +162,8 @@ files:
155
162
  - lib/numb/prime_count.rb
156
163
  - lib/numb/prime_signature.rb
157
164
  - lib/numb/primitive_pseudoperfect.rb
165
+ - lib/numb/primitive_root.rb
166
+ - lib/numb/primitive_roots.rb
158
167
  - lib/numb/primorial.rb
159
168
  - lib/numb/pronic.rb
160
169
  - lib/numb/properties.rb
@@ -237,15 +246,20 @@ files:
237
246
  - spec/numb/centered_cube_spec.rb
238
247
  - spec/numb/centered_hexagonal_spec.rb
239
248
  - spec/numb/centered_n_gonal_spec.rb
249
+ - spec/numb/centered_pentagonal_spec.rb
240
250
  - spec/numb/centered_triangular_spec.rb
241
251
  - spec/numb/composite_spec.rb
242
252
  - spec/numb/congruum_spec.rb
243
253
  - spec/numb/coprime_spec.rb
244
254
  - spec/numb/core_spec.rb
245
255
  - spec/numb/cube_spec.rb
256
+ - spec/numb/cullen_spec.rb
257
+ - spec/numb/cyclic_spec.rb
246
258
  - spec/numb/d_spec.rb
247
259
  - spec/numb/decagonal_spec.rb
248
260
  - spec/numb/deficient_spec.rb
261
+ - spec/numb/delannoy_spec.rb
262
+ - spec/numb/demlo_spec.rb
249
263
  - spec/numb/digital_sum_spec.rb
250
264
  - spec/numb/dihedral_prime_spec.rb
251
265
  - spec/numb/divides_spec.rb
@@ -265,6 +279,7 @@ files:
265
279
  - spec/numb/fibonacci_spec.rb
266
280
  - spec/numb/friendly_spec.rb
267
281
  - spec/numb/frugal_spec.rb
282
+ - spec/numb/full_reptend_prime_spec.rb
268
283
  - spec/numb/giuga_spec.rb
269
284
  - spec/numb/goldbach_spec.rb
270
285
  - spec/numb/hamming_spec.rb
@@ -280,6 +295,7 @@ files:
280
295
  - spec/numb/idoneal_spec.rb
281
296
  - spec/numb/integer_p_spec.rb
282
297
  - spec/numb/interprime_spec.rb
298
+ - spec/numb/isqrt_spec.rb
283
299
  - spec/numb/jacobsthal_lucas_spec.rb
284
300
  - spec/numb/k_perfect_spec.rb
285
301
  - spec/numb/kaprekar_spec.rb
@@ -295,6 +311,7 @@ files:
295
311
  - spec/numb/mersenne_prime_spec.rb
296
312
  - spec/numb/minimal_spec.rb
297
313
  - spec/numb/mobius_spec.rb
314
+ - spec/numb/modulo_order_spec.rb
298
315
  - spec/numb/myriagonal_spec.rb
299
316
  - spec/numb/narcissistic_spec.rb
300
317
  - spec/numb/nivenmorphic_spec.rb
@@ -323,6 +340,8 @@ files:
323
340
  - spec/numb/prime_count_spec.rb
324
341
  - spec/numb/prime_signature_spec.rb
325
342
  - spec/numb/primitive_pseudoperfect_spec.rb
343
+ - spec/numb/primitive_root_spec.rb
344
+ - spec/numb/primitive_roots_spec.rb
326
345
  - spec/numb/primorial_spec.rb
327
346
  - spec/numb/pronic_spec.rb
328
347
  - spec/numb/proth_spec.rb
@@ -416,10 +435,12 @@ test_files:
416
435
  - spec/numb/primitive_pseudoperfect_spec.rb
417
436
  - spec/numb/polydivisible_spec.rb
418
437
  - spec/numb/strictly_non_palindromic_spec.rb
438
+ - spec/numb/cyclic_spec.rb
419
439
  - spec/numb/iban_spec.rb
420
440
  - spec/numb/equidigital_spec.rb
421
441
  - spec/numb/primorial_spec.rb
422
442
  - spec/numb/superabundant_spec.rb
443
+ - spec/numb/modulo_order_spec.rb
423
444
  - spec/numb/sociable_spec.rb
424
445
  - spec/numb/unitary_perfect_spec.rb
425
446
  - spec/numb/nivenmorphic_spec.rb
@@ -447,6 +468,7 @@ test_files:
447
468
  - spec/numb/polite_spec.rb
448
469
  - spec/numb/unitary_amicable_spec.rb
449
470
  - spec/numb/squared_triangular_spec.rb
471
+ - spec/numb/cullen_spec.rb
450
472
  - spec/numb/zerofree_spec.rb
451
473
  - spec/numb/eban_spec.rb
452
474
  - spec/numb/automorphic_spec.rb
@@ -456,6 +478,7 @@ test_files:
456
478
  - spec/numb/hyperperfect_spec.rb
457
479
  - spec/numb/uban_spec.rb
458
480
  - spec/numb/zeisel_spec.rb
481
+ - spec/numb/primitive_roots_spec.rb
459
482
  - spec/numb/smooth_spec.rb
460
483
  - spec/numb/d_spec.rb
461
484
  - spec/numb/heptagonal_spec.rb
@@ -482,6 +505,7 @@ test_files:
482
505
  - spec/numb/unusual_spec.rb
483
506
  - spec/numb/octagonal_spec.rb
484
507
  - spec/numb/unitary_sociable_spec.rb
508
+ - spec/numb/full_reptend_prime_spec.rb
485
509
  - spec/numb/vampire_spec.rb
486
510
  - spec/numb/dodecagonal_spec.rb
487
511
  - spec/numb/dihedral_prime_spec.rb
@@ -512,6 +536,7 @@ test_files:
512
536
  - spec/numb/euclid_spec.rb
513
537
  - spec/numb/semiprime_spec.rb
514
538
  - spec/numb/deficient_spec.rb
539
+ - spec/numb/centered_pentagonal_spec.rb
515
540
  - spec/numb/almost_perfect_spec.rb
516
541
  - spec/numb/amicable_spec.rb
517
542
  - spec/numb/amenable_spec.rb
@@ -525,6 +550,7 @@ test_files:
525
550
  - spec/numb/semi_perfect_spec.rb
526
551
  - spec/numb/pentagonal_spec.rb
527
552
  - spec/numb/blum_spec.rb
553
+ - spec/numb/demlo_spec.rb
528
554
  - spec/numb/smarandache_wellin_spec.rb
529
555
  - spec/numb/maris_mcgwire_sosa_pair_spec.rb
530
556
  - spec/numb/core_spec.rb
@@ -535,9 +561,11 @@ test_files:
535
561
  - spec/numb/harshad_spec.rb
536
562
  - spec/numb/cube_spec.rb
537
563
  - spec/numb/ore_spec.rb
564
+ - spec/numb/delannoy_spec.rb
538
565
  - spec/numb/carol_spec.rb
539
566
  - spec/numb/powerful_spec.rb
540
567
  - spec/numb/prime_count_spec.rb
568
+ - spec/numb/primitive_root_spec.rb
541
569
  - spec/numb/weird_spec.rb
542
570
  - spec/numb/interprime_spec.rb
543
571
  - spec/numb/number_of_distinct_prime_factors_spec.rb
@@ -557,6 +585,7 @@ test_files:
557
585
  - spec/numb/decagonal_spec.rb
558
586
  - spec/numb/apocalyptic_spec.rb
559
587
  - spec/numb/kaprekar_spec.rb
588
+ - spec/numb/isqrt_spec.rb
560
589
  - spec/numb/hilbert_spec.rb
561
590
  - "spec/numb/st\xC3\xB8rmer_spec.rb"
562
591
  - spec/numb/keith_spec.rb