numb 0.68.0 → 0.72.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.68.0
1
+ 0.72.0
data/lib/numb.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  # coding: utf-8
2
2
 
3
- libs = %w{abundancy abundant achilles almost_perfect amicable aspiring
4
- automorphic balanced_prime biquadratic breeder brown carmichael carol
5
- centered_n_gonal centered_triangular congruum composite coprime
6
- core cototient cube d decagonal deficient dodecagonal dihedral_prime
7
- dudeney economical emrip equidigital extravagant factorial factorion
3
+ libs = %w{abundancy abundant achilles almost_perfect almost_prime amicable
4
+ apocalyptic aspiring augmented_amicable automorphic balanced_prime
5
+ binomial biquadratic breeder brown carmichael carol centered_n_gonal
6
+ centered_triangular congruum composite coprime core cototient
7
+ cube d decagonal deficient dodecagonal dihedral_prime dudeney
8
+ economical emrip equidigital extravagant factorial factorion
8
9
  fermat_pseudoprime fibonacci friendly frugal happy harshad
9
10
  heptagonal hexagonal highly_composite highly_abundant hilbert
10
11
  hyperperfect idoneal impolite integer_p interprime
@@ -0,0 +1,6 @@
1
+ # coding: utf-8
2
+ class Integer
3
+ def almost_prime?(k)
4
+ Ω == k
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class Integer
2
+ def apocalyptic?
3
+ (2**self).to_s.include?('666')
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ # coding: utf-8
2
+ class Integer
3
+ def augmented_amicable?(n)
4
+ m = self
5
+ [m.σ, n.σ].all?{|sigma| sigma == m + n - 1}
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ class Integer
2
+ def binomial?(exp=4)
3
+ x = self
4
+ return true if (0..2).include? x
5
+ (2..exp).each do |n|
6
+ (1...x).each do |a|
7
+ an = a**n
8
+ sign, *terms = an > x ? [:-, an, x] : [:+, x, an]
9
+ b = (terms.reduce(:-))**(1.0/n.to_f)
10
+ return true if b.integer? and x == an.send(sign, b**n)
11
+ end
12
+ end
13
+ false
14
+ end
15
+ end
@@ -0,0 +1,73 @@
1
+ describe Integer, "#almost_prime?" do
2
+
3
+ @seq = {
4
+ # A000040
5
+ 1 => [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,
6
+ 61,67,71,73,79,83,89,97,101,103,107,109,113,127,
7
+ 131,137,139,149,151,157,163,167,173,179,181,191,
8
+ 193,197,199,211,223,227,229,233,239,241,251,257,
9
+ 263,269,271],
10
+ # A001358
11
+ 2 => [4,6,9,10,14,15,21,22,25,26,33,34,35,38,39,46,49,
12
+ 51,55,57,58,62,65,69,74,77,82,85,86,87,91,93,94,
13
+ 95,106,111,115,118,119,121,122,123,129,133,134,
14
+ 141,142,143,145,146,155,158,159,161,166,169,177,
15
+ 178,183,185,187],
16
+ # A014612
17
+ 3 => [8,12,18,20,27,28,30,42,44,45,50,52,63,66,68,70,
18
+ 75,76,78,92,98,99,102,105,110,114,116,117,124,125,
19
+ 130,138,147,148,153,154,164,165,170,171,172,174,
20
+ 175,182,186,188,190,195,207,212,222,230,231,236,
21
+ 238,242,244],
22
+ # A014613
23
+ 4 => [16,24,36,40,54,56,60,81,84,88,90,100,104,126,132,
24
+ 135,136,140,150,152,156,184,189,196,198,204,210,
25
+ 220,225,228,232,234,248,250,260,276,294,296,297,
26
+ 306,308,315,328,330,340,342,344,348,350,351,364,
27
+ 372,375,376],
28
+ # A014614
29
+ 5 => [32,48,72,80,108,112,120,162,168,176,180,200,208,
30
+ 243,252,264,270,272,280,300,304,312,368,378,392,
31
+ 396,405,408,420,440,450,456,464,468,496,500,520,
32
+ 552,567,588,592,594,612,616,630,656,660,675,680,
33
+ 684,688,696],
34
+ # A046306
35
+ 6 => [64,96,144,160,216,224,240,324,336,352,360,400,
36
+ 416,486,504,528,540,544,560,600,608,624,729,736,
37
+ 756,784,792,810,816,840,880,900,912,928,936,992,
38
+ 1000,1040,1104,1134,1176,1184,1188,1215,1224,1232,
39
+ 1260,1312,1320],
40
+ # A046308
41
+ 7 => [128,192,288,320,432,448,480,648,672,704,720,800,
42
+ 832,972,1008,1056,1080,1088,1120,1200,1216,1248,
43
+ 1458,1472,1512,1568,1584,1620,1632,1680,1760,1800,
44
+ 1824,1856,1872,1984,2000,2080,2187,2208,2268,2352,
45
+ 2368,2376],
46
+ # A046310
47
+ 8 => [256,384,576,640,864,896,960,1296,1344,1408,1440,
48
+ 1600,1664,1944,2016,2112,2160,2176,2240,2400,2432,
49
+ 2496,2916,2944,3024,3136,3168,3240,3264,3360,3520,
50
+ 3600,3648,3712,3744,3968,4000,4160,4374,4416,4536,
51
+ 4704,4736],
52
+ # A046312
53
+ 9 => [512,768,1152,1280,1728,1792,1920,2592,2688,2816,
54
+ 2880,3200,3328,3888,4032,4224,4320,4352,4480,4800,
55
+ 4864,4992,5832,5888,6048,6272,6336,6480,6528,6720,
56
+ 7040,7200,7296,7424,7488,7936,8000,8320,8748,8832,
57
+ 9072,9408],
58
+ }
59
+
60
+ @seq.each do |k, members|
61
+ members.sample(10).each do |n|
62
+ it "should return true for #{k}-almost-prime #{n}" do
63
+ n.almost_prime?(k).should be_true
64
+ end
65
+ end
66
+
67
+ members.to_seq.invert.sample(10).each do |n|
68
+ it "should return false for non-#{k}-almost-prime #{n}" do
69
+ n.almost_prime?(k).should be_false
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,19 @@
1
+ describe Integer, "#apocalyptic?" do
2
+ # A007356
3
+ @seq = [157,192,218,220,222,224,226,243,245,247,251,278,
4
+ 285,286,287,312,355,361,366,382,384,390,394,411,
5
+ 434,443,478,497,499,506,508,528,529,539,540,541,
6
+ 564,578,580,582,583,610].to_seq
7
+
8
+ @seq.each do |n|
9
+ it "should return true for apocalyptic number #{n}" do
10
+ n.should be_apocalyptic
11
+ end
12
+ end
13
+
14
+ @seq.invert.sample(100).each do |n|
15
+ it "should return false for non-apocalyptic number #{n}" do
16
+ n.should_not be_apocalyptic
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,38 @@
1
+ describe Integer, "#augmented_amicable?" do
2
+
3
+ # A007992, A015630
4
+ @seq = [6160,12220,23500,68908,249424,425500,434784,
5
+ 649990,660825,1017856,1077336,1238380,1252216,
6
+ 1568260,1754536,2166136,2362360,2482536,2537220,
7
+ 2876445,3957525,4177524,4287825,5224660,5559510,
8
+ 5641552].zip(
9
+ [11697,16005,28917,76245,339825,570405,871585,
10
+ 697851,678376,1340865,2067625,1823925,1483785,
11
+ 1899261,2479065,2580105,4895241,4740505,5736445,
12
+ 3171556,4791916,6516237,4416976,7524525,9868075,
13
+ 7589745])
14
+
15
+ @seq.each do |m, n|
16
+ it "should return true for augmented amicable pair (#{m}, #{n})" do
17
+ m.augmented_amicable?(n).should be_true
18
+ end
19
+
20
+ it "should return true for augmented amicable pair (#{n}, #{m})" do
21
+ n.augmented_amicable?(m).should be_true
22
+ end
23
+ end
24
+
25
+ [[234,234], [78982,72101], [13,7], [100019,276281], [1,0]].each do |m, n|
26
+ it "should return false for non-augmented amicable pair (#{m}, #{n})" do
27
+ m.augmented_amicable?(n).should be_false
28
+ end
29
+
30
+ it "should return false for non-augmented amicable pair (#{n}, #{m})" do
31
+ n.augmented_amicable?(m).should be_false
32
+ end
33
+ end
34
+
35
+ it "should return false for amicable but non-augmented pair (220, 284)" do
36
+ 220.augmented_amicable?(284).should be_false
37
+ end
38
+ end
@@ -0,0 +1,20 @@
1
+ describe Integer, "#binomial?" do
2
+ # A079299
3
+ @seq = {
4
+ false => [6,14,22,30,38,42,46,62,66,70,78,86,94,102,110,
5
+ 114,118,134,138,142,150,154,158,166,174,182,186,
6
+ 190,198,206,210,214,222,230,238,246,254,258,262,
7
+ 266,270,278,282,286,294,302,310,318,322,326,330,
8
+ 334,350,354,358].to_seq
9
+ }
10
+ @seq[true] = (0..5).to_a + @seq[false].invert.to_a
11
+
12
+
13
+ @seq.each do |key, members|
14
+ members.sample(10).each do |n|
15
+ it "should return #{key} for #{'non-' unless key}binomial number #{n}" do
16
+ n.binomial?.should == key
17
+ end
18
+ end
19
+ end
20
+ 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.68.0
4
+ version: 0.72.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-01-15 00:00:00 +00:00
12
+ date: 2010-01-17 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -43,10 +43,14 @@ files:
43
43
  - lib/numb/abundant.rb
44
44
  - lib/numb/achilles.rb
45
45
  - lib/numb/almost_perfect.rb
46
+ - lib/numb/almost_prime.rb
46
47
  - lib/numb/amicable.rb
48
+ - lib/numb/apocalyptic.rb
47
49
  - lib/numb/aspiring.rb
50
+ - lib/numb/augmented_amicable.rb
48
51
  - lib/numb/automorphic.rb
49
52
  - lib/numb/balanced_prime.rb
53
+ - lib/numb/binomial.rb
50
54
  - lib/numb/biquadratic.rb
51
55
  - lib/numb/breeder.rb
52
56
  - lib/numb/brown.rb
@@ -163,10 +167,14 @@ files:
163
167
  - spec/abundant_spec.rb
164
168
  - spec/achilles_spec.rb
165
169
  - spec/almost_perfect_spec.rb
170
+ - spec/almost_prime_spec.rb
166
171
  - spec/amicable_spec.rb
172
+ - spec/apocalyptic_spec.rb
167
173
  - spec/aspiring_spec.rb
174
+ - spec/augmented_amicable_spec.rb
168
175
  - spec/automorphic_spec.rb
169
176
  - spec/balanced_prime_spec.rb
177
+ - spec/binomial_spec.rb
170
178
  - spec/biquadratic_spec.rb
171
179
  - spec/breeder_spec.rb
172
180
  - spec/brown_spec.rb
@@ -354,6 +362,7 @@ test_files:
354
362
  - spec/kynea_spec.rb
355
363
  - spec/centered_n_gonal_spec.rb
356
364
  - spec/highly_abundant_spec.rb
365
+ - spec/augmented_amicable_spec.rb
357
366
  - spec/rough_spec.rb
358
367
  - spec/emrip_spec.rb
359
368
  - spec/nth_prime_spec.rb
@@ -410,6 +419,7 @@ test_files:
410
419
  - spec/interprime_spec.rb
411
420
  - spec/number_of_distinct_prime_factors_spec.rb
412
421
  - spec/balanced_prime_spec.rb
422
+ - spec/binomial_spec.rb
413
423
  - spec/digital_sum_spec.rb
414
424
  - spec/brown_spec.rb
415
425
  - spec/factorion_spec.rb
@@ -417,6 +427,7 @@ test_files:
417
427
  - spec/extravagant_spec.rb
418
428
  - spec/self_descriptive_spec.rb
419
429
  - spec/decagonal_spec.rb
430
+ - spec/apocalyptic_spec.rb
420
431
  - spec/kaprekar_spec.rb
421
432
  - spec/hilbert_spec.rb
422
433
  - spec/keith_spec.rb
@@ -424,6 +435,7 @@ test_files:
424
435
  - spec/myriagonal_spec.rb
425
436
  - spec/achilles_spec.rb
426
437
  - spec/coprime_spec.rb
438
+ - spec/almost_prime_spec.rb
427
439
  - spec/pronic_spec.rb
428
440
  - spec/politeness_spec.rb
429
441
  - spec/noncototient_spec.rb