numb 0.152.0 → 0.170.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. data/VERSION +1 -1
  2. data/lib/numb/bell.rb +9 -12
  3. data/lib/numb/bernoulli.rb +7 -8
  4. data/lib/numb/catalan.rb +1 -5
  5. data/lib/numb/divisors/abundant.rb +58 -0
  6. data/lib/numb/divisors/aliquot.rb +31 -0
  7. data/lib/numb/divisors/amicable.rb +38 -0
  8. data/lib/numb/divisors/perfect.rb +73 -0
  9. data/lib/numb/divisors.rb +389 -0
  10. data/lib/numb/entringer.rb +2 -0
  11. data/lib/numb/figurate.rb +138 -0
  12. data/lib/numb/in_sequence.rb +11 -0
  13. data/lib/numb/jacobsthal_lucas.rb +5 -6
  14. data/lib/numb/knuth.rb +1 -4
  15. data/lib/numb/lucas.rb +5 -5
  16. data/lib/numb/lucas2.rb +11 -0
  17. data/lib/numb/lychrel.rb +0 -4
  18. data/lib/numb/palindrome.rb +8 -0
  19. data/lib/numb/pell_lucas.rb +9 -0
  20. data/lib/numb/primes.rb +164 -0
  21. data/lib/numb/pronic.rb +1 -0
  22. data/lib/numb/q.rb +13 -0
  23. data/lib/numb/schr/303/266der.rb +20 -0
  24. data/lib/numb/segmented.rb +29 -0
  25. data/lib/numb/stirling.rb +9 -0
  26. data/lib/numb/stirling2.rb +9 -0
  27. data/lib/numb/strictly_non_palindromic.rb +1 -5
  28. data/lib/numb/super_catalan.rb +17 -0
  29. data/lib/numb/super_d.rb +6 -0
  30. data/lib/numb/takeuchi.rb +18 -0
  31. data/lib/numb/unhappy.rb +2 -0
  32. data/lib/numb.rb +1 -53
  33. data/spec/numb/first_with_n_divisors_spec.rb +15 -0
  34. data/spec/numb/highly_composite_spec.rb +1 -1
  35. data/spec/numb/jacobsthal_lucas_spec.rb +19 -11
  36. data/spec/numb/lucas2_spec.rb +30 -0
  37. data/spec/numb/lucas_spec.rb +17 -9
  38. data/spec/numb/minimal_spec.rb +1 -1
  39. data/spec/numb/near_square_spec.rb +54 -0
  40. data/spec/numb/octahedral_spec.rb +29 -0
  41. data/spec/numb/palindrome_spec.rb +43 -0
  42. data/spec/numb/pell_lucas_spec.rb +28 -0
  43. data/spec/numb/pentatope_spec.rb +15 -0
  44. data/spec/numb/primitive_abundant_spec.rb +21 -0
  45. data/spec/numb/pyramidal_spec.rb +42 -0
  46. data/spec/numb/q_spec.rb +31 -0
  47. data/spec/numb/schr/303/266der_spec.rb +28 -0
  48. data/spec/numb/segmented_spec.rb +29 -0
  49. data/spec/numb/square_part_spec.rb +15 -0
  50. data/spec/numb/star_spec.rb +29 -0
  51. data/spec/numb/stella_octangula_spec.rb +29 -0
  52. data/spec/numb/stirling2_spec.rb +23 -0
  53. data/spec/numb/stirling_spec.rb +23 -0
  54. data/spec/numb/super_catalan_spec.rb +29 -0
  55. data/spec/numb/super_d_spec.rb +68 -0
  56. data/spec/numb/takeuchi_spec.rb +28 -0
  57. data/spec/numb/tetrahedral_spec.rb +15 -0
  58. metadata +63 -100
  59. data/lib/numb/abundancy.rb +0 -8
  60. data/lib/numb/abundant.rb +0 -20
  61. data/lib/numb/achilles.rb +0 -15
  62. data/lib/numb/aliquot_sequence.rb +0 -13
  63. data/lib/numb/almost_perfect.rb +0 -8
  64. data/lib/numb/almost_prime.rb +0 -6
  65. data/lib/numb/amicable.rb +0 -6
  66. data/lib/numb/aspiring.rb +0 -8
  67. data/lib/numb/augmented_amicable.rb +0 -7
  68. data/lib/numb/balanced_prime.rb +0 -10
  69. data/lib/numb/betrothed.rb +0 -8
  70. data/lib/numb/breeder.rb +0 -9
  71. data/lib/numb/brilliant.rb +0 -7
  72. data/lib/numb/centered_cube.rb +0 -7
  73. data/lib/numb/centered_hexagonal.rb +0 -6
  74. data/lib/numb/centered_n_gonal.rb +0 -9
  75. data/lib/numb/centered_pentagonal.rb +0 -6
  76. data/lib/numb/centered_square.rb +0 -5
  77. data/lib/numb/centered_triangular.rb +0 -5
  78. data/lib/numb/composite.rb +0 -5
  79. data/lib/numb/coprime.rb +0 -9
  80. data/lib/numb/cube.rb +0 -5
  81. data/lib/numb/d.rb +0 -6
  82. data/lib/numb/decagonal.rb +0 -5
  83. data/lib/numb/deficient.rb +0 -19
  84. data/lib/numb/dihedral_prime.rb +0 -26
  85. data/lib/numb/dodecagonal.rb +0 -5
  86. data/lib/numb/e_divisors.rb +0 -10
  87. data/lib/numb/e_perfect.rb +0 -7
  88. data/lib/numb/economical.rb +0 -16
  89. data/lib/numb/emrip.rb +0 -15
  90. data/lib/numb/equidigital.rb +0 -18
  91. data/lib/numb/extravagant.rb +0 -18
  92. data/lib/numb/fermat_pseudoprime.rb +0 -9
  93. data/lib/numb/friendly.rb +0 -9
  94. data/lib/numb/full_reptend_prime.rb +0 -5
  95. data/lib/numb/giuga.rb +0 -7
  96. data/lib/numb/harshad.rb +0 -9
  97. data/lib/numb/heptagonal.rb +0 -5
  98. data/lib/numb/hexagonal.rb +0 -6
  99. data/lib/numb/highly_abundant.rb +0 -7
  100. data/lib/numb/highly_composite.rb +0 -12
  101. data/lib/numb/hoax.rb +0 -7
  102. data/lib/numb/hyperperfect.rb +0 -7
  103. data/lib/numb/impolite.rb +0 -6
  104. data/lib/numb/infinitary_divisors.rb +0 -15
  105. data/lib/numb/infinitary_perfect.rb +0 -6
  106. data/lib/numb/interprime.rb +0 -6
  107. data/lib/numb/k_perfect.rb +0 -8
  108. data/lib/numb/mersenne_prime.rb +0 -5
  109. data/lib/numb/minimal.rb +0 -8
  110. data/lib/numb/multiamicable.rb +0 -7
  111. data/lib/numb/myriagonal.rb +0 -5
  112. data/lib/numb/n_gonal.rb +0 -7
  113. data/lib/numb/next_prev_prime.rb +0 -13
  114. data/lib/numb/nth_prime.rb +0 -17
  115. data/lib/numb/number_of_divisors.rb +0 -22
  116. data/lib/numb/octagonal.rb +0 -5
  117. data/lib/numb/ore.rb +0 -8
  118. data/lib/numb/pentagonal.rb +0 -5
  119. data/lib/numb/perfect.rb +0 -8
  120. data/lib/numb/perfect_power.rb +0 -9
  121. data/lib/numb/polite.rb +0 -7
  122. data/lib/numb/powerful.rb +0 -10
  123. data/lib/numb/practical.rb +0 -26
  124. data/lib/numb/prime_count.rb +0 -16
  125. data/lib/numb/prime_signature.rb +0 -5
  126. data/lib/numb/primitive_pseudoperfect.rb +0 -5
  127. data/lib/numb/rhonda.rb +0 -6
  128. data/lib/numb/rough.rb +0 -5
  129. data/lib/numb/safe_prime.rb +0 -5
  130. data/lib/numb/semiperfect.rb +0 -20
  131. data/lib/numb/semiprime.rb +0 -6
  132. data/lib/numb/smith.rb +0 -7
  133. data/lib/numb/smooth.rb +0 -5
  134. data/lib/numb/sociable.rb +0 -6
  135. data/lib/numb/sophie_germain_prime.rb +0 -5
  136. data/lib/numb/square.rb +0 -7
  137. data/lib/numb/square_free.rb +0 -6
  138. data/lib/numb/square_triangular.rb +0 -5
  139. data/lib/numb/squared_triangular.rb +0 -5
  140. data/lib/numb/sublime.rb +0 -6
  141. data/lib/numb/sum_of_e_divisors.rb +0 -10
  142. data/lib/numb/sum_of_infinitary_divisors.rb +0 -9
  143. data/lib/numb/sum_of_unitary_divisors.rb +0 -5
  144. data/lib/numb/super_poulet.rb +0 -5
  145. data/lib/numb/superabundant.rb +0 -18
  146. data/lib/numb/superperfect.rb +0 -6
  147. data/lib/numb/triangular.rb +0 -6
  148. data/lib/numb/twin_prime.rb +0 -5
  149. data/lib/numb/unitary_amicable.rb +0 -7
  150. data/lib/numb/unitary_divisor.rb +0 -5
  151. data/lib/numb/unitary_perfect.rb +0 -7
  152. data/lib/numb/unitary_sociable.rb +0 -7
  153. data/lib/numb/untouchable.rb +0 -14
  154. data/lib/numb/unusual.rb +0 -5
  155. data/lib/numb/weird.rb +0 -8
  156. data/lib/numb/wieferich.rb +0 -6
@@ -1,5 +0,0 @@
1
- class Integer
2
- def centered_square?
3
- centered_n_gonal? 4
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- class Integer
2
- def centered_triangular?
3
- centered_n_gonal?(3)
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- class Integer
2
- def composite?
3
- self > 1 and not prime?
4
- end
5
- end
data/lib/numb/coprime.rb DELETED
@@ -1,9 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- def coprime?(x)
4
- gcd(x) == 1
5
- end
6
- alias :⊥ :coprime?
7
- alias :stranger? :coprime?
8
- end
9
-
data/lib/numb/cube.rb DELETED
@@ -1,5 +0,0 @@
1
- class Integer
2
- def cube?
3
- Math.cbrt(self).integer?
4
- end
5
- end
data/lib/numb/d.rb DELETED
@@ -1,6 +0,0 @@
1
- # coding:utf-8
2
- class Integer
3
- def d?
4
- knödel?(3)
5
- end
6
- end
@@ -1,5 +0,0 @@
1
- class Integer
2
- def decagonal?
3
- n_gonal?(10)
4
- end
5
- end
@@ -1,19 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- # A deficient number is a number n for which σ(n) < 2n. That is, the sum of
4
- # its divisors are less than the number. (To calculate the sum of divisors
5
- # for an arbitrary integer see Integer#σ).
6
- #
7
- # Returns true if the number is deficient; false otherwise.
8
- #
9
- # 8.deficient? #=> true
10
- # 27.deficient? #=> true
11
- # 6.deficient? #=> false
12
- #
13
- def deficient?
14
- return false unless positive?
15
- σ < (2 * self)
16
- end
17
-
18
- alias :defective? :deficient?
19
- end
@@ -1,26 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
-
4
- # A dihedral prime is a prime number that appears as itself or another prime
5
- # when rendered on a seven-segment display of a calculator and...
6
- #
7
- # * Rotated 180°.
8
- # * Mirrored.
9
- # * Rotated 180° and mirrored.
10
- #
11
- # For example, 120121 is a dihedral prime. It is 121021 when rotated,
12
- # 151051 (another prime) when mirrored, and 150151 when rotated and
13
- # mirrored.
14
- #
15
- # Returns true if self is a dihedral prime; false otherwise.
16
- #
17
- # 101.dihedral_prime? #=> true
18
- # 181.dihedral_prime? #=> true
19
- # 7.dihedral_prime? #=> false
20
- #
21
- def dihedral_prime?
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
- [reverse, mirror[self], mirror[reverse]].all?(&:prime?)
25
- end
26
- end
@@ -1,5 +0,0 @@
1
- class Integer
2
- def dodecagonal?
3
- n_gonal?(12)
4
- end
5
- end
@@ -1,10 +0,0 @@
1
- class Integer
2
- def e_divisors
3
- return [1] if self == 1
4
- pfacts = primaries
5
- comb = pfacts.map{|p,a| (1..a).select{|b| a.divides?(b)}.map{|b| p**b}}
6
- comb.flatten.permutation(pfacts.size).select do |perm|
7
- perm.each_with_index.all?{|x,i| comb[i].include? x}
8
- end.map{|perm| perm.reduce(:*)}
9
- end
10
- end
@@ -1,7 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- def e_perfect?
4
- return false if odd?
5
- σe == 2 * self
6
- end
7
- end
@@ -1,16 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- # A number which is either frugal or equidigital.
4
- #
5
- # Returns true if self is economical; false otherwise.
6
- #
7
- # See also Integer#equidigital? and Integer#frugal?.
8
- #
9
- # 243.economical? #=> true
10
- # 7.economical? #=> true
11
- # 989.economical? #=> false
12
- #
13
- def economical?
14
- equidigital? or frugal?
15
- end
16
- end
data/lib/numb/emrip.rb DELETED
@@ -1,15 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- # An emrip is a prime whose reversed digits give a different prime. For
4
- # example, 17 is an emrip because 71 is also prime.
5
- #
6
- # Returns true if self is an emrip; false otherwise.
7
- #
8
- # 1009.emrip? #=> true
9
- # 1193.emrip? #=> true
10
- # 7.emrip? #=> false
11
- #
12
- def emrip?
13
- prime? and reverse != self and reverse.prime?
14
- end
15
- end
@@ -1,18 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- # An equidigital number has the same number of digits as
4
- # the number of digits in its prime factorization (including exponents).
5
- #
6
- # For example, 35 is equidigital because it has two digits and two 1-digit
7
- # prime factors (5 and 7).
8
- #
9
- # Returns true if self is equidigital; false otherwise.
10
- #
11
- # 81.equidigital? #=> true
12
- # 49.equidigital? #=> true
13
- # 1287.equidigital? #=> false
14
- #
15
- def equidigital?
16
- digits.size == prime_division.flatten.reject{|d|d==1}.join.to_i.digits.size
17
- end
18
- end
@@ -1,18 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- # An extravagant number has fewer digits than the number of digits in its
4
- # prime factorization (including exponents).
5
- #
6
- # Returns true if self is extravagant; false otherwise. Aliased to
7
- # Integer#wasteful?.
8
- #
9
- # 234.extravagant? #=> true
10
- # 87.extravagant? #=> true
11
- # 81.extravagant? #=> false
12
- #
13
- def extravagant?
14
- digits.size < prime_division.flatten.reject{|d|d==1}.join.to_i.digits.size
15
- end
16
-
17
- alias :wasteful? :extravagant?
18
- end
@@ -1,9 +0,0 @@
1
- class Integer
2
- def fermat_pseudoprime?(a=10)
3
- return false unless composite?
4
- q = self
5
- raise ArgumentError unless a >= 2
6
- raise ArgumentError unless (q - 2) >= a
7
- (a**(q-1)).modulo(q) == 1
8
- end
9
- end
data/lib/numb/friendly.rb DELETED
@@ -1,9 +0,0 @@
1
- class Integer
2
- def friendly?(*others)
3
- raise ArgumentError unless others.size >= 1 && others.uniq.size == others.size
4
- abundancy = self.abundancy
5
- others.all? {|o| o.abundancy == abundancy}
6
- end
7
- end
8
-
9
-
@@ -1,5 +0,0 @@
1
- class Integer
2
- def full_reptend_prime?
3
- prime? and primitive_root?(10)
4
- end
5
- end
data/lib/numb/giuga.rb DELETED
@@ -1,7 +0,0 @@
1
- class Integer
2
- def giuga?
3
- composite? and prime_factors.uniq.all? do |p|
4
- ((self / p) - 1).divides?(p)
5
- end
6
- end
7
- end
data/lib/numb/harshad.rb DELETED
@@ -1,9 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- def harshad?
4
- self >= 1 and (self % digital_sum).zero?
5
- end
6
-
7
- alias :niven? :harshad?
8
- alias :multidigital? :harshad?
9
- end
@@ -1,5 +0,0 @@
1
- class Integer
2
- def heptagonal?
3
- n_gonal?(7)
4
- end
5
- end
@@ -1,6 +0,0 @@
1
- class Integer
2
- def hexagonal?
3
- return true if zero?
4
- ((Math.sqrt((8*self) + 1) + 1)/4).integer?
5
- end
6
- end
@@ -1,7 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- def highly_abundant?
4
- return true if self == 1
5
- (self - 1).downto(1).all?{|m| σ > m.σ }
6
- end
7
- end
@@ -1,12 +0,0 @@
1
- class Integer
2
- def highly_composite?
3
- return false if self > 6 and not (abundant? or primorial_product?)
4
- return true if [1,4,36].include?(self)
5
- n_divisors = number_of_divisors
6
- (self-1).downto(1).none? do |x|
7
- x.number_of_divisors >= n_divisors
8
- end
9
- end
10
-
11
- alias :julian? :highly_composite?
12
- end
data/lib/numb/hoax.rb DELETED
@@ -1,7 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- def hoax?
4
- return false unless composite?
5
- sum_of_digits == prime_factors.uniq.map{|f| f.sum_of_digits}.reduce(:+)
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- def hyperperfect?(k=1)
4
- raise ArgumentError unless k >= 1
5
- (1 + (k * (σ - self - 1))) == self
6
- end
7
- end
data/lib/numb/impolite.rb DELETED
@@ -1,6 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- def impolite?
4
- not polite?
5
- end
6
- end
@@ -1,15 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- def infinitary_divisors
4
- pf = Hash[prime_factors.uniq.map{|f| [f, 0]}]
5
- bin = divisors.map do |d|
6
- prime_divisors = pf.map(&:first)
7
- [d, pf.merge(Hash[d.primaries]).
8
- values.
9
- map{|v| sprintf("%.#{to_s(2).size}b", v)}.join]
10
- end
11
- bin = Hash[bin]
12
- target = bin[self].chars.map.with_index.to_a.select{|a,b| a == '0'}.map(&:last)
13
- bin.select{|d,b| target.all?{|i| b[i] == '0'}}.keys.sort
14
- end
15
- end
@@ -1,6 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- def infinitary_perfect?
4
- σ∞ == 2*self
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- class Integer
2
- def interprime?
3
- return false if prime?
4
- self == (next_prime + prev_prime)/2
5
- end
6
- end
@@ -1,8 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- def k_perfect?(k)
4
- σ == k * self
5
- end
6
-
7
- alias :multiply_perfect? :k_perfect?
8
- end
@@ -1,5 +0,0 @@
1
- class Integer
2
- def mersenne_prime?
3
- mersenne? and prime?
4
- end
5
- end
data/lib/numb/minimal.rb DELETED
@@ -1,8 +0,0 @@
1
- class Integer
2
- def minimal?
3
- div_n = number_of_divisors
4
- (self-1).downto(1).all? do |n|
5
- n.number_of_divisors != div_n
6
- end
7
- end
8
- end
@@ -1,7 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- def multiamicable?(m, a, b)
4
- return false unless m != self and m < self and a.positive? and b.positive?
5
- m.σ - m == a*self and σ - self == b*m
6
- end
7
- end
@@ -1,5 +0,0 @@
1
- class Integer
2
- def myriagonal?
3
- n_gonal?(10_000)
4
- end
5
- end
data/lib/numb/n_gonal.rb DELETED
@@ -1,7 +0,0 @@
1
- class Integer
2
- def n_gonal?(n)
3
- raise ArgumentError unless n.is_a?(Integer) and n >= 3
4
- return true if zero?
5
- ((Math.sqrt((8*n - 16)*self + (n-4)**2) + n - 4) / (2*n - 4)).integer?
6
- end
7
- end
@@ -1,13 +0,0 @@
1
- class Integer
2
- def next_prime
3
- p = succ
4
- p += 1 until p.prime?
5
- p
6
- end
7
-
8
- def prev_prime
9
- p = self - 1
10
- p -= 1 until p.prime?
11
- p
12
- end
13
- end
@@ -1,17 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- # Algorithm derived from Formulas for pi(n) and the n-th prime by Sebastian
4
- # Martin Ruiz and Jonathan Sondow [arXiv:math/0210312v2 [math.NT]]
5
-
6
- # Returns, after many eons, the nth prime, where n = self
7
- def nth_prime
8
- n = self
9
- return 2 if n == 1
10
- raise ArgumentError if n < 1
11
- (2..( 2*n * Math.log(n) + 2).floor).map do |k|
12
- 1 - (k.π.fdiv(n)).floor
13
- end.reduce(:+) + 2
14
- end
15
-
16
- alias :prime :nth_prime
17
- end
@@ -1,22 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- # Algorithm derived from Formulas for pi(n) and the n-th prime by Sebastian
4
- # Martin Ruiz and Jonathan Sondow [arXiv:math/0210312v2 [math.NT]]
5
-
6
- # Returns the number of divisors of self
7
- def τ
8
- # TODO: Consider something simpler, and perhaps faster, like
9
- # primaries.map(&:last).map(&:succ).reduce(:*)
10
- n = self
11
- return @nod if defined?(@nod)
12
- @nod = (1..isqrt).
13
- map {|i| n.quo(i).to_i - (n - 1).quo(i).to_i }.
14
- reduce(:+) * 2
15
- @nod -= 1 if square?
16
- @nod
17
- end
18
-
19
-
20
- alias :number_of_divisors :τ
21
- alias :d :τ
22
- end
@@ -1,5 +0,0 @@
1
- class Integer
2
- def octagonal?
3
- n_gonal?(8)
4
- end
5
- end
data/lib/numb/ore.rb DELETED
@@ -1,8 +0,0 @@
1
- class Integer
2
- def ore?
3
- div = divisors
4
- Rational(div.size, div.map{|d| Rational(1, d)}.reduce(:+)).denominator == 1
5
- end
6
-
7
- alias :harmonic_divisor? :ore?
8
- end
@@ -1,5 +0,0 @@
1
- class Integer
2
- def pentagonal?
3
- n_gonal?(5)
4
- end
5
- end
data/lib/numb/perfect.rb DELETED
@@ -1,8 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- def perfect?
4
- return false if self < 6 or self.odd? or self.to_s !~ /(6|8)$/
5
- return false if self != 6 and digital_root != 1
6
- k_perfect?(2)
7
- end
8
- end
@@ -1,9 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- def perfect_power?
4
- return false unless positive?
5
- return true if self == 1
6
- divisors = self.divisors
7
- (2..Math.log2(self)).any? { |pow| divisors.any? {|div| (div ** pow) == self} }
8
- end
9
- end
data/lib/numb/polite.rb DELETED
@@ -1,7 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- def polite?
4
- return true if self == 1
5
- politeness.positive?
6
- end
7
- end
data/lib/numb/powerful.rb DELETED
@@ -1,10 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- def powerful?
4
- return false unless positive?
5
- divisors = self.divisors
6
- divisors.select {|d| d.prime? }.all?{|prime| divisors.include? (prime ** 2)}
7
- end
8
-
9
- alias :handsome? :powerful?
10
- end
@@ -1,26 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- # Implementation of Stewart, B. M. (1954), "Sums of distinct divisors",
4
- # American Journal of Mathematics 76: 779–785, doi:10.2307/2372651,
5
- # MR0064800
6
- def practical?
7
- sum = 1
8
- k = 2
9
- n = self
10
- while (n >= k)
11
- s = 1
12
- u = 0
13
- while (n % k == 0)
14
- n = n/k
15
- s = s * k + 1
16
- u += 1
17
- end
18
- unless (u == 0)
19
- return false if (k > sum + 1)
20
- sum *= s
21
- end
22
- k += (k == 2) ? 1 : 2
23
- end
24
- true
25
- end
26
- end
@@ -1,16 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- # Algorithm derived from Formulas for pi(n) and the n-th prime by Sebastian
4
- # Martin Ruiz and Jonathan Sondow [arXiv:math/0210312v2 [math.NT]]
5
-
6
- # Returns the number of primes equal to or less than self
7
- def π
8
- x = self
9
- return 0 if x == 1
10
- @prime_count ||= ([2] + (3..x).select(&:odd?)).map do |j|
11
- 1 + ( ((2 - j.τ)/j).floor ).floor
12
- end.reduce(:+)
13
- end
14
- alias :prime_pi :π
15
- alias :prime_count :π
16
- end
@@ -1,5 +0,0 @@
1
- class Integer
2
- def prime_signature
3
- prime_division.map{|base, exponent| exponent}.sort.reverse
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- class Integer
2
- def primitive_pseudoperfect?
3
- pseudoperfect? and proper_divisors.sort.none?(&:pseudoperfect?)
4
- end
5
- end
data/lib/numb/rhonda.rb DELETED
@@ -1,6 +0,0 @@
1
- class Integer
2
- def rhonda?(base=10)
3
- d = base == 10 ? digits : to_s(base).split(//).map{|_| _.to_i(base)}
4
- d.reduce(:*) == base * (prime_factors.reduce(:+) || 0)
5
- end
6
- end
data/lib/numb/rough.rb DELETED
@@ -1,5 +0,0 @@
1
- class Integer
2
- def rough?(k)
3
- prime_factors.all?{|f| f >= k}
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- class Integer
2
- def safe_prime?
3
- prime? and odd? and ((self - 1) / 2).prime?
4
- end
5
- end
@@ -1,20 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- def semiperfect?
4
- return false if deficient?
5
- return true if perfect?
6
- possibles = { 0 => true}
7
- proper_sod = (sod = σ || 0) - self
8
- proper_divisors.reverse.each do |divisor|
9
- possibles.keys.each do |possible|
10
- possibles.delete(possible) if possible + sod < self
11
- x = possible + divisor
12
- return true if x == self or x == proper_sod
13
- possibles[x] = true if x < self
14
- end
15
- sod -= divisor
16
- end
17
- false
18
- end
19
- alias :pseudoperfect? :semiperfect?
20
- end
@@ -1,6 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- def semiprime?
4
- Ω == 2
5
- end
6
- end
data/lib/numb/smith.rb DELETED
@@ -1,7 +0,0 @@
1
- # coding: utf-8
2
- class Integer
3
- def smith?
4
- return false if prime?
5
- digital_sum == prime_division.map{|d,e| d.digital_sum * e}.reduce(:+)
6
- end
7
- end
data/lib/numb/smooth.rb DELETED
@@ -1,5 +0,0 @@
1
- class Integer
2
- def smooth?(b)
3
- prime_factors.none?{|f| f > b}
4
- end
5
- end
data/lib/numb/sociable.rb DELETED
@@ -1,6 +0,0 @@
1
- class Integer
2
- def sociable?(t)
3
- return false unless t >= 3
4
- aliquot_sequence(t.succ).last == self
5
- end
6
- end
@@ -1,5 +0,0 @@
1
- class Integer
2
- def sophie_germain_prime?
3
- prime? and (2*self).succ.prime?
4
- end
5
- end