numb 0.96.0 → 0.99.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 CHANGED
@@ -1 +1 @@
1
- 0.96.0
1
+ 0.99.0
data/lib/numb/aban.rb ADDED
@@ -0,0 +1,5 @@
1
+ class Integer
2
+ def aban?
3
+ not words.sub(/and/,'').include?('a')
4
+ end
5
+ end
data/lib/numb/eban.rb ADDED
@@ -0,0 +1,5 @@
1
+ class Integer
2
+ def eban?
3
+ not words.include?('e')
4
+ end
5
+ end
data/lib/numb/words.rb ADDED
@@ -0,0 +1,37 @@
1
+ class Integer
2
+ WORDS = {
3
+ 0 => 'zero', 1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four',
4
+ 5 => 'five', 6 => 'six', 7 => 'seven', 8 => 'eight', 9 => 'nine',
5
+ 10 => 'ten', 11 => 'eleven', 12 => 'twelve', 13 => 'thirteen',
6
+ 14 => 'fourteen', 15 => 'fifteen', 16 => 'sixteen', 17 => 'seventeen',
7
+ 18 => 'eighteen', 19 => 'nineteen', 20 => 'twenty', 30 => 'thirty',
8
+ 40 => 'forty', 50 => 'fifty', 60 => 'sixty', 70 => 'seventy',
9
+ 80 => 'eighty', 90 => 'ninety'
10
+ }
11
+
12
+ def words
13
+ return WORDS[0] if zero?
14
+ str = (place = places.to_a).map do |name, v|
15
+ next if v.zero?
16
+ case name
17
+ when :units then WORDS[v]
18
+ when :tens
19
+ units = place.pop.last
20
+ v == 1 ? WORDS[10 + units]
21
+ : WORDS[10 * v] + (units.zero? ? '' : ' ' + units.words)
22
+ else
23
+ v.words + ' ' + name.to_s[0..-2]
24
+ end
25
+ end.compact.join(', ')
26
+ str.include?(',') ? str.sub(/,([^,]+)$/,' and\1') : str
27
+ end
28
+
29
+ def places
30
+ n = self
31
+ {trillions: 10e11, billions: 10e8, millions: 10e5, thousands: 10e2,
32
+ hundreds: 10e1, tens: 10, units: 1}.map do |k,v|
33
+ v, n = n.divmod(v)
34
+ [k, v]
35
+ end.tap{|a| return Hash[a] }
36
+ end
37
+ end
@@ -0,0 +1,15 @@
1
+ describe Integer, "#aban?" do
2
+ @seq = [*(1..999), *(1_000_000..1_000_999)]
3
+
4
+ @seq.sample(100).each do |n|
5
+ it "returns true for aban number #{n}" do
6
+ n.should be_aban
7
+ end
8
+ end
9
+
10
+ @seq.to_seq.invert.sample(100).each do |n|
11
+ it "returns false for non-aban number #{n}" do
12
+ n.should_not be_aban
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ describe Integer, "#eban?" do
2
+ # A006933
3
+ @seq = [2,4,6,30,32,34,36,40,42,44,46,50,52,54,56,60,62,
4
+ 64,66,2000,2002,2004,2006,2030,2032,2034,2036,
5
+ 2040,2042,2044,2046,2050,2052,2054,2056,2060,2062,
6
+ 2064,2066,4000,4002,4004,4006,4030,4032,4034,4036,
7
+ 4040,4042,4044,4046,4050,4052,4054,4056]
8
+
9
+ @seq.each do |n|
10
+ it "returns true for eban number #{n}" do
11
+ n.should be_eban
12
+ end
13
+ end
14
+
15
+ @seq.to_seq.invert.sample(100).each do |n|
16
+ it "returns false for non-eban number #{n}" do
17
+ n.should_not be_eban
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,60 @@
1
+ describe Integer, "#words" do
2
+ @seq = {
3
+ 0 => 'zero',
4
+ 1 => 'one',
5
+ 2 => 'two',
6
+ 3 => 'three',
7
+ 4 => 'four',
8
+ 5 => 'five',
9
+ 6 => 'six',
10
+ 7 => 'seven',
11
+ 8 => 'eight',
12
+ 9 => 'nine',
13
+ 10 => 'ten',
14
+ 11 => 'eleven',
15
+ 12 => 'twelve',
16
+ 13 => 'thirteen',
17
+ 14 => 'fourteen',
18
+ 15 => 'fifteen',
19
+ 16 => 'sixteen',
20
+ 17 => 'seventeen',
21
+ 18 => 'eighteen',
22
+ 19 => 'nineteen',
23
+ 20 => 'twenty',
24
+ 24 => 'twenty four',
25
+ 30 => 'thirty',
26
+ 39 => 'thirty nine',
27
+ 40 => 'forty',
28
+ 42 => 'forty two',
29
+ 50 => 'fifty',
30
+ 56 => 'fifty six',
31
+ 60 => 'sixty',
32
+ 63 => 'sixty three',
33
+ 70 => 'seventy',
34
+ 71 => 'seventy one',
35
+ 80 => 'eighty',
36
+ 88 => 'eighty eight',
37
+ 90 => 'ninety',
38
+ 95 => 'ninety five',
39
+ 100 => 'one hundred',
40
+ 103 => 'one hundred and three',
41
+ 140 => 'one hundred and forty',
42
+ 155 => 'one hundred and fifty five',
43
+ 199 => 'one hundred and ninety nine',
44
+ 300 => 'three hundred',
45
+ 712 => 'seven hundred and twelve',
46
+ 1_000 => 'one thousand',
47
+ 1_001 => 'one thousand and one',
48
+ 30_333 => 'thirty thousand, three hundred and thirty three',
49
+ 900_002 => 'nine hundred thousand and two',
50
+ 1_000_000 => 'one million',
51
+ 34_000_006 => 'thirty four million and six',
52
+ 999_999_999 => 'nine hundred and ninety nine million, nine hundred and ninety nine thousand, nine hundred and ninety nine',
53
+ 40_000_000_000 => 'forty billion',
54
+ }.each_pair do |n, name|
55
+ it "returns #{name} for #{n}" do
56
+ n.words.should == name
57
+ end
58
+ end
59
+ end
60
+
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.96.0
4
+ version: 0.99.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-12 00:00:00 +00:00
12
+ date: 2010-03-13 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -39,6 +39,7 @@ files:
39
39
  - Rakefile
40
40
  - VERSION
41
41
  - lib/numb.rb
42
+ - lib/numb/aban.rb
42
43
  - lib/numb/abundancy.rb
43
44
  - lib/numb/abundant.rb
44
45
  - lib/numb/achilles.rb
@@ -73,6 +74,7 @@ files:
73
74
  - lib/numb/dodecagonal.rb
74
75
  - lib/numb/doubly_even.rb
75
76
  - lib/numb/dudeney.rb
77
+ - lib/numb/eban.rb
76
78
  - lib/numb/economical.rb
77
79
  - lib/numb/emrip.rb
78
80
  - lib/numb/equidigital.rb
@@ -186,8 +188,10 @@ files:
186
188
  - lib/numb/weird.rb
187
189
  - lib/numb/wieferich.rb
188
190
  - lib/numb/woodall.rb
191
+ - lib/numb/words.rb
189
192
  - lib/numb/zeisel.rb
190
193
  - lib/numb/zerofree.rb
194
+ - spec/numb/aban_spec.rb
191
195
  - spec/numb/abundancy_spec.rb
192
196
  - spec/numb/abundant_spec.rb
193
197
  - spec/numb/achilles_spec.rb
@@ -222,6 +226,7 @@ files:
222
226
  - spec/numb/dodecagonal_spec.rb
223
227
  - spec/numb/doubly_even_spec.rb
224
228
  - spec/numb/dudeney_spec.rb
229
+ - spec/numb/eban_spec.rb
225
230
  - spec/numb/economical_spec.rb
226
231
  - spec/numb/emrip_spec.rb
227
232
  - spec/numb/equidigital_spec.rb
@@ -334,6 +339,7 @@ files:
334
339
  - spec/numb/weird_spec.rb
335
340
  - spec/numb/wieferich_prime_spec.rb
336
341
  - spec/numb/woodall_spec.rb
342
+ - spec/numb/words_spec.rb
337
343
  - spec/numb/zeisel_spec.rb
338
344
  - spec/numb/zerofree_spec.rb
339
345
  - spec/spec.opts
@@ -404,9 +410,11 @@ test_files:
404
410
  - spec/numb/unitary_amicable_spec.rb
405
411
  - spec/numb/squared_triangular_spec.rb
406
412
  - spec/numb/zerofree_spec.rb
413
+ - spec/numb/eban_spec.rb
407
414
  - spec/numb/automorphic_spec.rb
408
415
  - spec/numb/minimal_spec.rb
409
416
  - spec/numb/jacobsthal_lucas_spec.rb
417
+ - spec/numb/aban_spec.rb
410
418
  - spec/numb/hyperperfect_spec.rb
411
419
  - spec/numb/zeisel_spec.rb
412
420
  - spec/numb/smooth_spec.rb
@@ -447,6 +455,7 @@ test_files:
447
455
  - spec/numb/mersenne_prime_spec.rb
448
456
  - spec/numb/composite_spec.rb
449
457
  - spec/numb/practical_spec.rb
458
+ - spec/numb/words_spec.rb
450
459
  - spec/numb/sophie_germain_prime_spec.rb
451
460
  - spec/numb/parasitic_spec.rb
452
461
  - spec/numb/friendly_spec.rb