numb 0.111.0 → 0.114.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.111.0
1
+ 0.114.0
@@ -6,7 +6,7 @@ class Integer
6
6
  max_iterations.floor.times do |limit|
7
7
  sequence << summatory_function[sequence.last]
8
8
  break if sequence[0..-2].include?(sequence.last)
9
- return sequence << (1/0.0) if limit.succ == max_iterations
9
+ return sequence << (1/0.0) if limit.consecutive?(max_iterations)
10
10
  end
11
11
  sequence
12
12
  end
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  class Integer
3
3
  def betrothed?(m)
4
- σ == m.σ and σ == self.succ + m
4
+ σ == m.σ and consecutive?(σ - m)
5
5
  end
6
6
  alias :quasi_amicable? :betrothed?
7
7
  alias :reduced_amicable? :betrothed?
data/lib/numb/brown.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  class Integer
2
2
  def brown?(n)
3
- m = self
4
- n.factorial.succ == m**2
3
+ n.factorial.consecutive?(self ** 2)
5
4
  end
6
5
  end
@@ -0,0 +1,13 @@
1
+ class Integer
2
+ def catalan
3
+ (2*self).factorial / (succ.factorial * factorial)
4
+ end
5
+
6
+ def catalan?
7
+ n = -1
8
+ loop do
9
+ return true if (cat = (n += 1).catalan) == self
10
+ return false if cat > self
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ class Integer
2
+ def centered_cube?
3
+ 1.upto(Math.cbrt(self)).any? do |n|
4
+ self == n**3 + (n - 1) ** 3
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ class Integer
2
+ def centered_hexagonal?
3
+ n = self - 1
4
+ n.divides?(6) and (n/6).triangular?
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class Integer
2
+ def consecutive?(m)
3
+ self == m.succ or succ == m
4
+ end
5
+ end
@@ -21,11 +21,6 @@ class Integer
21
21
  def dihedral_prime?
22
22
  return false unless prime? and to_s.match(/^[01825]+$/)
23
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
+ [reverse, mirror[self], mirror[reverse]].all?(&:prime?)
30
25
  end
31
26
  end
data/lib/numb/emrip.rb CHANGED
@@ -10,8 +10,6 @@ class Integer
10
10
  # 7.emrip? #=> false
11
11
  #
12
12
  def emrip?
13
- return false unless prime?
14
- reversed = to_s.reverse.to_i
15
- reversed != self and reversed.prime?
13
+ prime? and reverse != self and reverse.prime?
16
14
  end
17
15
  end
data/lib/numb/idoneal.rb CHANGED
@@ -62,4 +62,5 @@ class Integer
62
62
  end
63
63
  true
64
64
  end
65
+ alias :convenient? :idoneal?
65
66
  end
data/lib/numb/lychrel.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  class Integer
2
2
  def palindrome?
3
- to_s.reverse.to_i == self
3
+ reverse == self
4
4
  end
5
5
 
6
6
  def lychrel?
@@ -8,7 +8,7 @@ class Integer
8
8
  # This limit is as arbitrary as it looks
9
9
  100.times do
10
10
  return false if n.palindrome?
11
- n += n.to_s.reverse.to_i
11
+ n += n.reverse
12
12
  end
13
13
  true
14
14
  end
data/lib/numb/mms_pair.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  class Integer
3
3
  def mms_pair?(other)
4
- return false unless (self == other.succ) || (other == self.succ)
4
+ return false unless consecutive?(other)
5
5
  sum = [self,other].map do |n|
6
6
  (n.digits + n.prime_factors.map{|p| p.digits}.flatten).reduce(:+)
7
7
  end
@@ -0,0 +1,11 @@
1
+ class Integer
2
+ def properties
3
+ methods.grep(/\?/).
4
+ map{|m| method(m)}.
5
+ uniq. # Filter out aliases
6
+ select{|m| m.arity.zero? and m[]}.
7
+ map{|m| m.name[0..-2]}. # Strip question mark
8
+ map(&:to_sym).
9
+ sort
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ class Integer
2
+ def reverse
3
+ to_s.reverse.to_i
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ # A000108
2
+ CATALAN = [1,1,2,5,14,42,132,429,1430,4862,16796,58786,
3
+ 208012,742900,2674440,9694845,35357670,129644790,
4
+ 477638700,1767263190,6564120420,24466267020,
5
+ 91482563640,343059613650,1289904147324]
6
+
7
+ describe Integer, "#catalan?" do
8
+ @seq = CATALAN.uniq
9
+
10
+ @seq.each do |n|
11
+ it "returns true for Catalan number #{n}" do
12
+ n.should be_catalan
13
+ end
14
+ end
15
+
16
+ @seq.to_seq.invert.sample(100).each do |n|
17
+ it "returns false for non-Catalan number #{n}" do
18
+ n.should_not be_catalan
19
+ end
20
+ end
21
+ end
22
+
23
+ describe Integer, "#catalan" do
24
+ CATALAN.each_with_index do |catalan, n|
25
+ it "returns #{catalan} for #{n}" do
26
+ n.catalan.should == catalan
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ describe Integer, "#centered_cube?" do
2
+ # A005898
3
+ @seq = [1,9,35,91,189,341,559,855,1241,1729,2331,3059,
4
+ 3925,4941,6119,7471,9009,10745,12691,14859,17261,
5
+ 19909,22815,25991,29449,33201,37259,41635,46341,
6
+ 51389,56791,62559,68705,75241,82179,89531,97309,
7
+ 105525]
8
+
9
+ @seq.each do |n|
10
+ it "returns true for centered cube #{n}" do
11
+ n.should be_centered_cube
12
+ end
13
+ end
14
+
15
+ @seq.to_seq.invert.sample(100).each do |n|
16
+ it "returns false for non-centered-cube #{n}" do
17
+ n.should_not be_centered_cube
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ describe Integer, "#centered_hexagonal?" do
2
+ # A003215
3
+ @seq = [1,7,19,37,61,91,127,169,217,271,331,397,469,547,
4
+ 631,721,817,919,1027,1141,1261,1387,1519,1657,
5
+ 1801,1951,2107,2269,2437,2611,2791,2977,3169,3367,
6
+ 3571,3781,3997,4219,4447,4681,4921,5167,5419,5677,
7
+ 5941,6211,6487]
8
+
9
+ @seq.each do |n|
10
+ it "returns true for centered hexagonal number #{n}" do
11
+ n.should be_centered_hexagonal
12
+ end
13
+ end
14
+
15
+ @seq.to_seq.invert.sample(100).each do |n|
16
+ it "returns false for non-centered-hexagonal number #{n}" do
17
+ n.should_not be_centered_hexagonal
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ describe Integer, "#reverse" do
2
+ it "returns single digits as-is" do
3
+ (0..9).each do |n|
4
+ n.reverse.should == n
5
+ end
6
+ end
7
+
8
+ [[10,1], [99, 99], [1234, 4321], [101, 101], [8272, 2728]].each do |n,r|
9
+ it "returns #{r} for #{n}" do
10
+ n.reverse.should == r
11
+ end
12
+ end
13
+ 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.111.0
4
+ version: 0.114.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-13 00:00:00 +00:00
12
+ date: 2010-03-14 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -64,10 +64,14 @@ files:
64
64
  - lib/numb/brown.rb
65
65
  - lib/numb/carmichael.rb
66
66
  - lib/numb/carol.rb
67
+ - lib/numb/catalan.rb
68
+ - lib/numb/centered_cube.rb
69
+ - lib/numb/centered_hexagonal.rb
67
70
  - lib/numb/centered_n_gonal.rb
68
71
  - lib/numb/centered_triangular.rb
69
72
  - lib/numb/composite.rb
70
73
  - lib/numb/congruum.rb
74
+ - lib/numb/consecutive.rb
71
75
  - lib/numb/coprime.rb
72
76
  - lib/numb/core.rb
73
77
  - lib/numb/cototient.rb
@@ -153,10 +157,12 @@ files:
153
157
  - lib/numb/primitive_pseudoperfect.rb
154
158
  - lib/numb/primorial.rb
155
159
  - lib/numb/pronic.rb
160
+ - lib/numb/properties.rb
156
161
  - lib/numb/proth.rb
157
162
  - lib/numb/quarticfree.rb
158
163
  - lib/numb/refactorable.rb
159
164
  - lib/numb/repunit.rb
165
+ - lib/numb/reverse.rb
160
166
  - lib/numb/rhonda.rb
161
167
  - lib/numb/rough.rb
162
168
  - lib/numb/safe_prime.rb
@@ -227,6 +233,9 @@ files:
227
233
  - spec/numb/brown_spec.rb
228
234
  - spec/numb/carmichael_spec.rb
229
235
  - spec/numb/carol_spec.rb
236
+ - spec/numb/catalan_spec.rb
237
+ - spec/numb/centered_cube_spec.rb
238
+ - spec/numb/centered_hexagonal_spec.rb
230
239
  - spec/numb/centered_n_gonal_spec.rb
231
240
  - spec/numb/centered_triangular_spec.rb
232
241
  - spec/numb/composite_spec.rb
@@ -320,6 +329,7 @@ files:
320
329
  - spec/numb/quarticfree_spec.rb
321
330
  - spec/numb/refactorable_spec.rb
322
331
  - spec/numb/repunit_spec.rb
332
+ - spec/numb/reverse_spec.rb
323
333
  - spec/numb/rhonda_spec.rb
324
334
  - spec/numb/rough_spec.rb
325
335
  - spec/numb/safe_prime_spec.rb
@@ -429,6 +439,7 @@ test_files:
429
439
  - spec/numb/perfect_spec.rb
430
440
  - spec/numb/perfect_power_spec.rb
431
441
  - spec/numb/factorial_spec.rb
442
+ - spec/numb/centered_cube_spec.rb
432
443
  - spec/numb/carmichael_spec.rb
433
444
  - spec/numb/woodall_spec.rb
434
445
  - spec/numb/abundancy_spec.rb
@@ -450,6 +461,7 @@ test_files:
450
461
  - spec/numb/heptagonal_spec.rb
451
462
  - spec/numb/kynea_spec.rb
452
463
  - spec/numb/sum_of_squares_spec.rb
464
+ - spec/numb/centered_hexagonal_spec.rb
453
465
  - spec/numb/centered_n_gonal_spec.rb
454
466
  - spec/numb/highly_abundant_spec.rb
455
467
  - spec/numb/augmented_amicable_spec.rb
@@ -475,6 +487,7 @@ test_files:
475
487
  - spec/numb/dihedral_prime_spec.rb
476
488
  - spec/numb/breeder_spec.rb
477
489
  - spec/numb/sphenic_spec.rb
490
+ - spec/numb/reverse_spec.rb
478
491
  - spec/numb/idoneal_spec.rb
479
492
  - spec/numb/sum_of_unitary_divisors_spec.rb
480
493
  - spec/numb/square_triangular_spec.rb
@@ -528,6 +541,7 @@ test_files:
528
541
  - spec/numb/weird_spec.rb
529
542
  - spec/numb/interprime_spec.rb
530
543
  - spec/numb/number_of_distinct_prime_factors_spec.rb
544
+ - spec/numb/catalan_spec.rb
531
545
  - spec/numb/balanced_prime_spec.rb
532
546
  - spec/numb/binomial_spec.rb
533
547
  - spec/numb/digital_sum_spec.rb