ClosestSum 1.0.0-universal-linux → 1.1.0-universal-linux
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.
- checksums.yaml +4 -4
- data/lib/ClosestSum.rb +7 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d682f216b3324060a57b1dbce50d994077a83052
|
4
|
+
data.tar.gz: 757ccf8a8c79ab64256b8a5418e5ae0620918da1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7e681c0475b06520415617ec1a02b009228ac55e9c7bbb8df8c38cac4fd4e90543e9ccc72f8c5d58ec97b0ea4682c445d9f274e8d6596675ee0f220ab8eddf4
|
7
|
+
data.tar.gz: b77e8f9a111f61433f8433a333ad4eea1c349119143e27f01f27e30e22076dd0c2dffaecb8b092b6a88d0b9f4adae5bea20046d2e75d04af805fe42756a58b8b
|
data/lib/ClosestSum.rb
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
# Algorithm --
|
8
8
|
# 20) Sort the hash as per the largest to the smallest.
|
9
9
|
# 40) Check if adding the next entity (i.e. the 1st entity for the 1st run) to the current 'final list' will exceed the first argument. If so move to 60, otherwise 50.
|
10
|
-
# 50) Add the entity to final list and move to 40 if 'final list' total size != the first argument, otherwise
|
10
|
+
# 50) Add the entity to final list and move to 40 if 'final list' total size != the first argument, otherwise exit program.
|
11
11
|
# 60) Skip to the next entity if it exists. If it does not, return final list and exit program.
|
12
12
|
|
13
13
|
# Variable list --
|
@@ -40,14 +40,17 @@ module ClosestSum
|
|
40
40
|
inputHash = inputHash.sort_by {
|
41
41
|
|x, y|
|
42
42
|
y
|
43
|
-
|
43
|
+
}.reverse
|
44
44
|
totalCurrentSize = totalSize(finalList)
|
45
45
|
inputHash.each {
|
46
46
|
|key, value|
|
47
47
|
if finalList[key] == nil
|
48
|
-
|
48
|
+
if totalCurrentSize + value <= targetSize
|
49
|
+
finalList[key] = value
|
50
|
+
totalCurrentSize += value
|
51
|
+
end
|
49
52
|
end
|
50
53
|
}
|
51
54
|
finalList
|
52
55
|
end
|
53
|
-
end
|
56
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ClosestSum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: universal-linux
|
6
6
|
authors:
|
7
7
|
- dE
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Given a hash of keys and numeric values and another integer value (target
|
14
14
|
size), this module will select the largest keys from the given hash such that the
|
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
40
|
version: '0'
|
41
41
|
requirements: []
|
42
42
|
rubyforge_project:
|
43
|
-
rubygems_version: 2.
|
43
|
+
rubygems_version: 2.2.2
|
44
44
|
signing_key:
|
45
45
|
specification_version: 4
|
46
46
|
summary: Given a list of names/paths and the corresponding numeric value, will select
|