numb 0.84.0 → 0.89.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -10
- data/VERSION +1 -1
- data/lib/numb/dihedral_prime.rb +8 -2
- data/lib/numb/goldbach.rb +6 -0
- data/lib/numb/nivenmorphic.rb +1 -1
- data/lib/numb/nonhypotenuse.rb +7 -0
- data/lib/numb/safe_prime.rb +5 -0
- data/lib/numb/st/303/270rmer.rb +6 -0
- data/lib/numb/unusual.rb +5 -0
- data/spec/{dihedral_prime_spec.rb → numb/dihedral_prime_spec.rb} +1 -1
- data/spec/numb/goldbach_spec.rb +23 -0
- data/spec/{nivenmorphic_spec.rb → numb/nivenmorphic_spec.rb} +7 -7
- data/spec/numb/nonhypotenuse_spec.rb +20 -0
- data/spec/{perfect_spec.rb → numb/perfect_spec.rb} +0 -2
- data/spec/numb/safe_prime_spec.rb +20 -0
- data/spec/numb/st/303/270rmer_spec.rb +21 -0
- data/spec/numb/unusual_spec.rb +20 -0
- data/spec/spec_helper.rb +1 -5
- metadata +289 -276
- data/spec/01_spec.rb +0 -1
- /data/spec/{abundancy_spec.rb → numb/abundancy_spec.rb} +0 -0
- /data/spec/{abundant_spec.rb → numb/abundant_spec.rb} +0 -0
- /data/spec/{achilles_spec.rb → numb/achilles_spec.rb} +0 -0
- /data/spec/{almost_perfect_spec.rb → numb/almost_perfect_spec.rb} +0 -0
- /data/spec/{almost_prime_spec.rb → numb/almost_prime_spec.rb} +0 -0
- /data/spec/{amicable_spec.rb → numb/amicable_spec.rb} +0 -0
- /data/spec/{apocalyptic_spec.rb → numb/apocalyptic_spec.rb} +0 -0
- /data/spec/{aspiring_spec.rb → numb/aspiring_spec.rb} +0 -0
- /data/spec/{augmented_amicable_spec.rb → numb/augmented_amicable_spec.rb} +0 -0
- /data/spec/{automorphic_spec.rb → numb/automorphic_spec.rb} +0 -0
- /data/spec/{balanced_prime_spec.rb → numb/balanced_prime_spec.rb} +0 -0
- /data/spec/{base_spec.rb → numb/base_spec.rb} +0 -0
- /data/spec/{binomial_spec.rb → numb/binomial_spec.rb} +0 -0
- /data/spec/{biquadratic_spec.rb → numb/biquadratic_spec.rb} +0 -0
- /data/spec/{breeder_spec.rb → numb/breeder_spec.rb} +0 -0
- /data/spec/{brown_spec.rb → numb/brown_spec.rb} +0 -0
- /data/spec/{carmichael_spec.rb → numb/carmichael_spec.rb} +0 -0
- /data/spec/{carol_spec.rb → numb/carol_spec.rb} +0 -0
- /data/spec/{centered_n_gonal_spec.rb → numb/centered_n_gonal_spec.rb} +0 -0
- /data/spec/{centered_triangular_spec.rb → numb/centered_triangular_spec.rb} +0 -0
- /data/spec/{composite_spec.rb → numb/composite_spec.rb} +0 -0
- /data/spec/{congruum_spec.rb → numb/congruum_spec.rb} +0 -0
- /data/spec/{coprime_spec.rb → numb/coprime_spec.rb} +0 -0
- /data/spec/{core_spec.rb → numb/core_spec.rb} +0 -0
- /data/spec/{cube_spec.rb → numb/cube_spec.rb} +0 -0
- /data/spec/{d_spec.rb → numb/d_spec.rb} +0 -0
- /data/spec/{decagonal_spec.rb → numb/decagonal_spec.rb} +0 -0
- /data/spec/{deficient_spec.rb → numb/deficient_spec.rb} +0 -0
- /data/spec/{digital_sum_spec.rb → numb/digital_sum_spec.rb} +0 -0
- /data/spec/{divides_spec.rb → numb/divides_spec.rb} +0 -0
- /data/spec/{dodecagonal_spec.rb → numb/dodecagonal_spec.rb} +0 -0
- /data/spec/{dudeney_spec.rb → numb/dudeney_spec.rb} +0 -0
- /data/spec/{economical_spec.rb → numb/economical_spec.rb} +0 -0
- /data/spec/{emrip_spec.rb → numb/emrip_spec.rb} +0 -0
- /data/spec/{equidigital_spec.rb → numb/equidigital_spec.rb} +0 -0
- /data/spec/{evil_spec.rb → numb/evil_spec.rb} +0 -0
- /data/spec/{extravagant_spec.rb → numb/extravagant_spec.rb} +0 -0
- /data/spec/{factorial_spec.rb → numb/factorial_spec.rb} +0 -0
- /data/spec/{factorion_spec.rb → numb/factorion_spec.rb} +0 -0
- /data/spec/{fermat_pseudoprime_spec.rb → numb/fermat_pseudoprime_spec.rb} +0 -0
- /data/spec/{fibonacci_spec.rb → numb/fibonacci_spec.rb} +0 -0
- /data/spec/{friendly_spec.rb → numb/friendly_spec.rb} +0 -0
- /data/spec/{frugal_spec.rb → numb/frugal_spec.rb} +0 -0
- /data/spec/{happy_spec.rb → numb/happy_spec.rb} +0 -0
- /data/spec/{harshad_spec.rb → numb/harshad_spec.rb} +0 -0
- /data/spec/{heptagonal_spec.rb → numb/heptagonal_spec.rb} +0 -0
- /data/spec/{hexagonal_spec.rb → numb/hexagonal_spec.rb} +0 -0
- /data/spec/{highly_abundant_spec.rb → numb/highly_abundant_spec.rb} +0 -0
- /data/spec/{highly_composite_spec.rb → numb/highly_composite_spec.rb} +0 -0
- /data/spec/{hilbert_spec.rb → numb/hilbert_spec.rb} +0 -0
- /data/spec/{hyperperfect_spec.rb → numb/hyperperfect_spec.rb} +0 -0
- /data/spec/{idoneal_spec.rb → numb/idoneal_spec.rb} +0 -0
- /data/spec/{integer_p_spec.rb → numb/integer_p_spec.rb} +0 -0
- /data/spec/{interprime_spec.rb → numb/interprime_spec.rb} +0 -0
- /data/spec/{jacobsthal_lucas_spec.rb → numb/jacobsthal_lucas_spec.rb} +0 -0
- /data/spec/{k_perfect.rb → numb/k_perfect_spec.rb} +0 -0
- /data/spec/{kaprekar_spec.rb → numb/kaprekar_spec.rb} +0 -0
- /data/spec/{keith_spec.rb → numb/keith_spec.rb} +0 -0
- /data/spec/{knodel_spec.rb → numb/knodel_spec.rb} +0 -0
- /data/spec/{kynea_spec.rb → numb/kynea_spec.rb} +0 -0
- /data/spec/{leonardo_spec.rb → numb/leonardo_spec.rb} +0 -0
- /data/spec/{leyland_spec.rb → numb/leyland_spec.rb} +0 -0
- /data/spec/{lucas_carmichael_spec.rb → numb/lucas_carmichael_spec.rb} +0 -0
- /data/spec/{lucas_spec.rb → numb/lucas_spec.rb} +0 -0
- /data/spec/{maris_mcgwire_sosa_pair_spec.rb → numb/maris_mcgwire_sosa_pair_spec.rb} +0 -0
- /data/spec/{mersenne_prime_spec.rb → numb/mersenne_prime_spec.rb} +0 -0
- /data/spec/{minimal_spec.rb → numb/minimal_spec.rb} +0 -0
- /data/spec/{mobius_spec.rb → numb/mobius_spec.rb} +0 -0
- /data/spec/{myriagonal_spec.rb → numb/myriagonal_spec.rb} +0 -0
- /data/spec/{narcissistic_spec.rb → numb/narcissistic_spec.rb} +0 -0
- /data/spec/{noncototient_spec.rb → numb/noncototient_spec.rb} +0 -0
- /data/spec/{nth_prime_spec.rb → numb/nth_prime_spec.rb} +0 -0
- /data/spec/{number_of_distinct_prime_factors_spec.rb → numb/number_of_distinct_prime_factors_spec.rb} +0 -0
- /data/spec/{number_of_prime_factors_spec.rb → numb/number_of_prime_factors_spec.rb} +0 -0
- /data/spec/{octagonal_spec.rb → numb/octagonal_spec.rb} +0 -0
- /data/spec/{odious_spec.rb → numb/odious_spec.rb} +0 -0
- /data/spec/{ordinal_spec.rb → numb/ordinal_spec.rb} +0 -0
- /data/spec/{ore_spec.rb → numb/ore_spec.rb} +0 -0
- /data/spec/{parasitic_spec.rb → numb/parasitic_spec.rb} +0 -0
- /data/spec/{pentagonal_spec.rb → numb/pentagonal_spec.rb} +0 -0
- /data/spec/{perfect_power_spec.rb → numb/perfect_power_spec.rb} +0 -0
- /data/spec/{polite_spec.rb → numb/polite_spec.rb} +0 -0
- /data/spec/{politeness_spec.rb → numb/politeness_spec.rb} +0 -0
- /data/spec/{polydivisible_spec.rb → numb/polydivisible_spec.rb} +0 -0
- /data/spec/{positive_spec.rb → numb/positive_spec.rb} +0 -0
- /data/spec/{poulet_spec.rb → numb/poulet_spec.rb} +0 -0
- /data/spec/{powerful_spec.rb → numb/powerful_spec.rb} +0 -0
- /data/spec/{practical_spec.rb → numb/practical_spec.rb} +0 -0
- /data/spec/{prime_count_spec.rb → numb/prime_count_spec.rb} +0 -0
- /data/spec/{prime_signature_spec.rb → numb/prime_signature_spec.rb} +0 -0
- /data/spec/{primitive_pseudoperfect_spec.rb → numb/primitive_pseudoperfect_spec.rb} +0 -0
- /data/spec/{primorial_spec.rb → numb/primorial_spec.rb} +0 -0
- /data/spec/{pronic_spec.rb → numb/pronic_spec.rb} +0 -0
- /data/spec/{proth_spec.rb → numb/proth_spec.rb} +0 -0
- /data/spec/{quarticfree_spec.rb → numb/quarticfree_spec.rb} +0 -0
- /data/spec/{refactorable_spec.rb → numb/refactorable_spec.rb} +0 -0
- /data/spec/{repunit_spec.rb → numb/repunit_spec.rb} +0 -0
- /data/spec/{rhonda_spec.rb → numb/rhonda_spec.rb} +0 -0
- /data/spec/{rough_spec.rb → numb/rough_spec.rb} +0 -0
- /data/spec/{self_descriptive_spec.rb → numb/self_descriptive_spec.rb} +0 -0
- /data/spec/{self_spec.rb → numb/self_spec.rb} +0 -0
- /data/spec/{semi_perfect_spec.rb → numb/semi_perfect_spec.rb} +0 -0
- /data/spec/{semiprime_spec.rb → numb/semiprime_spec.rb} +0 -0
- /data/spec/{smarandache_wellin_spec.rb → numb/smarandache_wellin_spec.rb} +0 -0
- /data/spec/{smith_spec.rb → numb/smith_spec.rb} +0 -0
- /data/spec/{smooth_spec.rb → numb/smooth_spec.rb} +0 -0
- /data/spec/{sociable_spec.rb → numb/sociable_spec.rb} +0 -0
- /data/spec/{sophie_germain_prime_spec.rb → numb/sophie_germain_prime_spec.rb} +0 -0
- /data/spec/{sphenic_spec.rb → numb/sphenic_spec.rb} +0 -0
- /data/spec/{square_free_spec.rb → numb/square_free_spec.rb} +0 -0
- /data/spec/{square_spec.rb → numb/square_spec.rb} +0 -0
- /data/spec/{sublime_spec.rb → numb/sublime_spec.rb} +0 -0
- /data/spec/{sum_of_squares.rb → numb/sum_of_squares_spec.rb} +0 -0
- /data/spec/{sum_of_unitary_divisors_spec.rb → numb/sum_of_unitary_divisors_spec.rb} +0 -0
- /data/spec/{superabundant_spec.rb → numb/superabundant_spec.rb} +0 -0
- /data/spec/{superperfect_spec.rb → numb/superperfect_spec.rb} +0 -0
- /data/spec/{totient_spec.rb → numb/totient_spec.rb} +0 -0
- /data/spec/{triangular_spec.rb → numb/triangular_spec.rb} +0 -0
- /data/spec/{trimorphic_spec.rb → numb/trimorphic_spec.rb} +0 -0
- /data/spec/{twin_prime_spec.rb → numb/twin_prime_spec.rb} +0 -0
- /data/spec/{undulating_spec.rb → numb/undulating_spec.rb} +0 -0
- /data/spec/{unhappy_spec.rb → numb/unhappy_spec.rb} +0 -0
- /data/spec/{unitary_amicable_spec.rb → numb/unitary_amicable_spec.rb} +0 -0
- /data/spec/{unitary_divisor_spec.rb → numb/unitary_divisor_spec.rb} +0 -0
- /data/spec/{unitary_perfect.rb → numb/unitary_perfect_spec.rb} +0 -0
- /data/spec/{unitary_sociable.rb → numb/unitary_sociable_spec.rb} +0 -0
- /data/spec/{untouchable_spec.rb → numb/untouchable_spec.rb} +0 -0
- /data/spec/{vampire_spec.rb → numb/vampire_spec.rb} +0 -0
- /data/spec/{weird_spec.rb → numb/weird_spec.rb} +0 -0
- /data/spec/{wieferich_prime_spec.rb → numb/wieferich_prime_spec.rb} +0 -0
- /data/spec/{woodall_spec.rb → numb/woodall_spec.rb} +0 -0
- /data/spec/{zeisel_spec.rb → numb/zeisel_spec.rb} +0 -0
- /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 '
|
25
|
-
|
26
|
-
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.
|
1
|
+
0.89.0
|
data/lib/numb/dihedral_prime.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/numb/nivenmorphic.rb
CHANGED
data/lib/numb/unusual.rb
ADDED
@@ -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
|
-
#
|
3
|
-
@seq = [1,2,3,4,5,6,7,8,9,910,
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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.
|
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
|
@@ -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 '
|
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
|