string_permutations 1.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/string_permutations.rb +40 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cf86dd6fdc107698739ea4ef4efcb8b9a332eddd
4
+ data.tar.gz: f3531f63b17c18207fd1a69c4c8529610951e24f
5
+ SHA512:
6
+ metadata.gz: 2538db49239397e02e8b6290b54211c50522c78d92f6c4ccd3ef34477923b02a4b50a82ffbe84f49dd490aee4847188cd7945af542781c702c718184431c12e6
7
+ data.tar.gz: ef5f87a09c2bf839698721c2324ff26d22bcaf1c17471863d280bd4967cd235f92182df2c916752599c7a92637281576d9891459d2db6906ecfcace105803685
@@ -0,0 +1,40 @@
1
+ module StringPermutations
2
+
3
+ def StringPermutations.permutate(str,k)
4
+ return nil unless k.class == Fixnum && str.class == String
5
+ arr = str.split("")
6
+ @for_perms = []
7
+ @result = []
8
+ @final = []
9
+ combination(arr,k,0,k)
10
+ @for_perms.each{|x|
11
+ arr = x.split("")
12
+ permutation(arr,0,k)
13
+ }
14
+ @final.uniq
15
+ end
16
+
17
+ def self.combination(arr,len,start,k)
18
+ if(len == 0)
19
+ @for_perms.push(@result.join(""))
20
+ return
21
+ end
22
+ for i in start..(arr.length - len)
23
+ @result[k - len] = arr[i]
24
+ combination(arr,len-1,i+1,k)
25
+ end
26
+ end
27
+
28
+ def self.permutation(a,i,n)
29
+ if i==n
30
+ @final.push(a.join(""))
31
+ else
32
+ for j in i..n
33
+ a[i],a[j] = a[j],a[i]
34
+ permutation(a,i+1,n)
35
+ a[i],a[j] = a[j],a[i]
36
+ end
37
+ end
38
+ end
39
+
40
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: string_permutations
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Ashish Agrawal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: find the permutations of a string k characters at a time
14
+ email: ashishagrawal979@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/string_permutations.rb
20
+ homepage: https://github.com/ashish979/string_permutation
21
+ licenses:
22
+ - Nonstandard
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.6
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: permutation of a string k characters at a time
44
+ test_files: []