numb 0.152.0 → 0.170.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/numb/bell.rb +9 -12
- data/lib/numb/bernoulli.rb +7 -8
- data/lib/numb/catalan.rb +1 -5
- data/lib/numb/divisors/abundant.rb +58 -0
- data/lib/numb/divisors/aliquot.rb +31 -0
- data/lib/numb/divisors/amicable.rb +38 -0
- data/lib/numb/divisors/perfect.rb +73 -0
- data/lib/numb/divisors.rb +389 -0
- data/lib/numb/entringer.rb +2 -0
- data/lib/numb/figurate.rb +138 -0
- data/lib/numb/in_sequence.rb +11 -0
- data/lib/numb/jacobsthal_lucas.rb +5 -6
- data/lib/numb/knuth.rb +1 -4
- data/lib/numb/lucas.rb +5 -5
- data/lib/numb/lucas2.rb +11 -0
- data/lib/numb/lychrel.rb +0 -4
- data/lib/numb/palindrome.rb +8 -0
- data/lib/numb/pell_lucas.rb +9 -0
- data/lib/numb/primes.rb +164 -0
- data/lib/numb/pronic.rb +1 -0
- data/lib/numb/q.rb +13 -0
- data/lib/numb/schr/303/266der.rb +20 -0
- data/lib/numb/segmented.rb +29 -0
- data/lib/numb/stirling.rb +9 -0
- data/lib/numb/stirling2.rb +9 -0
- data/lib/numb/strictly_non_palindromic.rb +1 -5
- data/lib/numb/super_catalan.rb +17 -0
- data/lib/numb/super_d.rb +6 -0
- data/lib/numb/takeuchi.rb +18 -0
- data/lib/numb/unhappy.rb +2 -0
- data/lib/numb.rb +1 -53
- data/spec/numb/first_with_n_divisors_spec.rb +15 -0
- data/spec/numb/highly_composite_spec.rb +1 -1
- data/spec/numb/jacobsthal_lucas_spec.rb +19 -11
- data/spec/numb/lucas2_spec.rb +30 -0
- data/spec/numb/lucas_spec.rb +17 -9
- data/spec/numb/minimal_spec.rb +1 -1
- data/spec/numb/near_square_spec.rb +54 -0
- data/spec/numb/octahedral_spec.rb +29 -0
- data/spec/numb/palindrome_spec.rb +43 -0
- data/spec/numb/pell_lucas_spec.rb +28 -0
- data/spec/numb/pentatope_spec.rb +15 -0
- data/spec/numb/primitive_abundant_spec.rb +21 -0
- data/spec/numb/pyramidal_spec.rb +42 -0
- data/spec/numb/q_spec.rb +31 -0
- data/spec/numb/schr/303/266der_spec.rb +28 -0
- data/spec/numb/segmented_spec.rb +29 -0
- data/spec/numb/square_part_spec.rb +15 -0
- data/spec/numb/star_spec.rb +29 -0
- data/spec/numb/stella_octangula_spec.rb +29 -0
- data/spec/numb/stirling2_spec.rb +23 -0
- data/spec/numb/stirling_spec.rb +23 -0
- data/spec/numb/super_catalan_spec.rb +29 -0
- data/spec/numb/super_d_spec.rb +68 -0
- data/spec/numb/takeuchi_spec.rb +28 -0
- data/spec/numb/tetrahedral_spec.rb +15 -0
- metadata +63 -100
- data/lib/numb/abundancy.rb +0 -8
- data/lib/numb/abundant.rb +0 -20
- data/lib/numb/achilles.rb +0 -15
- data/lib/numb/aliquot_sequence.rb +0 -13
- data/lib/numb/almost_perfect.rb +0 -8
- data/lib/numb/almost_prime.rb +0 -6
- data/lib/numb/amicable.rb +0 -6
- data/lib/numb/aspiring.rb +0 -8
- data/lib/numb/augmented_amicable.rb +0 -7
- data/lib/numb/balanced_prime.rb +0 -10
- data/lib/numb/betrothed.rb +0 -8
- data/lib/numb/breeder.rb +0 -9
- data/lib/numb/brilliant.rb +0 -7
- data/lib/numb/centered_cube.rb +0 -7
- data/lib/numb/centered_hexagonal.rb +0 -6
- data/lib/numb/centered_n_gonal.rb +0 -9
- data/lib/numb/centered_pentagonal.rb +0 -6
- data/lib/numb/centered_square.rb +0 -5
- data/lib/numb/centered_triangular.rb +0 -5
- data/lib/numb/composite.rb +0 -5
- data/lib/numb/coprime.rb +0 -9
- data/lib/numb/cube.rb +0 -5
- data/lib/numb/d.rb +0 -6
- data/lib/numb/decagonal.rb +0 -5
- data/lib/numb/deficient.rb +0 -19
- data/lib/numb/dihedral_prime.rb +0 -26
- data/lib/numb/dodecagonal.rb +0 -5
- data/lib/numb/e_divisors.rb +0 -10
- data/lib/numb/e_perfect.rb +0 -7
- data/lib/numb/economical.rb +0 -16
- data/lib/numb/emrip.rb +0 -15
- data/lib/numb/equidigital.rb +0 -18
- data/lib/numb/extravagant.rb +0 -18
- data/lib/numb/fermat_pseudoprime.rb +0 -9
- data/lib/numb/friendly.rb +0 -9
- data/lib/numb/full_reptend_prime.rb +0 -5
- data/lib/numb/giuga.rb +0 -7
- data/lib/numb/harshad.rb +0 -9
- data/lib/numb/heptagonal.rb +0 -5
- data/lib/numb/hexagonal.rb +0 -6
- data/lib/numb/highly_abundant.rb +0 -7
- data/lib/numb/highly_composite.rb +0 -12
- data/lib/numb/hoax.rb +0 -7
- data/lib/numb/hyperperfect.rb +0 -7
- data/lib/numb/impolite.rb +0 -6
- data/lib/numb/infinitary_divisors.rb +0 -15
- data/lib/numb/infinitary_perfect.rb +0 -6
- data/lib/numb/interprime.rb +0 -6
- data/lib/numb/k_perfect.rb +0 -8
- data/lib/numb/mersenne_prime.rb +0 -5
- data/lib/numb/minimal.rb +0 -8
- data/lib/numb/multiamicable.rb +0 -7
- data/lib/numb/myriagonal.rb +0 -5
- data/lib/numb/n_gonal.rb +0 -7
- data/lib/numb/next_prev_prime.rb +0 -13
- data/lib/numb/nth_prime.rb +0 -17
- data/lib/numb/number_of_divisors.rb +0 -22
- data/lib/numb/octagonal.rb +0 -5
- data/lib/numb/ore.rb +0 -8
- data/lib/numb/pentagonal.rb +0 -5
- data/lib/numb/perfect.rb +0 -8
- data/lib/numb/perfect_power.rb +0 -9
- data/lib/numb/polite.rb +0 -7
- data/lib/numb/powerful.rb +0 -10
- data/lib/numb/practical.rb +0 -26
- data/lib/numb/prime_count.rb +0 -16
- data/lib/numb/prime_signature.rb +0 -5
- data/lib/numb/primitive_pseudoperfect.rb +0 -5
- data/lib/numb/rhonda.rb +0 -6
- data/lib/numb/rough.rb +0 -5
- data/lib/numb/safe_prime.rb +0 -5
- data/lib/numb/semiperfect.rb +0 -20
- data/lib/numb/semiprime.rb +0 -6
- data/lib/numb/smith.rb +0 -7
- data/lib/numb/smooth.rb +0 -5
- data/lib/numb/sociable.rb +0 -6
- data/lib/numb/sophie_germain_prime.rb +0 -5
- data/lib/numb/square.rb +0 -7
- data/lib/numb/square_free.rb +0 -6
- data/lib/numb/square_triangular.rb +0 -5
- data/lib/numb/squared_triangular.rb +0 -5
- data/lib/numb/sublime.rb +0 -6
- data/lib/numb/sum_of_e_divisors.rb +0 -10
- data/lib/numb/sum_of_infinitary_divisors.rb +0 -9
- data/lib/numb/sum_of_unitary_divisors.rb +0 -5
- data/lib/numb/super_poulet.rb +0 -5
- data/lib/numb/superabundant.rb +0 -18
- data/lib/numb/superperfect.rb +0 -6
- data/lib/numb/triangular.rb +0 -6
- data/lib/numb/twin_prime.rb +0 -5
- data/lib/numb/unitary_amicable.rb +0 -7
- data/lib/numb/unitary_divisor.rb +0 -5
- data/lib/numb/unitary_perfect.rb +0 -7
- data/lib/numb/unitary_sociable.rb +0 -7
- data/lib/numb/untouchable.rb +0 -14
- data/lib/numb/unusual.rb +0 -5
- data/lib/numb/weird.rb +0 -8
- data/lib/numb/wieferich.rb +0 -6
data/lib/numb/centered_square.rb
DELETED
data/lib/numb/composite.rb
DELETED
data/lib/numb/coprime.rb
DELETED
data/lib/numb/cube.rb
DELETED
data/lib/numb/d.rb
DELETED
data/lib/numb/decagonal.rb
DELETED
data/lib/numb/deficient.rb
DELETED
@@ -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
|
data/lib/numb/dihedral_prime.rb
DELETED
@@ -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
|
data/lib/numb/dodecagonal.rb
DELETED
data/lib/numb/e_divisors.rb
DELETED
@@ -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
|
data/lib/numb/e_perfect.rb
DELETED
data/lib/numb/economical.rb
DELETED
@@ -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
|
data/lib/numb/equidigital.rb
DELETED
@@ -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
|
data/lib/numb/extravagant.rb
DELETED
@@ -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
|
data/lib/numb/friendly.rb
DELETED
data/lib/numb/giuga.rb
DELETED
data/lib/numb/harshad.rb
DELETED
data/lib/numb/heptagonal.rb
DELETED
data/lib/numb/hexagonal.rb
DELETED
data/lib/numb/highly_abundant.rb
DELETED
@@ -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
data/lib/numb/hyperperfect.rb
DELETED
data/lib/numb/impolite.rb
DELETED
@@ -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
|
data/lib/numb/interprime.rb
DELETED
data/lib/numb/k_perfect.rb
DELETED
data/lib/numb/mersenne_prime.rb
DELETED
data/lib/numb/minimal.rb
DELETED
data/lib/numb/multiamicable.rb
DELETED
data/lib/numb/myriagonal.rb
DELETED
data/lib/numb/n_gonal.rb
DELETED
data/lib/numb/next_prev_prime.rb
DELETED
data/lib/numb/nth_prime.rb
DELETED
@@ -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
|
data/lib/numb/octagonal.rb
DELETED
data/lib/numb/ore.rb
DELETED
data/lib/numb/pentagonal.rb
DELETED
data/lib/numb/perfect.rb
DELETED
data/lib/numb/perfect_power.rb
DELETED
data/lib/numb/polite.rb
DELETED
data/lib/numb/powerful.rb
DELETED
data/lib/numb/practical.rb
DELETED
@@ -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
|
data/lib/numb/prime_count.rb
DELETED
@@ -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
|
data/lib/numb/prime_signature.rb
DELETED
data/lib/numb/rhonda.rb
DELETED
data/lib/numb/rough.rb
DELETED
data/lib/numb/safe_prime.rb
DELETED
data/lib/numb/semiperfect.rb
DELETED
@@ -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
|
data/lib/numb/semiprime.rb
DELETED
data/lib/numb/smith.rb
DELETED
data/lib/numb/smooth.rb
DELETED
data/lib/numb/sociable.rb
DELETED