numb 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/numb/primitive_pseudoperfect.rb +5 -0
- data/lib/numb/semiperfect.rb +20 -0
- data/lib/numb/weird.rb +1 -1
- data/lib/numb.rb +4 -4
- data/spec/primitive_pseudoperfect_spec.rb +18 -0
- data/spec/semi_perfect_spec.rb +30 -4
- metadata +5 -2
- data/lib/numb/semi_perfect.rb +0 -15
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.9.0
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
class Integer
|
3
|
+
def semiperfect?
|
4
|
+
return false if deficient?
|
5
|
+
return true if perfect?
|
6
|
+
possibles, divisors = { 0 => true}, proper_positive_divisors
|
7
|
+
proper_sod = (sod = sum_of_divisors || 0) - self
|
8
|
+
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/weird.rb
CHANGED
data/lib/numb.rb
CHANGED
@@ -5,10 +5,10 @@ libs = %w{abundant achilles automorphic balanced_prime carol composite deficient
|
|
5
5
|
extravagant factorion frugal happy harshad hilbert hyperperfect
|
6
6
|
impolite kaprekar keith kynea lucas lucas_carmichael mms_pair mobius
|
7
7
|
narcissistic nivenmorphic ordinal parasitic perfect perfect_power
|
8
|
-
polite polydivisible powerful practical
|
9
|
-
|
10
|
-
|
11
|
-
weird
|
8
|
+
polite polydivisible powerful practical primitive_pseudoperfect
|
9
|
+
pronic self self_descriptive semiperfect semiprime
|
10
|
+
smarandache_wellin smith sophie_germain_prime sphenic square
|
11
|
+
square_free triangular trimorphic undulating vampire weird
|
12
12
|
}
|
13
13
|
|
14
14
|
class Integer
|
@@ -0,0 +1,18 @@
|
|
1
|
+
describe Integer, "#primitive_pseudoperfect" do
|
2
|
+
PPP = [6,20,28,88,104,272,304,350,368,464,490,496,550,
|
3
|
+
572,650,748,770,910,945,1184,1190,1312,1330,1376,
|
4
|
+
1430,1504,1575,1610,1696,1870,1888,1952,2002,2030,
|
5
|
+
2090,2170,2205,2210,2470,2530,2584,2590,2870,2990,
|
6
|
+
3010,3128,3190,3230,3290,3410,3465,3496,3710,3770,
|
7
|
+
3944,4070,4095,4130,4216,4270,4288,4408,4510,4544,
|
8
|
+
4672,4690,4712,4730,4970]
|
9
|
+
it "returns true for primitive pseudoperfect numbers" do
|
10
|
+
PPP.shuffle.first(10).each{|_| _.should be_primitive_pseudoperfect}
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns true for primitive pseudoperfect numbers" do
|
14
|
+
((1..PPP.max).to_a - PPP).shuffle.
|
15
|
+
first(10).
|
16
|
+
each{|_| _.should_not be_primitive_pseudoperfect}
|
17
|
+
end
|
18
|
+
end
|
data/spec/semi_perfect_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
describe Integer, "#
|
1
|
+
describe Integer, "#semiperfect?" do
|
2
2
|
SEMI_PERFECT = [6,12,18,20,24,28,30,36,40,42,48,54,56,60,66,72,
|
3
3
|
78,80,84,88,90,96,100,102,104,108,112,114,120,126,
|
4
4
|
132,138,140,144,150,156,160,162,168,174,176,180,
|
@@ -6,19 +6,45 @@ describe Integer, "#semi_perfect?" do
|
|
6
6
|
228,234,240,246,252,258,260,264]
|
7
7
|
it "returns true if the number is semi-perfect" do
|
8
8
|
SEMI_PERFECT.each do |number|
|
9
|
-
number.should
|
9
|
+
number.should be_semiperfect
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns true if the number is a multiple of a known semi-perfect" do
|
14
|
+
(SEMI_PERFECT.combination(2).map{|_| _.reduce(:*)}.uniq - SEMI_PERFECT).
|
15
|
+
shuffle.first(15).each do |number|
|
16
|
+
number.should be_semiperfect
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Guy, R. K.
|
21
|
+
# "Almost Perfect, Quasi-Perfect, Pseudoperfect, Harmonic, Weird, Multiperfect and Hyperperfect Numbers."
|
22
|
+
# §B2 in Unsolved Problems in Number Theory, 2nd ed. New York: Springer-Verlag, pp. 45-53, 1994
|
23
|
+
it "returns true for 2**m * p (where m >= 1 && p.prime? && (p < 2**(m+1) && p > 2**m)" do
|
24
|
+
[[4, 17], [4, 19], [4, 23], [4, 29], [4, 31],
|
25
|
+
[5, 37], [5, 41], [5, 43], [5, 47], [5, 53], [5, 59], [5, 61],
|
26
|
+
[6, 67], [6, 71], [6, 73], [6, 79], [6, 83], [6, 89], [6, 97],
|
27
|
+
[6, 101],[6, 103],[6, 107],[6, 109],[6, 113],[6, 127]].shuffle.first(10).each do |m,p|
|
28
|
+
(2**m * p).should be_semiperfect
|
10
29
|
end
|
11
30
|
end
|
12
31
|
|
13
32
|
it "returns false if the number is not semi-perfect" do
|
14
33
|
((1..263).to_a - SEMI_PERFECT).each do |number|
|
15
|
-
number.should_not
|
34
|
+
number.should_not be_semiperfect
|
16
35
|
end
|
17
36
|
end
|
18
37
|
|
19
38
|
it "returns false if the number is negative" do
|
20
39
|
(1..263).each do |number|
|
21
|
-
(-number).should_not
|
40
|
+
(-number).should_not be_semiperfect
|
22
41
|
end
|
23
42
|
end
|
43
|
+
|
44
|
+
it "handles large input quickly and without raising a RangeError" do
|
45
|
+
require 'timeout'
|
46
|
+
lambda do
|
47
|
+
Timeout.timeout(5) { 19305.semiperfect? }
|
48
|
+
end.should_not raise_error
|
49
|
+
end
|
24
50
|
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.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Run Paint Run Run
|
@@ -77,12 +77,13 @@ files:
|
|
77
77
|
- lib/numb/powerful.rb
|
78
78
|
- lib/numb/practical.rb
|
79
79
|
- lib/numb/prime.rb
|
80
|
+
- lib/numb/primitive_pseudoperfect.rb
|
80
81
|
- lib/numb/pronic.rb
|
81
82
|
- lib/numb/ruby1.8.rb
|
82
83
|
- lib/numb/ruby1.9.rb
|
83
84
|
- lib/numb/self.rb
|
84
85
|
- lib/numb/self_descriptive.rb
|
85
|
-
- lib/numb/
|
86
|
+
- lib/numb/semiperfect.rb
|
86
87
|
- lib/numb/semiprime.rb
|
87
88
|
- lib/numb/smarandache_wellin.rb
|
88
89
|
- lib/numb/smith.rb
|
@@ -136,6 +137,7 @@ files:
|
|
136
137
|
- spec/polydivisible_spec.rb
|
137
138
|
- spec/powerful_spec.rb
|
138
139
|
- spec/practical_spec.rb
|
140
|
+
- spec/primitive_pseudoperfect_spec.rb
|
139
141
|
- spec/pronic_spec.rb
|
140
142
|
- spec/self_descriptive_spec.rb
|
141
143
|
- spec/self_spec.rb
|
@@ -184,6 +186,7 @@ specification_version: 3
|
|
184
186
|
summary: Experiments in number theory with new predicate methods for Integer.
|
185
187
|
test_files:
|
186
188
|
- spec/economical_spec.rb
|
189
|
+
- spec/primitive_pseudoperfect_spec.rb
|
187
190
|
- spec/polydivisible_spec.rb
|
188
191
|
- spec/equidigital_spec.rb
|
189
192
|
- spec/nivenmorphic_spec.rb
|
data/lib/numb/semi_perfect.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
class Integer
|
3
|
-
def semi_perfect?
|
4
|
-
return false if deficient?
|
5
|
-
return true if perfect?
|
6
|
-
divisors = proper_positive_divisors
|
7
|
-
1.upto(divisors.size-1) do |size|
|
8
|
-
divisors.combination(size) do |comb|
|
9
|
-
return true if Array(comb).reduce(:+) == self
|
10
|
-
end
|
11
|
-
end
|
12
|
-
false
|
13
|
-
end
|
14
|
-
alias :pseudo_perfect? :semi_perfect?
|
15
|
-
end
|