jinyu-simple-combiner 0.0.1
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 +7 -0
- data/lib/utils/simple_combiner.rb +49 -0
- metadata +44 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 82c08dd429c20824dd660b599dc0a70cb63f9adb
|
|
4
|
+
data.tar.gz: 9fa85e022f7c996774bcfd746756a0d92a22aa33
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3e591dbe9c93907a5e44db117856f52f4e1f1b878f52392cb046205cf68ad0fd0c630471df611d619e1fe22084e8ddc21b9b98ace3ce2fdebaa645ed1fe48bad
|
|
7
|
+
data.tar.gz: 68ff2e3b93061985c48e701af9fca692a707861309156ec89e9a78bf397547210c1203918cc10a7668669b92eb0295ed4585d1752c72f846b257dd2dfff94caf
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# no guarantee for memory usage efficiency
|
|
2
|
+
# no garantee for computation efficiency
|
|
3
|
+
# no garentee for no-bug :D
|
|
4
|
+
class SimpleCombiner
|
|
5
|
+
def self.combine(the_list, number, current_list = [])
|
|
6
|
+
return current_list if number == 0
|
|
7
|
+
|
|
8
|
+
result = the_list.map do |element|
|
|
9
|
+
_current_list = Marshal.load(Marshal.dump(current_list))
|
|
10
|
+
_current_list << element
|
|
11
|
+
combine(the_list, number - 1, _current_list.freeze)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
return result[0][0].is_a?(Array) ? result.inject([]){|arr, ele| arr + ele} : result
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def self.permutate(the_list, number)
|
|
19
|
+
return [] if number == 0 || the_list.empty?
|
|
20
|
+
|
|
21
|
+
this_results = []
|
|
22
|
+
while element = the_list.delete_at(0)
|
|
23
|
+
results = []
|
|
24
|
+
|
|
25
|
+
number.downto(0).each do |num|
|
|
26
|
+
combine_results = [[nil]]
|
|
27
|
+
combine_results = permutate(Marshal.load(Marshal.dump(the_list)), number - num) + combine_results
|
|
28
|
+
|
|
29
|
+
result = []
|
|
30
|
+
combine_results.each do |combine_result|
|
|
31
|
+
result = ([element] * num + combine_result).compact
|
|
32
|
+
|
|
33
|
+
if result.size < number
|
|
34
|
+
break
|
|
35
|
+
else
|
|
36
|
+
results << result
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
if this_results.last != results.last
|
|
42
|
+
this_results += results
|
|
43
|
+
else
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
return this_results
|
|
48
|
+
end
|
|
49
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: jinyu-simple-combiner
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Yukai Jin
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-01-07 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: a simple tool for combination and permutation, no any guarentee
|
|
14
|
+
email: fish1928@outlook.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/utils/simple_combiner.rb
|
|
20
|
+
homepage: https://github.com/fish1928/SimpleCombiner
|
|
21
|
+
licenses:
|
|
22
|
+
- MIT
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubyforge_project:
|
|
40
|
+
rubygems_version: 2.6.12
|
|
41
|
+
signing_key:
|
|
42
|
+
specification_version: 4
|
|
43
|
+
summary: simple tool for combination and permutation
|
|
44
|
+
test_files: []
|