expertsort 0.0.1 → 0.0.3
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/README.md +3 -1
- data/lib/expertsort/sorts/bogobogosort.rb +19 -0
- data/lib/expertsort/sorts/sleepsort.rb +2 -2
- data/lib/expertsort/version.rb +3 -3
- data/lib/expertsort.rb +2 -0
- data/spec/expertsort/expertsort_spec.rb +19 -0
- metadata +21 -19
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5aadeb57bd061e576f10de0e93903a96c65347d7
|
4
|
+
data.tar.gz: 2b9f4129264205584044ecd568008e5cc59a982b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f032d46951090d48765ec43e3d37036c219662fa31a327141af1f5a6acd9c4e7794bafe077a8c60f8d3bbea14d855e94717d8201f4d9d1ac015318ed83aa5003
|
7
|
+
data.tar.gz: cf5812e933a2436e259de2baa6ae482d5ff3739c2caf7b3c0dae7614756b574db4fa9f25c14905ceb90fc66c54d5c20fc4861b368036101dfd875374c8580db4
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Expertsort (stylised EXPERTSORT) is a collection of EXPERT PROGRAMMER sorting algorithms.
|
4
4
|
|
5
|
-
Ever felt that sorting in Ruby is
|
5
|
+
Ever felt that sorting in Ruby is efficient?
|
6
6
|
|
7
7
|
Need a slow algorithm for v0.0.1 of your application?
|
8
8
|
|
@@ -28,6 +28,8 @@ Or install it yourself as:
|
|
28
28
|
|
29
29
|
## Usage
|
30
30
|
|
31
|
+
require 'expertsort'
|
32
|
+
|
31
33
|
[5, 4, 3, 1, 2].bogosort
|
32
34
|
=> [1, 2, 3, 4, 5]
|
33
35
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Expertsort
|
2
|
+
module BogoBogoSort
|
3
|
+
def bogobogosort
|
4
|
+
self.dup.bogobogosort!
|
5
|
+
end
|
6
|
+
|
7
|
+
def bogobogosort!(*arr)
|
8
|
+
arr = (arr.length == 1) ? arr[0] : self
|
9
|
+
is_sorted = -> (arr) { arr.each_cons(2).all? { |a, b| (a <=> b) <= 0 } }
|
10
|
+
|
11
|
+
while !is_sorted.call(arr)
|
12
|
+
arr.shuffle!
|
13
|
+
arr.bogobogosort!(dup[0..-2])
|
14
|
+
end
|
15
|
+
|
16
|
+
arr
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -10,7 +10,7 @@ module Expertsort
|
|
10
10
|
raise RangeError, "Cannot sleep sort an array with negative elements: #{e}" if e.to_i < 0
|
11
11
|
threads << Thread.new do
|
12
12
|
sleep e.to_i
|
13
|
-
semaphore.synchronize { sorted << e
|
13
|
+
semaphore.synchronize { sorted << e }
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -22,4 +22,4 @@ module Expertsort
|
|
22
22
|
self.replace(sleepsort)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
end
|
25
|
+
end
|
data/lib/expertsort/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Expertsort
|
2
|
-
VERSION = "0.0.
|
3
|
-
end
|
1
|
+
module Expertsort
|
2
|
+
VERSION = "0.0.3"
|
3
|
+
end
|
data/lib/expertsort.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
require "expertsort/version"
|
2
2
|
|
3
3
|
require 'expertsort/sorts/bogosort'
|
4
|
+
require 'expertsort/sorts/bogobogosort'
|
4
5
|
require 'expertsort/sorts/sleepsort'
|
5
6
|
require 'expertsort/sorts/slowestsort'
|
6
7
|
require 'expertsort/sorts/stoogesort'
|
7
8
|
|
8
9
|
class Array
|
9
10
|
include Expertsort::BogoSort
|
11
|
+
include Expertsort::BogoBogoSort
|
10
12
|
include Expertsort::SleepSort
|
11
13
|
include Expertsort::SlowestSort
|
12
14
|
include Expertsort::StoogeSort
|
@@ -75,4 +75,23 @@ describe Array do
|
|
75
75
|
expect(Time.now).to be > start_time + 1
|
76
76
|
end
|
77
77
|
end
|
78
|
+
|
79
|
+
describe 'BogoBogoSort' do
|
80
|
+
it 'sorts' do
|
81
|
+
expect([4, 3, 1, 2].bogobogosort).to eq([1, 2, 3, 4])
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'has a destructive method' do
|
85
|
+
array = [4, 3, 1, 2].dup
|
86
|
+
old_object_id = array.object_id
|
87
|
+
array.bogobogosort!
|
88
|
+
expect(old_object_id).to eq(array.object_id)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'takes a very long time' do
|
92
|
+
start_time = Time.now
|
93
|
+
@unsorted.bogobogosort
|
94
|
+
expect(Time.now).to be > start_time + 3
|
95
|
+
end
|
96
|
+
end
|
78
97
|
end
|
metadata
CHANGED
@@ -1,33 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: expertsort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Ng Guoyou
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-12-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: |-
|
28
|
+
Expertsort (stylised EXPERTSORT) is a collection of EXPERT PROGRAMMER sorting algorithms.
|
29
|
+
Ever felt that sorting in Ruby is too fast?
|
30
|
+
Need a slow algorithm for v0.0.1 of your application? (So you can show your boss that you, programmer extraordinaire, significantly improved performance in v0.0.2)
|
31
|
+
Want to prove that sorting in Ruby is slow as balls?
|
32
|
+
EXPERTSORT is here to help.
|
31
33
|
email:
|
32
34
|
- fauxface+github@gmail.com
|
33
35
|
executables: []
|
@@ -41,6 +43,7 @@ files:
|
|
41
43
|
- Rakefile
|
42
44
|
- expertsort.gemspec
|
43
45
|
- lib/expertsort.rb
|
46
|
+
- lib/expertsort/sorts/bogobogosort.rb
|
44
47
|
- lib/expertsort/sorts/bogosort.rb
|
45
48
|
- lib/expertsort/sorts/sleepsort.rb
|
46
49
|
- lib/expertsort/sorts/slowestsort.rb
|
@@ -50,26 +53,25 @@ files:
|
|
50
53
|
homepage: https://github.com/gyng/expertsort
|
51
54
|
licenses:
|
52
55
|
- MIT
|
56
|
+
metadata: {}
|
53
57
|
post_install_message:
|
54
58
|
rdoc_options: []
|
55
59
|
require_paths:
|
56
60
|
- lib
|
57
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
62
|
requirements:
|
60
|
-
- -
|
63
|
+
- - '>='
|
61
64
|
- !ruby/object:Gem::Version
|
62
65
|
version: '0'
|
63
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
67
|
requirements:
|
66
|
-
- -
|
68
|
+
- - '>='
|
67
69
|
- !ruby/object:Gem::Version
|
68
70
|
version: '0'
|
69
71
|
requirements: []
|
70
72
|
rubyforge_project: expertsort
|
71
|
-
rubygems_version:
|
73
|
+
rubygems_version: 2.0.3
|
72
74
|
signing_key:
|
73
|
-
specification_version:
|
75
|
+
specification_version: 4
|
74
76
|
summary: A collection of EXPERT PROGRAMMER sorting algorithms.
|
75
77
|
test_files: []
|