numb 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +10 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/lib/numb/abundant.rb +20 -0
- data/lib/numb/achilles.rb +15 -0
- data/lib/numb/automorphic.rb +24 -0
- data/lib/numb/carol.rb +21 -0
- data/lib/numb/deficient.rb +19 -0
- data/lib/numb/dihedral_prime.rb +25 -0
- data/lib/numb/dudeney.rb +15 -0
- data/lib/numb/economical.rb +16 -0
- data/lib/numb/emrip.rb +17 -0
- data/lib/numb/equidigital.rb +18 -0
- data/lib/numb/extravagant.rb +18 -0
- data/lib/numb/factorion.rb +15 -0
- data/lib/numb/frugal.rb +16 -0
- data/lib/numb/happy.rb +15 -0
- data/lib/numb/harshad.rb +8 -0
- data/lib/numb/hilbert.rb +7 -0
- data/lib/numb/hyperperfect.rb +7 -0
- data/lib/numb/impolite.rb +6 -0
- data/lib/numb/kaprekar.rb +14 -0
- data/lib/numb/keith.rb +15 -0
- data/lib/numb/kynea.rb +9 -0
- data/lib/numb/mms_pair.rb +11 -0
- data/lib/numb/mobius.rb +11 -0
- data/lib/numb/narcissistic.rb +8 -0
- data/lib/numb/nivenmorphic.rb +9 -0
- data/lib/numb/ordinal.rb +11 -0
- data/lib/numb/parasitic.rb +10 -0
- data/lib/numb/perfect.rb +10 -0
- data/lib/numb/perfect_power.rb +9 -0
- data/lib/numb/polite.rb +7 -0
- data/lib/numb/polydivisible.rb +10 -0
- data/lib/numb/powerful.rb +8 -0
- data/lib/numb/practical.rb +26 -0
- data/lib/numb/prime.rb +495 -0
- data/lib/numb/ruby1.8.rb +9 -0
- data/lib/numb/ruby1.9.rb +8 -0
- data/lib/numb/self.rb +13 -0
- data/lib/numb/self_descriptive.rb +9 -0
- data/lib/numb/semi_perfect.rb +15 -0
- data/lib/numb/semiprime.rb +6 -0
- data/lib/numb/smarandache_wellin.rb +11 -0
- data/lib/numb/smith.rb +7 -0
- data/lib/numb/sphenic.rb +8 -0
- data/lib/numb/square.rb +8 -0
- data/lib/numb/square_free.rb +6 -0
- data/lib/numb/triangular.rb +8 -0
- data/lib/numb/trimorphic.rb +6 -0
- data/lib/numb/undulating.rb +11 -0
- data/lib/numb/vampire.rb +11 -0
- data/lib/numb/weird.rb +8 -0
- data/lib/numb.rb +80 -0
- data/numb.gemspec +201 -0
- data/spec/abundant_spec.rb +24 -0
- data/spec/achilles_spec.rb +24 -0
- data/spec/automorphic_spec.rb +208 -0
- data/spec/carol_spec.rb +18 -0
- data/spec/deficient_spec.rb +23 -0
- data/spec/digital_sum_spec.rb +8 -0
- data/spec/dihedral_prime_spec.rb +38 -0
- data/spec/dudeney_spec.rb +14 -0
- data/spec/economical_spec.rb +28 -0
- data/spec/emrip_spec.rb +26 -0
- data/spec/equidigital_spec.rb +27 -0
- data/spec/extravagant_spec.rb +20 -0
- data/spec/factor_spec.rb +22 -0
- data/spec/factorion_spec.rb +13 -0
- data/spec/frugal_spec.rb +20 -0
- data/spec/happy_spec.rb +24 -0
- data/spec/harshad_spec.rb +25 -0
- data/spec/hilbert_spec.rb +24 -0
- data/spec/hyperperfect_spec.rb +59 -0
- data/spec/kaprekar_spec.rb +25 -0
- data/spec/keith_spec.rb +21 -0
- data/spec/kynea_spec.rb +19 -0
- data/spec/maris_mcgwire_sosa_pair_spec.rb +20 -0
- data/spec/mobius_spec.rb +52 -0
- data/spec/narcissistic_spec.rb +18 -0
- data/spec/nivenmorphic_spec.rb +24 -0
- data/spec/number_of_distinct_prime_factors_spec.rb +35 -0
- data/spec/number_of_prime_factors_spec.rb +32 -0
- data/spec/ordinal_spec.rb +64 -0
- data/spec/parasitic_spec.rb +29 -0
- data/spec/perfect_power_spec.rb +24 -0
- data/spec/perfect_spec.rb +103 -0
- data/spec/polite_spec.rb +14 -0
- data/spec/politeness_spec.rb +11 -0
- data/spec/polydivisible_spec.rb +19 -0
- data/spec/powerful_spec.rb +25 -0
- data/spec/practical_spec.rb +30 -0
- data/spec/self_descriptive_spec.rb +19 -0
- data/spec/self_spec.rb +20 -0
- data/spec/semi_perfect_spec.rb +24 -0
- data/spec/semiprime_spec.rb +21 -0
- data/spec/smarandache_wellin_spec.rb +26 -0
- data/spec/smith_spec.rb +19 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/sphenic_spec.rb +20 -0
- data/spec/square_free_spec.rb +19 -0
- data/spec/square_spec.rb +24 -0
- data/spec/triangular_spec.rb +19 -0
- data/spec/trimorphic_spec.rb +25 -0
- data/spec/undulating_spec.rb +20 -0
- data/spec/vampire_spec.rb +19 -0
- data/spec/weird_spec.rb +24 -0
- metadata +216 -0
@@ -0,0 +1,103 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Integer, "#perfect?" do
|
4
|
+
it "returns true for the first 7 perfect numbers" do
|
5
|
+
[6, 28, 496, 8128, 33550336, 8589869056, 137438691328].each do |n|
|
6
|
+
n.perfect?.should be_true
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns false for the neighbours of the first 7 perfect numbers" do
|
11
|
+
[6, 28, 496, 8128, 33550336, 8589869056, 137438691328].each do |n|
|
12
|
+
(n+1).perfect?.should be_false
|
13
|
+
(n-1).perfect?.should be_false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns false for odd integers" do
|
18
|
+
[29,31,33,35].each do |n|
|
19
|
+
n.perfect?.should be_false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns false for 1" do
|
24
|
+
1.perfect?.should be_false
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns false for 0" do
|
28
|
+
0.perfect?.should be_false
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns false for -1" do
|
32
|
+
-1.perfect?.should be_false
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns false for non-perfect positive integers" do
|
36
|
+
[8, 66, 3478].each do |n|
|
37
|
+
n.perfect?.should be_false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns false for negative integers" do
|
42
|
+
-6.perfect?.should be_false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe Integer, "#proper_positive_divisors" do
|
47
|
+
it "returns an Array" do
|
48
|
+
6.proper_positive_divisors.should be_an_instance_of(Array)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns integers that divide into self with no remainder" do
|
52
|
+
6.proper_positive_divisors.should include(2, 3)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "doesn't return integers that divide into self with a remainder" do
|
56
|
+
6.proper_positive_divisors.should_not include(4, 5)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "doesn't return itself as a divisor" do
|
60
|
+
9.proper_positive_divisors.should_not include(9)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns all of the proper divisors of self" do
|
64
|
+
33.proper_positive_divisors.sort.should == [1, 3, 11]
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns [] for 1" do
|
68
|
+
1.proper_positive_divisors.should == []
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns [] for 0" do
|
72
|
+
0.proper_positive_divisors.should == []
|
73
|
+
end
|
74
|
+
|
75
|
+
it "returns [] for -1" do
|
76
|
+
-1.proper_positive_divisors.should == []
|
77
|
+
end
|
78
|
+
|
79
|
+
it "returns [] when self is negative" do
|
80
|
+
-32.proper_positive_divisors.should == []
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe Integer, "#digital_root" do
|
85
|
+
it "returns each single-digit number as is" do
|
86
|
+
(0..9).each do |n|
|
87
|
+
n.digital_root.should == n
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it "returns the sum of the digits of multi-digit numbers" do
|
92
|
+
18.digital_root.should == 9
|
93
|
+
end
|
94
|
+
|
95
|
+
it "returns a single digit even when the sum of the digits is greater than 9" do
|
96
|
+
65536.digital_root.should == 7
|
97
|
+
end
|
98
|
+
|
99
|
+
it "works for negative numbers" do
|
100
|
+
-4.digital_root.should == 5
|
101
|
+
-99.digital_root.should == 9
|
102
|
+
end
|
103
|
+
end
|
data/spec/polite_spec.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
describe Integer, "#polite?" do
|
2
|
+
it "returns true for polite numbers" do
|
3
|
+
[1,3,5,6,7,9,10,11,12,13,14,15,17,18,19,20,21,22,
|
4
|
+
23,24,25,26,27,28,29,30,31,33,34,35,36,37,38,39,40].each do |polite|
|
5
|
+
polite.should be_polite
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns false for impolite numbers" do
|
10
|
+
[2,4,8,16,32].each do |impolite|
|
11
|
+
impolite.should_not be_polite
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
describe Integer, "#politeness" do
|
2
|
+
it "returns number of non-trivial ways to write n as the sum of >= 2 consecutive integers" do
|
3
|
+
[0,0,0,1,0,1,1,1,0,2,1,1,1,1,1,3,0,1,2,1,1,3,1,1,
|
4
|
+
1,2,1,3,1,1,3,1,0,3,1,3,2,1,1,3,1,1,3,1,1,5,1,1,1,
|
5
|
+
2,2,3,1,1,3,3,1,3,1,1,3,1,1,5,0,3,3,1,1,3,3,1,2,1,
|
6
|
+
1,5,1,3,3,1,1,4,1,1,3,3,1,3,1,1,5,3,1,3,1,3,1,1,2,
|
7
|
+
5,2].each_with_index do |politeness, number|
|
8
|
+
number.politeness.should == politeness
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe Integer, "#polydivisible?" do
|
2
|
+
# http://www.research.att.com/~njas/sequences/A078282
|
3
|
+
POLYDIVISIBLE = [1,10,102,1020,10200,102000,1020005,10200056,
|
4
|
+
102000564,1020005640,10200056405,3608528850368400786036725,
|
5
|
+
48000688208466084040,30000600003, 381654729]
|
6
|
+
|
7
|
+
it "returns true for polydivisible numbers" do
|
8
|
+
POLYDIVISIBLE.each do |number|
|
9
|
+
number.should be_polydivisible
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns false for non-polydivisible numbers" do
|
14
|
+
[123456, 2020, 102001].each do |number|
|
15
|
+
number.should_not be_polydivisible
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
describe Integer, "#powerful?" do
|
2
|
+
POWERFUL = [1,4,8,9,16,25,27,32,36,49,64,72,81,100,108,121,
|
3
|
+
125,128,144,169,196,200,216,225,243,256,288,289,
|
4
|
+
324,343,361,392,400,432,441,484,500,512,529,576,
|
5
|
+
625,648,675,676,729,784,800,841,864,900,961,968,
|
6
|
+
972,1000]
|
7
|
+
it "returns true for a powerful number" do
|
8
|
+
POWERFUL.each do |number|
|
9
|
+
number.should be_powerful
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns false for a non-powerful number" do
|
14
|
+
((1..999).to_a - POWERFUL).sample(10).each do |number|
|
15
|
+
number.should_not be_powerful
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns false for a negative number" do
|
20
|
+
(1..999).each do |number|
|
21
|
+
(-number).should_not be_powerful
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
describe Integer, "#practical?" do
|
2
|
+
PRACTICAL =[1,2,4,6,8,12,16,18,20,24,28,30,32,36,40,42,48,54,
|
3
|
+
56,60,64,66,72,78,80,84,88,90,96,100,104,108,112,
|
4
|
+
120,126,128,132,140,144,150,156,160,162,168,176,
|
5
|
+
180,192,196,198,200,204,208,210,216,220,224,228,
|
6
|
+
234,240,252]
|
7
|
+
it "returns true for any practical number" do
|
8
|
+
PRACTICAL.each do |number|
|
9
|
+
number.should be_practical
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns false for any non-practical number" do
|
14
|
+
((1..252).to_a - PRACTICAL).each do |number|
|
15
|
+
number.should_not be_practical
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns true for powers of two" do
|
20
|
+
[38, 41, 2, 5].each do |pow|
|
21
|
+
(2 ** pow).should be_practical
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns true for perfect numbers" do
|
26
|
+
[6, 28, 496, 8128, 33550336, 8589869056, 137438691328].each do |n|
|
27
|
+
n.should be_practical
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe Integer, "#self_descriptive?" do
|
2
|
+
SELF_DESCRIPTIVE = [nil,nil,nil,nil,1210,21200,nil,
|
3
|
+
3211000,42101000,521001000,6210001000]
|
4
|
+
|
5
|
+
SELF_DESCRIPTIVE.each_with_index do |number, base|
|
6
|
+
next if number.nil?
|
7
|
+
it "returns true if the number is self-descriptive in base #{base}" do
|
8
|
+
number.self_descriptive?(base).should be_true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
[21,101,2345,26871,112200,1723492,
|
13
|
+
66287620,112276826,2386520171].each do |number|
|
14
|
+
base = number.digits.size
|
15
|
+
it "returns false if the number isn't self-descriptive in base #{base}" do
|
16
|
+
number.to_s(base).to_i.self_descriptive?(base).should be_false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/self_spec.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
describe Integer, "#self?" do
|
2
|
+
SELF = [1,3,5,7,9,20,31,42,53,64,75,86,97,108,110,121,
|
3
|
+
132,143,154,165,176,187,198,209,211,222,233,244,
|
4
|
+
255,266,277,288,299,310,312,323,334,345,356,367,
|
5
|
+
378,389,400,411,413,424,435,446,457,468,479,490,
|
6
|
+
501,512,514,525]
|
7
|
+
|
8
|
+
it "returns true for self numbers" do
|
9
|
+
SELF.each do |number|
|
10
|
+
number.should be_self
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns false for non-self numbers" do
|
15
|
+
((1..200).to_a - SELF).each do |number|
|
16
|
+
number.should_not be_self
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
describe Integer, "#semi_perfect?" do
|
2
|
+
SEMI_PERFECT = [6,12,18,20,24,28,30,36,40,42,48,54,56,60,66,72,
|
3
|
+
78,80,84,88,90,96,100,102,104,108,112,114,120,126,
|
4
|
+
132,138,140,144,150,156,160,162,168,174,176,180,
|
5
|
+
186,192,196,198,200,204,208,210,216,220,222,224,
|
6
|
+
228,234,240,246,252,258,260,264]
|
7
|
+
it "returns true if the number is semi-perfect" do
|
8
|
+
SEMI_PERFECT.each do |number|
|
9
|
+
number.should be_semi_perfect
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns false if the number is not semi-perfect" do
|
14
|
+
((1..263).to_a - SEMI_PERFECT).each do |number|
|
15
|
+
number.should_not be_semi_perfect
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns false if the number is negative" do
|
20
|
+
(1..263).each do |number|
|
21
|
+
(-number).should_not be_semi_perfect
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
describe Integer, "#semiprime?" do
|
2
|
+
# http://www.research.att.com/~njas/sequences/A001358
|
3
|
+
SEMI_PRIME = [4,6,9,10,14,15,21,22,25,26,33,34,35,38,39,46,49,
|
4
|
+
51,55,57,58,62,65,69,74,77,82,85,86,87,91,93,94,
|
5
|
+
95,106,111,115,118,119,121,122,123,129,133,134,
|
6
|
+
141,142,143,145,146,155,158,159,161,166,169,177,
|
7
|
+
178,183,185,187]
|
8
|
+
|
9
|
+
it "returns true for semi-prime numbers" do
|
10
|
+
SEMI_PRIME.each do |number|
|
11
|
+
number.should be_semiprime
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns false for non-semi-prime numbers" do
|
16
|
+
((1..187).to_a - SEMI_PRIME).each do |number|
|
17
|
+
number.should_not be_semiprime
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
describe Integer, "#smarandache-wellin?" do
|
2
|
+
# http://www.research.att.com/~njas/sequences/A019518
|
3
|
+
SMARANDACHE_WELLIN = [2,23,235,2357,235711,23571113,2357111317,
|
4
|
+
235711131719,23571113171923,2357111317192329,
|
5
|
+
235711131719232931,23571113171923293137,
|
6
|
+
2357111317192329313741,235711131719232931374143,
|
7
|
+
23571113171923293137414347]
|
8
|
+
|
9
|
+
it "returns true for Smarandache-Wellin numbers" do
|
10
|
+
SMARANDACHE_WELLIN.each do |number|
|
11
|
+
number.should be_smarandache_wellin
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns false for non-Smarandache-Wellin numbers" do
|
16
|
+
[3,5757490, 99].each do |number|
|
17
|
+
number.should_not be_smarandache_wellin
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns false for numbers which merely contain Smarandache-Wellin numbers" do
|
22
|
+
[234, 82357].each do |number|
|
23
|
+
number.should_not be_smarandache_wellin
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/smith_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
describe Integer, "#smith?" do
|
2
|
+
# http://www.research.att.com/~njas/sequences/A006753
|
3
|
+
SMITH = [4,22,27,58,85,94,121,166,202,265,274,319,346,355,
|
4
|
+
378,382,391,438,454,483,517,526,535,562,576,588,
|
5
|
+
627,634,636,645,648,654,663,666,690,706,728,729,
|
6
|
+
762,778,825,852,861,895,913,915,922,958,985,1086]
|
7
|
+
|
8
|
+
it "returns true for Smith numbers" do
|
9
|
+
SMITH.each do |number|
|
10
|
+
number.should be_smith
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns false for non-Smith numbers" do
|
15
|
+
((1..1086).to_a - SMITH).each do |number|
|
16
|
+
number.should_not be_smith
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
describe Integer, "#sphenic?" do
|
2
|
+
# http://www.research.att.com/~njas/sequences/A007304
|
3
|
+
SPHENIC = [30,42,66,70,78,102,105,110,114,130,138,154,165,
|
4
|
+
170,174,182,186,190,195,222,230,231,238,246,255,
|
5
|
+
258,266,273,282,285,286,290,310,318,322,345,354,
|
6
|
+
357,366,370,374,385,399,402,406,410,418,426,429,
|
7
|
+
430,434,435,438]
|
8
|
+
|
9
|
+
it "returns true for sphenic numbers" do
|
10
|
+
SPHENIC.each do |number|
|
11
|
+
number.should be_sphenic
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns false for non-sphenic numbers" do
|
16
|
+
((1..438).to_a - SPHENIC).each do |number|
|
17
|
+
number.should_not be_sphenic
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe Integer, "#square_free?" do
|
2
|
+
# http://www.research.att.com/~njas/sequences/A005117
|
3
|
+
SQUARE_FREE = [1,2,3,5,6,7,10,11,13,14,15,17,19,21,22,23,26,29,
|
4
|
+
30,31,33,34,35,37,38,39,41,42,43,46,47,51,53,55,
|
5
|
+
57,58,59,61,62,65,66,67,69,70,71,73,74,77,78,79,
|
6
|
+
82,83,85,86,87,89,91,93,94,95,97,101,102,103,105,
|
7
|
+
106,107,109,110,111,113]
|
8
|
+
it "returns true for square-free numbers" do
|
9
|
+
SQUARE_FREE.each do |number|
|
10
|
+
number.should be_square_free
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns false for non-square-free numbers" do
|
15
|
+
((1..113).to_a - SQUARE_FREE).each do |number|
|
16
|
+
number.should_not be_square_free
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/square_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
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]
|
6
|
+
|
7
|
+
it "returns true if the number is square" do
|
8
|
+
SQUARES.each do |number|
|
9
|
+
number.should be_square
|
10
|
+
end
|
11
|
+
end
|
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
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns false for negative numbers" do
|
20
|
+
[-1, -378, -9].each do |number|
|
21
|
+
number.should_not be_square
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe Integer, "#triangular?" do
|
2
|
+
TRIANGULAR = [0,1,3,6,10,15,21,28,36,45,55,66,78,91,105,120,
|
3
|
+
136,153,171,190,210,231,253,276,300,325,351,378,
|
4
|
+
406,435,465,496,528,561,595,630,666,703,741,780,
|
5
|
+
820,861,903,946,990,1035,1081,1128,1176,1225,1275,
|
6
|
+
1326,1378,1431]
|
7
|
+
|
8
|
+
it "returns true for triangular numbers" do
|
9
|
+
TRIANGULAR.each do |number|
|
10
|
+
number.should be_triangular
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns false for non-triangular numbers" do
|
15
|
+
((1..1431).to_a - TRIANGULAR).each do |number|
|
16
|
+
number.should_not be_triangular
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
describe Integer, "#trimorphic?" do
|
2
|
+
TRIMORPHIC = [0,1,4,5,6,9,24,25,49,51,75,76,99,125,249,251,375,
|
3
|
+
376,499,501,624,625,749,751,875,999,1249,3751,
|
4
|
+
4375,4999,5001,5625,6249,8751,9375,9376,9999,
|
5
|
+
18751,31249,40625,49999,50001,59375,68751,81249,
|
6
|
+
90624,90625]
|
7
|
+
|
8
|
+
it "returns true for trimorphic numbers" do
|
9
|
+
TRIMORPHIC.each do |number|
|
10
|
+
number.should be_trimorphic
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns false for non-trimorphic numbers" do
|
15
|
+
[2,3,7, 8752, 906266, 33333].each do |number|
|
16
|
+
number.should_not be_trimorphic
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns false for negative numbers" do
|
21
|
+
[2,3,4,7,9,8752, 906266, 33333].each do |number|
|
22
|
+
(-number).should_not be_trimorphic
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
describe Integer, "#undulating?" do
|
2
|
+
# http://www.research.att.com/~njas/sequences/A046075
|
3
|
+
UNDULATING = [101,121,131,141,151,161,171,181,191,202,212,232,
|
4
|
+
242,252,262,272,282,292,303,313,323,343,353,363,
|
5
|
+
373,383,393,404,414,424,434,454,464,474,484,494,
|
6
|
+
505,515,525,535,545,565,575,585,595,606,616,626,
|
7
|
+
636,646,656]
|
8
|
+
|
9
|
+
it "requires true for undulating numbers" do
|
10
|
+
UNDULATING.each do |number|
|
11
|
+
number.should be_undulating
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "requires false for non-undulating numbers" do
|
16
|
+
((1..300).to_a - UNDULATING).each do |number|
|
17
|
+
number.should_not be_undulating
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
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]
|
7
|
+
|
8
|
+
it "returns true for vampire numbers" do
|
9
|
+
VAMPIRE.each do |number|
|
10
|
+
number.should be_vampire
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns false for non-vampire numbers" do
|
15
|
+
[1259,22,1396].each do |number|
|
16
|
+
number.should_not be_vampire
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/weird_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
describe Integer, "#weird?" do
|
2
|
+
WEIRD = [70,836,4030,5830,7192,7912,9272,10430,10570,
|
3
|
+
10792,10990,11410,11690,12110,12530,12670,13370,
|
4
|
+
13510,13790,13930,14770,15610,15890,16030,16310,
|
5
|
+
16730,16870,17272,17570,17990,18410,18830,18970,
|
6
|
+
19390,19670]
|
7
|
+
it "returns true if the number is weird" do
|
8
|
+
WEIRD.sample(10).each do |number|
|
9
|
+
number.should be_weird
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns false if the number is not weird" do
|
14
|
+
[1, 39, 69, 13791].each do |number|
|
15
|
+
number.should_not be_weird
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns false if the number is negative" do
|
20
|
+
[-1, -70, -39, -19390].each do |number|
|
21
|
+
number.should_not be_weird
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|