permutation 0.1.6 → 0.1.7
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.
- data/CHANGES +3 -0
- data/{GPL → COPYING} +0 -0
- data/{README.en → README} +0 -0
- data/Rakefile +44 -29
- data/VERSION +1 -1
- data/doc-main.txt +120 -0
- data/examples/tsp.rb +27 -28
- data/install.rb +3 -2
- data/lib/permutation.rb +11 -133
- data/lib/permutation/version.rb +1 -1
- data/make_doc.rb +5 -0
- data/permutation.gemspec +21 -0
- data/test/test.rb +0 -1
- metadata +19 -19
data/CHANGES
CHANGED
data/{GPL → COPYING}
RENAMED
File without changes
|
data/{README.en → README}
RENAMED
File without changes
|
data/Rakefile
CHANGED
@@ -1,22 +1,15 @@
|
|
1
|
-
|
2
|
-
require '
|
1
|
+
begin
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
rescue LoadError
|
4
|
+
end
|
3
5
|
require 'rake/clean'
|
4
|
-
|
6
|
+
require 'rbconfig'
|
5
7
|
include Config
|
6
8
|
|
7
9
|
PKG_NAME = 'permutation'
|
8
10
|
PKG_VERSION = File.read('VERSION').chomp
|
9
|
-
PKG_FILES = FileList[
|
10
|
-
|
11
|
-
desc "Installing library"
|
12
|
-
task :install do
|
13
|
-
ruby 'install.rb'
|
14
|
-
end
|
15
|
-
|
16
|
-
desc "Creating documentation"
|
17
|
-
task :doc do
|
18
|
-
ruby 'make_doc.rb'
|
19
|
-
end
|
11
|
+
PKG_FILES = FileList['**/*'].exclude(/^(doc|CVS|pkg|coverage)/)
|
12
|
+
CLEAN.include 'coverage', 'doc'
|
20
13
|
|
21
14
|
desc "Testing library"
|
22
15
|
task :test do
|
@@ -28,36 +21,59 @@ task :coverage do
|
|
28
21
|
sh %{rcov -Ilib test/test.rb}
|
29
22
|
end
|
30
23
|
|
31
|
-
|
32
|
-
|
33
|
-
|
24
|
+
desc "Installing library"
|
25
|
+
task :install do
|
26
|
+
ruby 'install.rb'
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Creating documentation"
|
30
|
+
task :doc do
|
31
|
+
ruby 'make_doc.rb'
|
32
|
+
end
|
33
|
+
|
34
|
+
if defined? Gem
|
35
|
+
spec_src = <<GEM
|
36
|
+
# -*- encoding: utf-8 -*-
|
37
|
+
Gem::Specification.new do |s|
|
38
|
+
s.name = '#{PKG_NAME}'
|
39
|
+
s.version = '#{PKG_VERSION}'
|
34
40
|
s.summary = 'Permutation library in pure Ruby'
|
35
41
|
s.description = "Library to perform different operations with permutations of sequences (strings, arrays, etc.)"
|
36
42
|
|
37
|
-
s.files = PKG_FILES
|
43
|
+
s.files = #{PKG_FILES.to_a.sort.inspect}
|
38
44
|
|
39
45
|
s.require_path = 'lib'
|
40
46
|
|
41
47
|
s.has_rdoc = true
|
42
|
-
s.rdoc_options << '--
|
43
|
-
s.extra_rdoc_files
|
48
|
+
s.rdoc_options << '--main' << 'doc-main.txt' << '--line-numbers'
|
49
|
+
s.extra_rdoc_files << 'doc-main.txt'
|
44
50
|
s.test_files << 'test/test.rb'
|
45
51
|
|
46
52
|
s.author = "Florian Frank"
|
47
53
|
s.email = "flori@ping.de"
|
48
|
-
s.homepage = "http
|
49
|
-
s.rubyforge_project = "
|
54
|
+
s.homepage = "http://#{PKG_NAME}.rubyforge.org"
|
55
|
+
s.rubyforge_project = "#{PKG_NAME}"
|
50
56
|
end
|
57
|
+
GEM
|
51
58
|
|
52
|
-
|
53
|
-
|
54
|
-
|
59
|
+
desc 'Create a gemspec file'
|
60
|
+
task :gemspec do
|
61
|
+
File.open("#{PKG_NAME}.gemspec", 'w') do |f|
|
62
|
+
f.puts spec_src
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
spec = eval(spec_src)
|
67
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
68
|
+
pkg.need_tar = true
|
69
|
+
pkg.package_files += PKG_FILES
|
70
|
+
end
|
55
71
|
end
|
56
72
|
|
57
73
|
desc m = "Writing version information for #{PKG_VERSION}"
|
58
74
|
task :version do
|
59
75
|
puts m
|
60
|
-
File.open(File.join('lib',
|
76
|
+
File.open(File.join('lib', PKG_NAME, 'version.rb'), 'w') do |v|
|
61
77
|
v.puts <<EOT
|
62
78
|
class Permutation
|
63
79
|
# Permutation version
|
@@ -71,7 +87,6 @@ EOT
|
|
71
87
|
end
|
72
88
|
end
|
73
89
|
|
74
|
-
|
90
|
+
task :default => [ :version, :gemspec, :test ]
|
75
91
|
|
76
|
-
task :release => [ :clean, :version, :package ]
|
77
|
-
# vim: set et sw=2 ts=2:
|
92
|
+
task :release => [ :clean, :version, :gemspec, :package ]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
data/doc-main.txt
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
== Permutation library for Ruby
|
2
|
+
|
3
|
+
=== Author
|
4
|
+
|
5
|
+
Florian Frank mailto:flori@ping.de
|
6
|
+
|
7
|
+
=== License
|
8
|
+
|
9
|
+
This is free software; you can redistribute it and/or modify it under the
|
10
|
+
terms of the GNU General Public License Version 2 as published by the Free
|
11
|
+
Software Foundation: www.gnu.org/copyleft/gpl.html
|
12
|
+
|
13
|
+
=== Download
|
14
|
+
|
15
|
+
The latest version of <b>permutation</b> can be found at
|
16
|
+
|
17
|
+
* http://rubyforge.org/frs/?group_id=291
|
18
|
+
|
19
|
+
The homepage of this library is located at
|
20
|
+
|
21
|
+
* http://permutation.rubyforge.org
|
22
|
+
|
23
|
+
=== Description
|
24
|
+
|
25
|
+
The Permutation class has a dual purpose: It can be used to create
|
26
|
+
permutations of a given size and to do some simple computations with/on
|
27
|
+
permutations. The instances of this class don't require much memory
|
28
|
+
because they don't include the permutation as a data structure. They
|
29
|
+
only save the information necessary to create the permutation if asked
|
30
|
+
to do so.
|
31
|
+
|
32
|
+
To generate permutations the ranking/unranking method described in [SS97]
|
33
|
+
is used. Because of Ruby's Bignum arithmetic it is useful also
|
34
|
+
for permutations of very large size.
|
35
|
+
|
36
|
+
=== Examples
|
37
|
+
|
38
|
+
In this section some examples show what can be done with this class.
|
39
|
+
|
40
|
+
Creating all permutations and project them on data:
|
41
|
+
|
42
|
+
perm = Permutation.new(3)
|
43
|
+
# => #<Permutation:0x57dc94 @last=5, @rank=0, @size=3>
|
44
|
+
perm.map { |p| p.value }
|
45
|
+
# => [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]]
|
46
|
+
colors = [:r, :g, :b]
|
47
|
+
# => [:r, :g, :b]
|
48
|
+
perm.map { |p| p.project(colors) }
|
49
|
+
# => [[:r, :g, :b], [:r, :b, :g], [:g, :r, :b], [:g, :b, :r], [:b, :r, :g],
|
50
|
+
# [:b, :g, :r]]
|
51
|
+
string = "abc"# => "abc"
|
52
|
+
perm.map { |p| p.project(string) }
|
53
|
+
# => ["abc", "acb", "bac", "bca", "cab", "cba"]
|
54
|
+
|
55
|
+
Or perhaps more convenient to use:
|
56
|
+
|
57
|
+
perm = Permutation.for("abc")
|
58
|
+
perm.map { |p| p.project }
|
59
|
+
# => ["abc", "acb", "bac", "bca", "cab", "cba"]
|
60
|
+
|
61
|
+
Finding the successor and predecessor of Permutations or a
|
62
|
+
certain Permutation for a given rank:
|
63
|
+
|
64
|
+
perm = Permutation.new(7)
|
65
|
+
# => #<Permutation:0x8453c @rank=0, @size=7, @last=5039>
|
66
|
+
perm.succ!
|
67
|
+
# => #<Permutation:0x8453c @rank=1, @size=7, @last=5039>
|
68
|
+
perm.succ!
|
69
|
+
# => #<Permutation:0x8453c @rank=2, @size=7, @last=5039>
|
70
|
+
perm.succ!
|
71
|
+
# => #<Permutation:0x8453c @rank=3, @size=7, @last=5039>
|
72
|
+
perm.pred!
|
73
|
+
# => #<Permutation:0x8453c @rank=2, @size=7, @last=5039>
|
74
|
+
perm.rank = 3200
|
75
|
+
# => 3200
|
76
|
+
perm
|
77
|
+
# => #<Permutation:0x8453c @rank=3200, @size=7, @last=5039>
|
78
|
+
perm.value
|
79
|
+
# => [4, 2, 5, 1, 3, 0, 6]
|
80
|
+
|
81
|
+
Generating random Permutations
|
82
|
+
|
83
|
+
perm = Permutation.new(10)
|
84
|
+
# => #<Permutation:0x59f4c0 @rank=0, @size=10, @last=3628799>
|
85
|
+
perm.random!.value
|
86
|
+
# => [6, 4, 9, 7, 3, 5, 8, 1, 2, 0]
|
87
|
+
perm.random!.value
|
88
|
+
# => [3, 7, 6, 1, 4, 8, 9, 2, 5, 0]
|
89
|
+
perm.random!.value
|
90
|
+
# => [2, 8, 4, 9, 3, 5, 6, 7, 0, 1]
|
91
|
+
perm.random!.project("ABCDEFGHIJ")
|
92
|
+
# => "DFJGAEBCIH"
|
93
|
+
perm.random!.project("ABCDEFGHIJ")
|
94
|
+
# => "BFADEGHJCI"
|
95
|
+
|
96
|
+
Performing some mathematical operations on/with Permutations
|
97
|
+
|
98
|
+
p1 = Permutation.from_cycles([[1, 3, 2], [5, 7]], 10)
|
99
|
+
# => #<Permutation:0x593594 @rank=80694, @size=10, @last=3628799>
|
100
|
+
p2 = Permutation.from_value [3, 2, 0, 5, 6, 8, 9, 1, 4, 7]
|
101
|
+
# => #<Permutation:0x5897b0 @rank=1171050, @size=10, @last=3628799>
|
102
|
+
p3 = p1 * p2
|
103
|
+
# => #<Permutation:0x586a88 @rank=769410, @size=10, @last=3628799>
|
104
|
+
p3.value
|
105
|
+
# => [2, 1, 0, 7, 6, 8, 9, 3, 4, 5]
|
106
|
+
p3.cycles
|
107
|
+
# => [[0, 2], [3, 7], [4, 6, 9, 5, 8]]
|
108
|
+
p4 = p1 * -p2
|
109
|
+
# => #<Permutation:0x581a10 @rank=534725, @size=10, @last=3628799>
|
110
|
+
p4.value
|
111
|
+
# => [1, 5, 3, 0, 8, 2, 4, 9, 7, 6]
|
112
|
+
p4.cycles
|
113
|
+
# => [[0, 1, 5, 2, 3], [4, 8, 7, 9, 6]]
|
114
|
+
id = p1 * -p1
|
115
|
+
# => #<Permutation:0x583a7c @rank=0, @size=10, @last=3628799>
|
116
|
+
|
117
|
+
=== References
|
118
|
+
|
119
|
+
[SS97] The Algorithm Design Manual, Steven S. Skiena, Telos/Springer, 1997.
|
120
|
+
|
data/examples/tsp.rb
CHANGED
@@ -7,25 +7,25 @@
|
|
7
7
|
require 'permutation'
|
8
8
|
|
9
9
|
def make_matrix(n)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
10
|
+
dist = Array.new(n) { [] }
|
11
|
+
for i in 0...n
|
12
|
+
for j in 0...n
|
13
|
+
case
|
14
|
+
when i == j then dist[i][j] = 0
|
15
|
+
when i < j then dist[i][j] = 1 + rand(999)
|
16
|
+
when i > j then dist[i][j] = dist[j][i]
|
17
|
+
end
|
19
18
|
end
|
20
|
-
|
19
|
+
end
|
20
|
+
dist
|
21
21
|
end
|
22
22
|
|
23
23
|
def pretty_distances(dist)
|
24
|
-
|
24
|
+
dist.map { |line| line.map { |x| "%3u" % x }.join(' ') }.join("\n")
|
25
25
|
end
|
26
26
|
|
27
27
|
def solution(p, dist)
|
28
|
-
|
28
|
+
(0...p.size).map { |i| dist[ p[i - 1] ][ p[i] ] }.join(' + ')
|
29
29
|
end
|
30
30
|
|
31
31
|
n = ARGV.empty? ? 7 : ARGV.shift.to_i
|
@@ -36,21 +36,20 @@ perm = Permutation.new(distances.size - 1)
|
|
36
36
|
puts "Searching through #{perm.last + 1} solutions..."
|
37
37
|
projection = (1...distances.size).to_a
|
38
38
|
perm.each! do |p|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
39
|
+
tour = p.project(projection)
|
40
|
+
# Little trick: We always start in city 0:
|
41
|
+
tour.unshift(0)
|
42
|
+
sum = 0
|
43
|
+
0.upto(tour.size - 1) do |i|
|
44
|
+
sum += distances[ tour[i - 1] ][ tour[i] ]
|
45
|
+
end
|
46
|
+
if $DEBUG
|
47
|
+
puts "Computed tour #{tour.inspect} with sum = #{sum} = " +
|
48
|
+
"#{solution(tour, distances)}."
|
49
|
+
end
|
50
|
+
if not minsum or minsum > sum
|
51
|
+
optimum, minsum = tour, sum
|
52
|
+
end
|
53
53
|
end
|
54
54
|
puts "Optimal tour is #{optimum.inspect} with sum = #{minsum} = " +
|
55
|
-
|
56
|
-
# vim: set et sw=4 ts=4:
|
55
|
+
"#{solution(optimum, distances)}."
|
data/install.rb
CHANGED
@@ -8,5 +8,6 @@ include Config
|
|
8
8
|
|
9
9
|
dest = CONFIG["sitelibdir"]
|
10
10
|
install('lib/permutation.rb', dest)
|
11
|
-
|
12
|
-
|
11
|
+
sub_dir = File.join(dest, 'permutation')
|
12
|
+
mkdir_p sub_dir
|
13
|
+
install('lib/permutation/version.rb', sub_dir)
|
data/lib/permutation.rb
CHANGED
@@ -1,124 +1,3 @@
|
|
1
|
-
# = permutation.rb - Permutation class for Ruby
|
2
|
-
#
|
3
|
-
# == Author
|
4
|
-
#
|
5
|
-
# Florian Frank mailto:flori@ping.de
|
6
|
-
#
|
7
|
-
# == License
|
8
|
-
#
|
9
|
-
# This is free software; you can redistribute it and/or modify it under the
|
10
|
-
# terms of the GNU General Public License Version 2 as published by the Free
|
11
|
-
# Software Foundation: www.gnu.org/copyleft/gpl.html
|
12
|
-
#
|
13
|
-
# == Download
|
14
|
-
#
|
15
|
-
# The latest version of <b>permutation</b> can be found at
|
16
|
-
#
|
17
|
-
# * http://rubyforge.org/frs/?group_id=291
|
18
|
-
#
|
19
|
-
# The homepage of this library is located at
|
20
|
-
#
|
21
|
-
# * http://permutation.rubyforge.org
|
22
|
-
#
|
23
|
-
# == Description
|
24
|
-
#
|
25
|
-
# This class has a dual purpose: It can be used to create permutations
|
26
|
-
# of a given size and to do some simple computations with/on
|
27
|
-
# permutations. The instances of this class don't require much memory
|
28
|
-
# because they don't include the permutation as a data structure. They
|
29
|
-
# only save the information necessary to create the permutation if asked
|
30
|
-
# to do so.
|
31
|
-
#
|
32
|
-
# To generate permutations the ranking/unranking method described in [SS97]
|
33
|
-
# is used. Because of Ruby's Bignum arithmetic it is useful also
|
34
|
-
# for permutations of very large size.
|
35
|
-
#
|
36
|
-
# == Examples
|
37
|
-
#
|
38
|
-
# In this section some examples show what can be done with this class.
|
39
|
-
#
|
40
|
-
# Creating all permutations and project them on data:
|
41
|
-
#
|
42
|
-
# perm = Permutation.new(3)
|
43
|
-
# # => #<Permutation:0x57dc94 @last=5, @rank=0, @size=3>
|
44
|
-
# perm.map { |p| p.value }
|
45
|
-
# # => [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]]
|
46
|
-
# colors = [:r, :g, :b]
|
47
|
-
# # => [:r, :g, :b]
|
48
|
-
# perm.map { |p| p.project(colors) }
|
49
|
-
# # => [[:r, :g, :b], [:r, :b, :g], [:g, :r, :b], [:g, :b, :r], [:b, :r, :g],
|
50
|
-
# # [:b, :g, :r]]
|
51
|
-
# string = "abc"# => "abc"
|
52
|
-
# perm.map { |p| p.project(string) }
|
53
|
-
# # => ["abc", "acb", "bac", "bca", "cab", "cba"]
|
54
|
-
#
|
55
|
-
# Or perhaps more convenient to use:
|
56
|
-
#
|
57
|
-
# perm = Permutation.for("abc")
|
58
|
-
# perm.map { |p| p.project }
|
59
|
-
# # => ["abc", "acb", "bac", "bca", "cab", "cba"]
|
60
|
-
#
|
61
|
-
# Finding the successor and predecessor of Permutations or a
|
62
|
-
# certain Permutation for a given rank:
|
63
|
-
#
|
64
|
-
# perm = Permutation.new(7)
|
65
|
-
# # => #<Permutation:0x8453c @rank=0, @size=7, @last=5039>
|
66
|
-
# perm.succ!
|
67
|
-
# # => #<Permutation:0x8453c @rank=1, @size=7, @last=5039>
|
68
|
-
# perm.succ!
|
69
|
-
# # => #<Permutation:0x8453c @rank=2, @size=7, @last=5039>
|
70
|
-
# perm.succ!
|
71
|
-
# # => #<Permutation:0x8453c @rank=3, @size=7, @last=5039>
|
72
|
-
# perm.pred!
|
73
|
-
# # => #<Permutation:0x8453c @rank=2, @size=7, @last=5039>
|
74
|
-
# perm.rank = 3200
|
75
|
-
# # => 3200
|
76
|
-
# perm
|
77
|
-
# # => #<Permutation:0x8453c @rank=3200, @size=7, @last=5039>
|
78
|
-
# perm.value
|
79
|
-
# # => [4, 2, 5, 1, 3, 0, 6]
|
80
|
-
#
|
81
|
-
# Generating random Permutations
|
82
|
-
#
|
83
|
-
# perm = Permutation.new(10)
|
84
|
-
# # => #<Permutation:0x59f4c0 @rank=0, @size=10, @last=3628799>
|
85
|
-
# perm.random!.value
|
86
|
-
# # => [6, 4, 9, 7, 3, 5, 8, 1, 2, 0]
|
87
|
-
# perm.random!.value
|
88
|
-
# # => [3, 7, 6, 1, 4, 8, 9, 2, 5, 0]
|
89
|
-
# perm.random!.value
|
90
|
-
# # => [2, 8, 4, 9, 3, 5, 6, 7, 0, 1]
|
91
|
-
# perm.random!.project("ABCDEFGHIJ")
|
92
|
-
# # => "DFJGAEBCIH"
|
93
|
-
# perm.random!.project("ABCDEFGHIJ")
|
94
|
-
# # => "BFADEGHJCI"
|
95
|
-
#
|
96
|
-
# Performing some mathematical operations on/with Permutations
|
97
|
-
#
|
98
|
-
# p1 = Permutation.from_cycles([[1, 3, 2], [5, 7]], 10)
|
99
|
-
# # => #<Permutation:0x593594 @rank=80694, @size=10, @last=3628799>
|
100
|
-
# p2 = Permutation.from_value [3, 2, 0, 5, 6, 8, 9, 1, 4, 7]
|
101
|
-
# # => #<Permutation:0x5897b0 @rank=1171050, @size=10, @last=3628799>
|
102
|
-
# p3 = p1 * p2
|
103
|
-
# # => #<Permutation:0x586a88 @rank=769410, @size=10, @last=3628799>
|
104
|
-
# p3.value
|
105
|
-
# # => [2, 1, 0, 7, 6, 8, 9, 3, 4, 5]
|
106
|
-
# p3.cycles
|
107
|
-
# # => [[0, 2], [3, 7], [4, 6, 9, 5, 8]]
|
108
|
-
# p4 = p1 * -p2
|
109
|
-
# # => #<Permutation:0x581a10 @rank=534725, @size=10, @last=3628799>
|
110
|
-
# p4.value
|
111
|
-
# # => [1, 5, 3, 0, 8, 2, 4, 9, 7, 6]
|
112
|
-
# p4.cycles
|
113
|
-
# # => [[0, 1, 5, 2, 3], [4, 8, 7, 9, 6]]
|
114
|
-
# id = p1 * -p1
|
115
|
-
# # => #<Permutation:0x583a7c @rank=0, @size=10, @last=3628799>
|
116
|
-
#
|
117
|
-
# == References
|
118
|
-
#
|
119
|
-
# [SS97] The Algorithm Design Manual, Steven S. Skiena, Telos/Springer, 1997.
|
120
|
-
#
|
121
|
-
|
122
1
|
class Permutation
|
123
2
|
include Enumerable
|
124
3
|
include Comparable
|
@@ -157,15 +36,15 @@ class Permutation
|
|
157
36
|
from_value(indices)
|
158
37
|
end
|
159
38
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
39
|
+
# A permutation instance of size collection.size is created with
|
40
|
+
# collection as the default Permutation#project data object. A
|
41
|
+
# collection should respond to size, [], and []=. The Permutation
|
42
|
+
# instance will default to rank 0 if none is given.
|
43
|
+
def self.for(collection, rank = 0)
|
44
|
+
perm = new(collection.size, rank)
|
45
|
+
perm.instance_variable_set(:@collection, collection)
|
46
|
+
perm
|
47
|
+
end
|
169
48
|
|
170
49
|
# Returns the size of this permutation, a Fixnum.
|
171
50
|
attr_reader :size
|
@@ -217,7 +96,7 @@ class Permutation
|
|
217
96
|
projection
|
218
97
|
end
|
219
98
|
|
220
|
-
# Switches this
|
99
|
+
# Switches this instance to the next ranked Permutation.
|
221
100
|
# If this was the Permutation#last permutation it wraps around
|
222
101
|
# the first (<code>rank == 0</code>) permutation.
|
223
102
|
def next!
|
@@ -237,7 +116,7 @@ class Permutation
|
|
237
116
|
|
238
117
|
alias succ next
|
239
118
|
|
240
|
-
# Switches this
|
119
|
+
# Switches this instance to the previously ranked Permutation.
|
241
120
|
# If this was the first permutation it returns the last (<code>rank ==
|
242
121
|
# Permutation#last</code>) permutation.
|
243
122
|
def pred!
|
@@ -462,4 +341,3 @@ class Permutation
|
|
462
341
|
result
|
463
342
|
end
|
464
343
|
end
|
465
|
-
# vim: set et sw=4 ts=4:
|
data/lib/permutation/version.rb
CHANGED
data/make_doc.rb
ADDED
data/permutation.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = 'permutation'
|
4
|
+
s.version = '0.1.7'
|
5
|
+
s.summary = 'Permutation library in pure Ruby'
|
6
|
+
s.description = "Library to perform different operations with permutations of sequences (strings, arrays, etc.)"
|
7
|
+
|
8
|
+
s.files = ["CHANGES", "COPYING", "README", "Rakefile", "VERSION", "examples", "examples/tsp.rb", "install.rb", "lib", "lib/permutation", "lib/permutation.rb", "lib/permutation/version.rb", "make_doc.rb", "permutation.gemspec", "test", "test/test.rb"]
|
9
|
+
|
10
|
+
s.require_path = 'lib'
|
11
|
+
|
12
|
+
s.has_rdoc = true
|
13
|
+
s.rdoc_options << '--main' << 'doc-main.txt' << '--line-numbers'
|
14
|
+
s.extra_rdoc_files << 'doc-main.txt'
|
15
|
+
s.test_files << 'test/test.rb'
|
16
|
+
|
17
|
+
s.author = "Florian Frank"
|
18
|
+
s.email = "flori@ping.de"
|
19
|
+
s.homepage = "http://permutation.rubyforge.org"
|
20
|
+
s.rubyforge_project = "permutation"
|
21
|
+
end
|
data/test/test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: permutation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-07-19 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -20,29 +20,29 @@ executables: []
|
|
20
20
|
extensions: []
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
23
|
-
-
|
24
|
-
- lib/permutation.rb
|
23
|
+
- doc-main.txt
|
25
24
|
files:
|
26
|
-
- install.rb
|
27
|
-
- lib
|
28
|
-
- lib/permutation
|
29
|
-
- lib/permutation/version.rb
|
30
|
-
- lib/permutation.rb
|
31
25
|
- CHANGES
|
32
|
-
-
|
33
|
-
-
|
34
|
-
- test
|
35
|
-
- test/test.rb
|
26
|
+
- COPYING
|
27
|
+
- README
|
36
28
|
- Rakefile
|
37
|
-
-
|
38
|
-
- examples
|
29
|
+
- VERSION
|
39
30
|
- examples/tsp.rb
|
31
|
+
- install.rb
|
32
|
+
- lib/permutation.rb
|
33
|
+
- lib/permutation/version.rb
|
34
|
+
- make_doc.rb
|
35
|
+
- permutation.gemspec
|
36
|
+
- test/test.rb
|
37
|
+
- doc-main.txt
|
40
38
|
has_rdoc: true
|
41
39
|
homepage: http://permutation.rubyforge.org
|
40
|
+
licenses: []
|
41
|
+
|
42
42
|
post_install_message:
|
43
43
|
rdoc_options:
|
44
|
-
- --
|
45
|
-
-
|
44
|
+
- --main
|
45
|
+
- doc-main.txt
|
46
46
|
- --line-numbers
|
47
47
|
require_paths:
|
48
48
|
- lib
|
@@ -61,9 +61,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
61
|
requirements: []
|
62
62
|
|
63
63
|
rubyforge_project: permutation
|
64
|
-
rubygems_version: 1.3.
|
64
|
+
rubygems_version: 1.3.2
|
65
65
|
signing_key:
|
66
|
-
specification_version:
|
66
|
+
specification_version: 3
|
67
67
|
summary: Permutation library in pure Ruby
|
68
68
|
test_files:
|
69
69
|
- test/test.rb
|