numb 0.138.0 → 0.152.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.
Files changed (55) hide show
  1. data/VERSION +1 -1
  2. data/lib/numb/abundancy.rb +2 -0
  3. data/lib/numb/achain.rb +99 -0
  4. data/lib/numb/almost_perfect.rb +2 -0
  5. data/lib/numb/amicable.rb +2 -4
  6. data/lib/numb/delannoy.rb +1 -0
  7. data/lib/numb/fibonacci.rb +1 -1
  8. data/lib/numb/goldbach.rb +6 -1
  9. data/lib/numb/harshad.rb +3 -2
  10. data/lib/numb/highly_composite.rb +2 -0
  11. data/lib/numb/hoax.rb +7 -0
  12. data/lib/numb/idempotent.rb +6 -0
  13. data/lib/numb/infinitary_divisors.rb +15 -0
  14. data/lib/numb/infinitary_perfect.rb +6 -0
  15. data/lib/numb/integer_p.rb +1 -1
  16. data/lib/numb/knuth.rb +15 -0
  17. data/lib/numb/lah.rb +6 -0
  18. data/lib/numb/motzkin.rb +16 -0
  19. data/lib/numb/multiamicable.rb +7 -0
  20. data/lib/numb/m/303/251nage.rb +23 -0
  21. data/lib/numb/nexus.rb +7 -0
  22. data/lib/numb/nsw.rb +16 -0
  23. data/lib/numb/pandigital.rb +6 -0
  24. data/lib/numb/persistent.rb +6 -0
  25. data/lib/numb/prime_power.rb +6 -0
  26. data/lib/numb/pronic.rb +1 -0
  27. data/lib/numb/square.rb +2 -2
  28. data/lib/numb/sum_of_infinitary_divisors.rb +9 -0
  29. data/lib/numb/superabundant.rb +12 -2
  30. data/lib/numb/vampire.rb +6 -5
  31. data/lib/numb.rb +17 -0
  32. data/spec/numb/achain_spec.rb +39 -0
  33. data/spec/numb/fibonacci_spec.rb +1 -1
  34. data/spec/numb/hoax_spec.rb +21 -0
  35. data/spec/numb/idempotent_spec.rb +59 -0
  36. data/spec/numb/infinitary_divisors_spec.rb +57 -0
  37. data/spec/numb/infinitary_perfect_spec.rb +21 -0
  38. data/spec/numb/integer_p_spec.rb +4 -4
  39. data/spec/numb/knuth_spec.rb +29 -0
  40. data/spec/numb/lah_spec.rb +61 -0
  41. data/spec/numb/motzkin_spec.rb +30 -0
  42. data/spec/numb/multiamicable_spec.rb +26 -0
  43. data/spec/numb/m/303/251nage_spec.rb +31 -0
  44. data/spec/numb/nexus_spec.rb +42 -0
  45. data/spec/numb/nsw_spec.rb +32 -0
  46. data/spec/numb/pandigital_spec.rb +29 -0
  47. data/spec/numb/persistent_spec.rb +44 -0
  48. data/spec/numb/prime_power_spec.rb +66 -0
  49. data/spec/numb/rough_spec.rb +37 -37
  50. data/spec/numb/square_spec.rb +16 -12
  51. data/spec/numb/sum_of_infinitary_divisors_spec.rb +15 -0
  52. data/spec/numb/superabundant_spec.rb +7 -7
  53. data/spec/numb/vampire_spec.rb +11 -11
  54. data/spec/spec_helper.rb +1 -1
  55. metadata +50 -2
@@ -13,15 +13,15 @@ describe Float, "#integer?" do
13
13
  end
14
14
  end
15
15
 
16
- [23.5, 4509.0000001, 2222981011.020].each do |n|
16
+ [23.5, 4509.00001, 2222981011.020].each do |n|
17
17
  it "should return false for float #{n}" do
18
18
  n.should_not be_integer
19
19
  end
20
20
  end
21
21
 
22
- it "ignores digits past the tenth" do
23
- 3.00000000001.should be_integer
22
+ it "ignores digits past the seventh" do
23
+ 3.00000001.should be_integer
24
24
  123.0000000000032.should be_integer
25
- 123.00000000032.should_not be_integer
25
+ 123.000032.should_not be_integer
26
26
  end
27
27
  end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ # A007448
3
+ KNUTH = [1,3,3,4,7,7,7,9,9,10,13,13,13,15,15,19,19,19,19,
4
+ 21,21,22,27,27,27,27,27,28,31,31,31,39,39,39,39,
5
+ 39,39,39,39,40,43,43,43,45,45,46,55,55,55,55,55,
6
+ 55,55,55,55,57,57,58,63,63,63,63,63,64,67,67,67,
7
+ 79,79,79,79]
8
+
9
+ describe Integer, "#knuth?" do
10
+ KNUTH.uniq.each do |n|
11
+ it "returns true for Knuth number #{n}" do
12
+ n.should be_knuth
13
+ end
14
+ end
15
+
16
+ KNUTH.uniq.to_seq.invert.sample(10).each do |n|
17
+ it "returns false for non-Knuth number #{n}" do
18
+ n.should_not be_knuth
19
+ end
20
+ end
21
+ end
22
+
23
+ describe Integer, "#knuth" do
24
+ KNUTH.each_with_index do |k, n|
25
+ it "returns #{k} as the #{n}#{n.ordinal} Knuth number" do
26
+ n.knuth.should == k
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,61 @@
1
+ # coding: utf-8
2
+ describe Integer, "#lah" do
3
+ @seq = {
4
+ # A000142
5
+ 1 => [1,1,2,6,24,120,720,5040,40320,362880,3628800,
6
+ 39916800,479001600,6227020800,87178291200,
7
+ 1307674368000,20922789888000,355687428096000,
8
+ 6402373705728000,121645100408832000,
9
+ 2432902008176640000][1..-1],
10
+ # A001286
11
+ 2 => [1,6,36,240,1800,15120,141120,1451520,16329600,
12
+ 199584000,2634508800,37362124800,566658892800,
13
+ 9153720576000,156920924160000,2845499424768000,
14
+ 54420176498688000,1094805903679488000,
15
+ 23112569077678080000],
16
+ # A001754
17
+ 3 => [0,0,1,12,120,1200,12600,141120,1693440,21772800,
18
+ 299376000,4390848000,68497228800,1133317785600,
19
+ 19833061248000,366148823040000,7113748561920000,
20
+ 145120470663168000,3101950060425216000,
21
+ 69337707233034240000,1617879835437465600000].reject(&:zero?),
22
+ # A001755
23
+ 4 => [1,20,300,4200,58800,846720,12700800,199584000,
24
+ 3293136000,57081024000,1038874636800,
25
+ 19833061248000,396661224960000,8299373322240000,
26
+ 181400588328960000,4135933413900288000,
27
+ 98228418580131840000],
28
+ # A001777
29
+ 5 => [1,30,630,11760,211680,3810240,69854400,
30
+ 1317254400,25686460800,519437318400,
31
+ 10908183686400,237996734976000,5394592659456000,
32
+ 126980411830272000,3101950060425216000,
33
+ 78582734864105472000],
34
+ # A001778
35
+ 6 => [1,42,1176,28224,635040,13970880,307359360,
36
+ 6849722880,155831195520,3636061228800,
37
+ 87265469491200,2157837063782400,55024845126451200,
38
+ 1447576694865100800,39291367432052736000,
39
+ 1100158288097476608000],
40
+ # A111597
41
+ 7 => [1,56,2016,60480,1663200,43908480,1141620480,
42
+ 29682132480,779155977600,20777492736000,
43
+ 565147802419200,15721384321843200,
44
+ 448059453172531200,13097122477350912000,
45
+ 392913674320527360000,12101741169072242688000],
46
+ }
47
+
48
+ @seq.each do |k, values|
49
+ (1...k).each do |n|
50
+ it "returns 0 for Lah(#{n}, #{k})" do
51
+ n.lah(k).should be_zero
52
+ end
53
+ end
54
+
55
+ values.to_enum.with_index(k).each do |lah, n|
56
+ it "returns #{lah} for Lah(#{n}, #{k})" do
57
+ n.lah(k).should == lah
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+
3
+ # A001006
4
+ MOTZKIN = [1,1,2,4,9,21,51,127,323,835,2188,5798,15511,
5
+ 41835,113634,310572,853467,2356779,6536382,
6
+ 18199284,50852019,142547559,400763223,1129760415,
7
+ 3192727797,9043402501,25669818476,73007772802,
8
+ 208023278209,593742784829].first(15)
9
+
10
+ describe Integer, "#motzkin" do
11
+ MOTZKIN.each_with_index.each do |m, n|
12
+ it "returns #{m} for Motzkin number #{n}" do
13
+ n.motzkin.should == m
14
+ end
15
+ end
16
+ end
17
+
18
+ describe Integer, "#motzkin?" do
19
+ MOTZKIN.sample(10).each do |n|
20
+ it "returns true for Motzkin number #{n}" do
21
+ n.should be_motzkin
22
+ end
23
+ end
24
+
25
+ MOTZKIN.to_seq.invert.sample(10).each do |n|
26
+ it "returns false for non-Motzkin number #{n}" do
27
+ n.should_not be_motzkin
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ describe Integer, "#multiamicable?" do
3
+ @seq = [
4
+ [1, 6, 76455288, 183102192],
5
+ [1, 7, 52920, 152280],
6
+ [1, 7, 16225560, 40580280],
7
+ [1, 7, 90863136, 227249568],
8
+ [1, 7, 16225560, 40580280],
9
+ [1, 7, 70821324288, 177124806144],
10
+ [1, 7, 199615613902848, 499240550375424],
11
+ ].first(5)
12
+
13
+ @seq.each do |a, b, m, n|
14
+ it "returns true for multi-amicable numbers #{n} and #{m} (α = #{a}, β = #{b})" do
15
+ n.should be_multiamicable(m, a, b)
16
+ end
17
+ end
18
+
19
+ @seq.each do |a, b, m, n|
20
+ a += 3
21
+ n -= 100
22
+ it "returns false for non-multi-amicable numbers #{n} and #{m} (α = #{a}, β = #{b})" do
23
+ n.should_not be_multiamicable(m, a, b)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ # A000179
3
+ MENAGE = [1,0,0,1,2,13,80,579,4738,43387,439792,4890741,
4
+ 59216642,775596313,10927434464,164806435783,
5
+ 2649391469058,45226435601207,817056406224416,
6
+ 15574618910994665,312400218671253762,
7
+ 6577618644576902053]
8
+
9
+ describe Integer, "#ménage" do
10
+ MENAGE.first(20).each_with_index do |m, n|
11
+ it "returns #{m} for ménage number #{n}" do
12
+ n.ménage.should == m
13
+ end
14
+ end
15
+ end
16
+
17
+ describe Integer, "#ménage" do
18
+ @seq = MENAGE.uniq.first(15)
19
+
20
+ @seq.each do |n|
21
+ it "returns true for ménage number #{n}" do
22
+ n.should be_ménage
23
+ end
24
+ end
25
+
26
+ @seq.to_seq.invert.sample(10).each do |n|
27
+ it "returns false for non-ménage number #{n}" do
28
+ n.should_not be_ménage
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ describe Integer, "#nexus" do
3
+ @seq = {
4
+ 0 => [1] * 60,
5
+ # A005408
6
+ 1 => [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,
7
+ 37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,
8
+ 69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99,
9
+ 101,103,105,107,109,111,113,115,117,119,121,123,
10
+ 125,127,129,131],
11
+ # A003215
12
+ 2 => [1,7,19,37,61,91,127,169,217,271,331,397,469,547,
13
+ 631,721,817,919,1027,1141,1261,1387,1519,1657,
14
+ 1801,1951,2107,2269,2437,2611,2791,2977,3169,3367,
15
+ 3571,3781,3997,4219,4447,4681,4921,5167,5419,5677,
16
+ 5941,6211,6487],
17
+ # A005917
18
+ 3 => [1,15,65,175,369,671,1105,1695,2465,3439,4641,
19
+ 6095,7825,9855,12209,14911,17985,21455,25345,
20
+ 29679,34481,39775,45585,51935,58849,66351,74465,
21
+ 83215,92625,102719,113521,125055,137345,150415,
22
+ 164289,178991],
23
+ # A022521
24
+ 4 => [1,31,211,781,2101,4651,9031,15961,26281,40951,
25
+ 61051,87781,122461,166531,221551,289201,371281,
26
+ 469711,586531,723901,884101,1069531,1282711,
27
+ 1526281,1803001,2115751,2467531],
28
+ # A022522
29
+ 5 => [1,63,665,3367,11529,31031,70993,144495,269297,
30
+ 468559,771561,1214423,1840825,2702727,3861089,
31
+ 5386591,7360353,9874655,13033657,16954119,
32
+ 21766121,27613783,34655985,43067087]
33
+ }
34
+
35
+ @seq.each do |d, values|
36
+ values.each_with_index do |nexus, n|
37
+ it "returns #{nexus} for #{n}" do
38
+ n.nexus(d).should == nexus
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+
3
+ # A002315
4
+ NSW = [1,7,41,239,1393,8119,47321,275807,1607521,
5
+ 9369319,54608393,318281039,1855077841,10812186007,
6
+ 63018038201,367296043199,2140758220993,
7
+ 12477253282759,72722761475561,423859315570607,
8
+ 2470433131948081]
9
+
10
+ describe Integer, "#nsw" do
11
+ NSW.each_with_index do |nsw, n|
12
+ it "returns #{nsw} as the #{n}#{n.ordinal} NSW number" do
13
+ n.nsw.should == nsw
14
+ end
15
+ end
16
+ end
17
+
18
+ describe Integer, "#nsw?" do
19
+ @seq = NSW
20
+
21
+ @seq.each do |n|
22
+ it "returns true for NSW number #{n}" do
23
+ n.should be_nsw
24
+ end
25
+ end
26
+
27
+ @seq.to_seq.invert.sample(100).each do |n|
28
+ it "returns false for non-NSW number #{n}" do
29
+ n.should_not be_nsw
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ describe Integer, "#pandigital?" do
3
+ # A050278
4
+ @seq = [1023456789,1023456798,1023456879,1023456897,
5
+ 1023456978,1023456987,1023457689,1023457698,
6
+ 1023457869,1023457896,1023457968,1023457986,
7
+ 1023458679,1023458697,1023458769,1023458796,
8
+ 1023458967,1023458976]
9
+ @seq.each do |n|
10
+ it "returns true for pandigital number #{n}" do
11
+ n.should be_pandigital
12
+ end
13
+ end
14
+
15
+ # A050289
16
+ [123456789,123456798,123456879,123456897,123456978,123456987,123457689,
17
+ 123457698,123457869,123457896,123457968,123457986,123458679,123458697,
18
+ 123458769,123458796,123458967,123458976].each do |n|
19
+ it "returns false for zeroless pandigital number #{n}" do
20
+ n.should_not be_pandigital
21
+ end
22
+ end
23
+
24
+ [19, 123456780, 987653211, 474839302029273675, 100000001, 34, 334455].each do |n|
25
+ it "returns false for non-pandigital number #{n}" do
26
+ n.should_not be_pandigital
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+ describe Integer, "#persistent?" do
3
+
4
+ @seq = {
5
+ # A051264
6
+ 1 => [1023456798,1023456897,1023456978,1023456987,
7
+ 1023457698,1023457896,1023457968,1023457986,
8
+ 1023458697,1023458796,1023458967,1023458976,
9
+ 1023459678,1023459687,1023459768,1023459786,
10
+ 1023459867,1023459876],
11
+ # A051018
12
+ 2 => [1023456789,1023456879,1023457689,1023457869,
13
+ 1023458679,1023458769,1023465789,1023465879,
14
+ 1023467589,1023467859,1023468579,1023468759,
15
+ 1023475689,1023475869,1023476589,1023476859,
16
+ 1023478569,1023478659],
17
+ # A051019
18
+ 3 => [1052674893,1052687493,1052746893,1052748693,
19
+ 1052867493,1052874693,1053267489,1053268749,
20
+ 1053274869,1053286749,1053287469,1065273489,
21
+ 1065287349,1067285493,1067328549,1068547293,
22
+ 1068547329,1068549273],
23
+ # A051020
24
+ 4 => [1253094867,1267085493,1268547309,1269085473,
25
+ 1273085469,1308547269,1308549267,1326854907,
26
+ 1327068549,1328746905,1450687329,1450732869,
27
+ 1450867293,1450928673,1452687309,1452690873,
28
+ 1452730869,1453087269],
29
+ }
30
+
31
+ @seq.each do |n,ks|
32
+ ks.each do |k|
33
+ it "returns true for #{n}-persistent number #{k}" do
34
+ k.should be_persistent(n)
35
+ end
36
+ end
37
+
38
+ ks.to_seq.invert.sample(20).each do |k|
39
+ it "returns false for non-#{n}-persistent number #{k}" do
40
+ k.should_not be_persistent(n)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,66 @@
1
+ # coding: utf-8
2
+ describe Integer, "#prime_power?" do
3
+ @seq = {
4
+ # A000961
5
+ 0 => [1,2,3,4,5,7,8,9,11,13,16,17,19,23,25,27,29,31,32,
6
+ 37,41,43,47,49,53,59,61,64,67,71,73,79,81,83,89,
7
+ 97,101,103,107,109,113,121,125,127,128,131,137,
8
+ 139,149,151,157,163,167,169,173,179,181,191,193,
9
+ 197,199,211,223,227],
10
+ # A000040
11
+ 1 => [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,
12
+ 61,67,71,73,79,83,89,97,101,103,107,109,113,127,
13
+ 131,137,139,149,151,157,163,167,173,179,181,191,
14
+ 193,197,199,211,223,227,229,233,239,241,251,257,
15
+ 263,269,271],
16
+ # A001248
17
+ 2 => [4,9,25,49,121,169,289,361,529,841,961,1369,1681,
18
+ 1849,2209,2809,3481,3721,4489,5041,5329,6241,6889,
19
+ 7921,9409,10201,10609,11449,11881,12769,16129,
20
+ 17161,18769,19321,22201],
21
+ # A030078
22
+ 3 => [8,27,125,343,1331,2197,4913,6859,12167,24389,
23
+ 29791,50653,68921,79507,103823,148877,205379,
24
+ 226981,300763,357911,389017,493039,571787,704969,
25
+ 912673,1030301,1092727,1225043,1295029,1442897],
26
+ # A030514
27
+ 4 => [16,81,625,2401,14641,28561,83521,130321,279841,
28
+ 707281,923521,1874161,2825761,3418801,4879681,
29
+ 7890481,12117361,13845841,20151121,25411681,
30
+ 28398241,38950081,47458321,62742241,88529281,
31
+ 104060401],
32
+ 5 => [32,243,3125,16807,161051,371293,1419857,2476099,
33
+ 6436343,20511149,28629151,69343957,115856201,
34
+ 147008443,229345007,418195493,714924299,844596301,
35
+ 1350125107,1804229351,2073071593,3077056399,
36
+ 3939040643],
37
+ }
38
+
39
+ @seq[0].each do |n|
40
+ it "returns true for prime-power #{n}" do
41
+ n.should be_prime_power
42
+ end
43
+ end
44
+
45
+ @seq[0].to_seq.invert.sample(10).each do |n|
46
+ it "returns false for non-prime-power #{n}" do
47
+ n.should_not be_prime_power
48
+ end
49
+ end
50
+
51
+ @seq.each do |k, values|
52
+ next if k.zero?
53
+
54
+ values.each do |n|
55
+ it "returns true for #{k}#{k.ordinal}-prime-power #{n}" do
56
+ n.should be_prime_power(k)
57
+ end
58
+ end
59
+
60
+ values.to_seq.invert.sample(10).each do |n|
61
+ it "returns false for non-#{k}#{k.ordinal}-prime-power #{n}" do
62
+ n.should_not be_prime_power(k)
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,48 +1,48 @@
1
+ # coding: utf-8
1
2
  describe Integer, "#rough?" do
2
-
3
- ROUGH = {
3
+ @seq = {
4
4
  # A000027
5
- 2 => [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
6
- 20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,
7
- 36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,
8
- 52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,
9
- 68,69,70,71,72,73,74,75,76,77],
10
- # A005408
11
- 3 => [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,
12
- 37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,
13
- 69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99,
14
- 101,103,105,107,109,111,113,115,117,119,121,123,
15
- 125,127,129,131],
5
+ 2 => [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
6
+ 20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,
7
+ 36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,
8
+ 52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,
9
+ 68,69,70,71,72,73,74,75,76,77],
10
+ # A005408
11
+ 3 => [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,
12
+ 37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,
13
+ 69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99,
14
+ 101,103,105,107,109,111,113,115,117,119,121,123,
15
+ 125,127,129,131],
16
16
  # A007310
17
- 5 => [1,5,7,11,13,17,19,23,25,29,31,35,37,41,43,47,49,
18
- 53,55,59,61,65,67,71,73,77,79,83,85,89,91,95,97,
19
- 101,103,107,109,113,115,119,121,125,127,131,133,
20
- 137,139,143,145,149],
17
+ 5 => [1,5,7,11,13,17,19,23,25,29,31,35,37,41,43,47,49,
18
+ 53,55,59,61,65,67,71,73,77,79,83,85,89,91,95,97,
19
+ 101,103,107,109,113,115,119,121,125,127,131,133,
20
+ 137,139,143,145,149],
21
21
  # A007775
22
- 7 => [1,7,11,13,17,19,23,29,31,37,41,43,47,49,53,59,61,
23
- 67,71,73,77,79,83,89,91,97,101,103,107,109,113,
24
- 119,121,127,131,133,137,139,143,149,151,157,161,
25
- 163,167,169,173,179,181,187,191,193,197,199,203,
26
- 209],
27
- # A008364
22
+ 7 => [1,7,11,13,17,19,23,29,31,37,41,43,47,49,53,59,61,
23
+ 67,71,73,77,79,83,89,91,97,101,103,107,109,113,
24
+ 119,121,127,131,133,137,139,143,149,151,157,161,
25
+ 163,167,169,173,179,181,187,191,193,197,199,203,
26
+ 209],
27
+ # A008364
28
28
  11 => [1,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,
29
29
  71,73,79,83,89,97,101,103,107,109,113,121,127,131,
30
30
  137,139,143,149,151,157,163,167,169,173,179,181,
31
31
  187,191,193,197,199,209,211,221,223,227,229,233,
32
32
  239,241,247],
33
- # A008365
33
+ # A008365
34
34
  13 => [1,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,
35
35
  73,79,83,89,97,101,103,107,109,113,127,131,137,
36
36
  139,149,151,157,163,167,169,173,179,181,191,193,
37
37
  197,199,211,221,223,227,229,233,239,241,247,251,
38
38
  257,263,269],
39
- # A008366
39
+ # A008366
40
40
  17 => [1,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,
41
41
  79,83,89,97,101,103,107,109,113,127,131,137,139,
42
42
  149,151,157,163,167,173,179,181,191,193,197,199,
43
43
  211,223,227,229,233,239,241,251,257,263,269,271,
44
44
  277,281,283],
45
- # A166061
45
+ # A166061
46
46
  19 => [1,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,
47
47
  83,89,97,101,103,107,109,113,127,131,137,139,149,
48
48
  151,157,163,167,173,179,181,191,193,197,199,211,
@@ -51,19 +51,19 @@ describe Integer, "#rough?" do
51
51
  23 => [1,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,
52
52
  89,97,101,103,107,109,113,127,131,137,139,149,151,
53
53
  157,163,167,173,179,181,191,193,197,199,211,223,
54
- 227,229,233,239,241,251,257,263,269,271]
54
+ 227,229,233,239,241,251,257,263,269,271],
55
55
  }
56
56
 
57
- ROUGH.each do |base, members|
58
- (members.first..members.last).each do |n|
59
- if members.include?(n)
60
- it "should return true for rough number #{n} when k=#{base}" do
61
- n.rough?(base).should be_true
62
- end
63
- else
64
- it "should return false for non-rough number #{n} when k=#{base}" do
65
- n.rough?(base).should be_false
66
- end
57
+ @seq.each do |k, values|
58
+ values.each do |n|
59
+ it "returns true for #{k}-rough number #{n}" do
60
+ n.should be_rough(k)
61
+ end
62
+ end
63
+
64
+ values.to_seq.invert.sample(5).each do |n|
65
+ it "returns false for non-#{k}-rough number #{n}" do
66
+ n.should_not be_rough(k)
67
67
  end
68
68
  end
69
69
  end
@@ -1,24 +1,28 @@
1
1
  describe Integer, "#square?" do
2
- SQUARES = [0,1,4,9,16,25,36,49,64,81,100,121,144,169,196,
3
- 225,256,289,324,361,400,441,484,529,576,625,676,
4
- 729,784,841,900,961,1024,1089,1156,1225,1296,1369,
5
- 1444,1521,1600,1681,1764,1849]
2
+ @seq = [0,1,4,9,16,25,36,49,64,81,100,121,144,169,196,
3
+ 225,256,289,324,361,400,441,484,529,576,625,676,
4
+ 729,784,841,900,961,1024,1089,1156,1225,1296,1369,
5
+ 1444,1521,1600,1681,1764,1849]
6
6
 
7
- it "returns true if the number is square" do
8
- SQUARES.each do |number|
9
- number.should be_square
7
+ @seq.each do |n|
8
+ it "returns true for square number #{n}" do
9
+ n.should be_square
10
10
  end
11
11
  end
12
12
 
13
- it "returns false if the number isn't square" do
14
- ((1..1850).to_a - SQUARES).each do |number|
15
- number.should_not be_square
13
+ @seq.to_seq.invert.each do |n|
14
+ it "returns false for non-square number #{n}" do
15
+ n.should_not be_square
16
16
  end
17
17
  end
18
18
 
19
19
  it "returns false for negative numbers" do
20
- [-1, -378, -9].each do |number|
21
- number.should_not be_square
20
+ [-1, -378, -9].each do |n|
21
+ n.should_not be_square
22
22
  end
23
23
  end
24
+
25
+ it "returns nil when the square root is infinite" do
26
+ 9999999880000000359859986946294623781838875946012712893365986548632235701967954558670969253503997913415008896487205684793069342787691170258832794954572186327945677037037154860793120217960493002317298159645342431034751955276791509386257991014312642060444444445753597283950617283950617283950617283950617283950617283950617283950617283950617284297678218281.square?.should be_nil
27
+ end
24
28
  end
@@ -0,0 +1,15 @@
1
+ # coding: utf-8
2
+ describe Integer, "#σ∞" do
3
+ # A049417
4
+ @seq = [1,3,4,5,6,12,8,15,10,18,12,20,14,24,24,17,18,30,
5
+ 20,30,32,36,24,60,26,42,40,40,30,72,32,51,48,54,
6
+ 48,50,38,60,56,90,42,96,44,60,60,72,48,68,50,78,
7
+ 72,70,54,120,72,120,80,90,60,120,62,96,80,85,84,
8
+ 144,68,90]
9
+
10
+ @seq.to_enum.with_index(1).each do |sum, n|
11
+ it "returns #{sum} for #{n}" do
12
+ n.σ∞.should == sum
13
+ end
14
+ end
15
+ end
@@ -1,18 +1,18 @@
1
1
  describe Integer, "#superabundant?" do
2
2
  # A004394
3
- SUPERABUNDANT = [1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,
4
- 1260,1680,2520,5040,10080,15120,25200,27720,55440,
5
- 110880,166320,277200,332640,554400,665280,720720,
6
- 1441440,2162160,3603600,4324320,7207200,8648640,
7
- 10810800]
3
+ @seq = [1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,
4
+ 1260,1680,2520,5040,10080,15120,25200,27720,55440,
5
+ 110880,166320,277200,332640,554400,665280,720720,
6
+ 1441440,2162160,3603600,4324320,7207200,8648640,
7
+ 10810800].first(17)
8
8
 
9
- SUPERABUNDANT.first(20).each do |n|
9
+ @seq.each do |n|
10
10
  it "should return true for superabundant number #{n}" do
11
11
  n.should be_superabundant
12
12
  end
13
13
  end
14
14
 
15
- ((1..SUPERABUNDANT.last).first(20) - SUPERABUNDANT).each do |n|
15
+ @seq.to_seq.invert.sample(20).each do |n|
16
16
  it "should return false for non-superabundant number #{n}" do
17
17
  n.should_not be_superabundant
18
18
  end
@@ -1,19 +1,19 @@
1
1
  describe Integer, "#vampire?" do
2
- # http://www.research.att.com/~njas/sequences/A014575
3
- VAMPIRE = [1260,1395,1435,1530,1827,2187,6880,102510,104260,
4
- 105210,105264,105750,108135,110758,115672,116725,
5
- 117067,118440,120600,123354,124483,125248,125433,
6
- 125460,125500,126027,126846,129640]
2
+ #A014575
3
+ @seq = [1260,1395,1435,1530,1827,2187,6880,102510,104260,
4
+ 105210,105264,105750,108135,110758,115672,116725,
5
+ 117067,118440,120600,123354,124483,125248,125433,
6
+ 125460,125500,126027,126846,129640]
7
7
 
8
- it "returns true for vampire numbers" do
9
- VAMPIRE.each do |number|
10
- number.should be_vampire
8
+ @seq.each do |n|
9
+ it "returns true for vampire number #{n}" do
10
+ n.should be_vampire
11
11
  end
12
12
  end
13
13
 
14
- it "returns false for non-vampire numbers" do
15
- [1259,22,1396].each do |number|
16
- number.should_not be_vampire
14
+ @seq.to_seq.invert.sample(10).each do |n|
15
+ it "returns false for non-vampire number #{n}" do
16
+ n.should_not be_vampire
17
17
  end
18
18
  end
19
19
  end
data/spec/spec_helper.rb CHANGED
@@ -25,7 +25,7 @@ class Seq
25
25
  end
26
26
 
27
27
  def invert
28
- return [] if @include.size < 2
28
+ return [] if @include.size < 2 or @include.size == self.end.succ - self.begin
29
29
  Seq.new(self.begin..self.end).tap{|s| s.exclude = @include }
30
30
  end
31
31