unique_permutation 1.0.1 → 1.0.2

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/unique_permutation.rb +15 -18
  3. metadata +16 -18
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 44423676ed73ec4103c5f6cfefe5f3727938c2b2cd55535a158a00fd08088691
4
+ data.tar.gz: 0b1770be1d694c8003b641103e80e33fc1bb161f82a41a6e00bc6e410e59d980
5
+ SHA512:
6
+ metadata.gz: 84358188c1c306e031f83dd0aaa11a24cc6d12dc850828d653f8779fd9e408cf0ce8fc6fa235727dddfb40c6f47f25740200802fbf1261b17096537610f5df66
7
+ data.tar.gz: c2b1a296f976ef0141da685310a43779a06d583580124b166ce7387e4a977a4c37af5b849e94c596c74f0fe2a88e59dee78f575a7e5db629212f34e3db42fcf2
@@ -2,31 +2,28 @@
2
2
  # This is incredibly more efficient that the built in permutation method as duplicate elements will yield
3
3
  # identical permutations.
4
4
 
5
+ # Based off of Algorithm L (Donald Knuth)
6
+
5
7
  class Array
6
- def unique_permutation(&block)
8
+ def unique_permutation # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
7
9
  return enum_for(:unique_permutation) unless block_given?
8
10
 
9
- array_copy = self.sort
11
+ array_copy = sort
10
12
  yield array_copy.dup
11
- return if size < 2
12
-
13
- while true
14
- # Based off of Algorithm L (Donald Knuth)
15
- j = size - 2;
16
- j -= 1 while j > 0 && array_copy[j] >= array_copy[j+1]
13
+ return if size <= 1
17
14
 
18
- if array_copy[j] < array_copy[j+1]
19
- l = size - 1
20
- l -= 1 while array_copy[j] >= array_copy[l]
15
+ loop do
16
+ j = size - 2
17
+ j -= 1 while j > 0 && array_copy[j] >= array_copy[j + 1]
18
+ break unless array_copy[j] < array_copy[j + 1]
21
19
 
22
- array_copy[j] , array_copy[l] = array_copy[l] , array_copy[j]
23
- array_copy[j+1..-1] = array_copy[j+1..-1].reverse
20
+ l = size - 1
21
+ l -= 1 while array_copy[j] >= array_copy[l]
24
22
 
25
- yield array_copy.dup
23
+ array_copy[j], array_copy[l] = array_copy[l], array_copy[j]
24
+ array_copy[(j + 1)..] = array_copy[(j + 1)..].reverse
26
25
 
27
- else
28
- break
29
- end
26
+ yield array_copy.dup
30
27
  end
31
28
  end
32
- end
29
+ end
metadata CHANGED
@@ -1,45 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unique_permutation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
5
- prerelease:
4
+ version: 1.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Aaron Rosenberg
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-03-19 00:00:00.000000000 Z
11
+ date: 2020-09-07 00:00:00.000000000 Z
13
12
  dependencies: []
14
- description: Adds the unique_permutation method to the array class.
13
+ description: Adds `Array#unique_permutation` method.
15
14
  email: aarongrosenberg@gmail.com
16
15
  executables: []
17
16
  extensions: []
18
17
  extra_rdoc_files: []
19
18
  files:
20
19
  - lib/unique_permutation.rb
21
- homepage: https://github.com/LtCmdDudefellah/unique_permutation
22
- licenses: []
23
- post_install_message:
20
+ homepage: https://github.com/agrberg/unique_permutation
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
24
25
  rdoc_options: []
25
26
  require_paths:
26
27
  - lib
27
28
  required_ruby_version: !ruby/object:Gem::Requirement
28
- none: false
29
29
  requirements:
30
- - - ! '>='
30
+ - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
32
+ version: '2.6'
33
33
  required_rubygems_version: !ruby/object:Gem::Requirement
34
- none: false
35
34
  requirements:
36
- - - ! '>='
35
+ - - ">="
37
36
  - !ruby/object:Gem::Version
38
37
  version: '0'
39
38
  requirements: []
40
- rubyforge_project:
41
- rubygems_version: 1.8.17
42
- signing_key:
43
- specification_version: 3
44
- summary: Create unique permutations from an array
39
+ rubygems_version: 3.1.2
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: Find unique permutations from an array
45
43
  test_files: []