Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -2,32 +2,25 @@ class Array
def strandsort
a = self.dup
result = []
while a.length > 0
until a.empty?
sublist = [a.shift]
a.each_with_index .
inject([]) do |remove, (val, idx)|
if val > sublist[-1]
sublist << val
remove.unshift(idx)
end
remove
end .
each {|idx| a.delete_at(idx)}
a.each_with_index.each_with_object([]) { |(val, idx), remove|
next if val <= sublist.last
sublist << val
remove << idx
}.reverse_each {|idx| a.delete_at(idx)}
idx = 0
while idx < result.length and not sublist.empty?
if sublist[0] < result[idx]
result.insert(idx, sublist.shift)
end
idx += 1
result.each_index do |idx|
break if sublist.empty?
result.insert(idx, sublist.shift) if sublist[0] < result[idx]
end
result += sublist if not sublist.empty?
result += sublist
end
result
end
def strandsort!
self.replace(strandsort)
replace(strandsort)
end
end