alpha-math 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/alpha_math.rb +7 -1
  3. data/lib/partitions.rb +30 -0
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9052f005b8bd96285dbe8fd9568b35ef994e641bd7a263d3da8cac783bb86f74
4
- data.tar.gz: 64e117f7f83875a34488d4104f74fd3d673225f33c6149e558b53956f0db1406
3
+ metadata.gz: 61af6c2507c11c16f49d5a84261d6d8ac38ae4a1ffb5c8a7a1f7e5112b7c3abe
4
+ data.tar.gz: 036c215950c93cdf82179b6937d2e1b3daec6c5723bf72dbb4705c9808735cc5
5
5
  SHA512:
6
- metadata.gz: '09bff5d6a8eecc8e1ef71c59b6308e4f8139d62236a7d7a5aaa8a16ca1e007e93ada407757c022234fded3a8059eb5ce0215a8ac2571cde1b1c34bac472d2750'
7
- data.tar.gz: dd7bc1ce3ae93c1e4eef4c34b614041ee21ce92b766e3c82e9d70ebc6c3da6191d619d37f831e87862843f881a167c0e0a4c95891c4263f736c4253864a153b4
6
+ metadata.gz: 69ada14ac253769384d6b739c115eef7447336646e5a9b79f77cb7074c997443c24d2bde29c571dca73d3b03a6977237f4cbcdc625fd5701c930d860143be006
7
+ data.tar.gz: 652781073e7c88db0187e200a3ae19339b2b7746dce0f7b9214843f111db86b897f899810a2a4e7d55c00bc9c7224adc1c2ce25abfd8c06bec1b06359677d19c
@@ -1,3 +1,5 @@
1
+ require_relative '../lib/partitions'
2
+
1
3
  module AlphaMath
2
4
 
3
5
  def self.decomposition(number, factors = [])
@@ -19,7 +21,7 @@ module AlphaMath
19
21
  end
20
22
 
21
23
  def self.divisors_of(number)
22
- (1..number / 2).select {|divisor| number.divmod(divisor).last.zero?} << number
24
+ (1..number / 2).select { |divisor| number.divmod(divisor).last.zero? } << number
23
25
  end
24
26
 
25
27
  def self.magnitude(number)
@@ -60,4 +62,8 @@ module AlphaMath
60
62
  zeros
61
63
  end
62
64
 
65
+ def self.partitions(number)
66
+ Partitions.new.enumerates(number)
67
+ end
68
+
63
69
  end
@@ -0,0 +1,30 @@
1
+ class Partitions
2
+
3
+ def enumerates(n)
4
+ partitions = {}
5
+ partitions[1] = [[1]]
6
+ 2.upto(n) do |value|
7
+ partitions[value] = partition(value, partitions)
8
+ end
9
+ partitions[n]
10
+ end
11
+
12
+ def partition(n, previous)
13
+ result = [[n]]
14
+ (n - 1).downto(1) do |value|
15
+ result.concat(sumfy(value, previous[n - value]))
16
+ end
17
+ result
18
+ end
19
+
20
+ def sumfy(number, partitions)
21
+ result = []
22
+ partitions.each do |partition|
23
+ result << ([number] + partition) if (number >= partition.first)
24
+ end
25
+ result
26
+ end
27
+
28
+ end
29
+
30
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alpha-math
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauro Quaglia
@@ -18,6 +18,7 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - lib/alpha_math.rb
21
+ - lib/partitions.rb
21
22
  homepage: https://github.com/MauroQuaglia/alpha-math/wiki
22
23
  licenses:
23
24
  - MIT
@@ -37,8 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
38
  - !ruby/object:Gem::Version
38
39
  version: '0'
39
40
  requirements: []
40
- rubyforge_project:
41
- rubygems_version: 2.7.9
41
+ rubygems_version: 3.0.6
42
42
  signing_key:
43
43
  specification_version: 4
44
44
  summary: Some tools on numbers.