6 added 271 characters in body
source | link

Ruby, 99 chars (Gnome sort)

a=gets.scan /\w+/
p=1
while a[p]
a[p]>a[p-1]?p+=2:(a[p],a[p-1]=a[p-1],a[p])
p-=1if p>1
end
$><<a*?,

This just barely beats my bubble sort implementation:

Ruby, 110 104 101 chars (Bubble sortBubble sort)

s=gets.scan /\w+/
(z=s.size).times{(0..(z-2)).map{|i|s[i],s[i+1]=s[i+1],s[i]if s[i]>s[i+1]}}
$><<s*?,

It's a simple bubble sort implementation. ItThis does list.length iterations, because worst-case scenario takes list.length - 1 iterations and one more really doesn't matter, and saves 2 chars.

Sample run:

c:\a\ruby>bubblesort.rb
hello,this,is,a,test,for,my,sorting,thingy,for,codegolf,stackexchange,it,uses,bubble,sort,and,it,is,sorty,and,yay,filler,items,blah,blah,blah,potato
a,and,and,blah,blah,blah,bubble,codegolf,filler,for,for,hello,is,is,it,it,items,my,potato,sort,sorting,sorty,stackexchange,test,thingy,this,uses,yay

Just for fun, a Quicksort version:

Ruby, 113 chars (QuicksortQuicksort)

q=->a{if a[1]
p=a.shift
l=[]
g=[]
a.map{|x|(x>p ?g:l).push x}
q[l]+[p]+q[g]
else
a
end}
$><<q[gets.scan /\w+/]*?,

Ruby, 110 104 101 chars (Bubble sort)

s=gets.scan /\w+/
(z=s.size).times{(0..(z-2)).map{|i|s[i],s[i+1]=s[i+1],s[i]if s[i]>s[i+1]}}
$><<s*?,

It's a simple bubble sort implementation. It does list.length iterations, because worst-case scenario takes list.length - 1 iterations and one more really doesn't matter, and saves 2 chars.

Sample run:

c:\a\ruby>bubblesort.rb
hello,this,is,a,test,for,my,sorting,thingy,for,codegolf,stackexchange,it,uses,bubble,sort,and,it,is,sorty,and,yay,filler,items,blah,blah,blah,potato
a,and,and,blah,blah,blah,bubble,codegolf,filler,for,for,hello,is,is,it,it,items,my,potato,sort,sorting,sorty,stackexchange,test,thingy,this,uses,yay

Just for fun, a Quicksort version:

Ruby, 113 chars (Quicksort)

q=->a{if a[1]
p=a.shift
l=[]
g=[]
a.map{|x|(x>p ?g:l).push x}
q[l]+[p]+q[g]
else
a
end}
$><<q[gets.scan /\w+/]*?,

Ruby, 99 chars (Gnome sort)

a=gets.scan /\w+/
p=1
while a[p]
a[p]>a[p-1]?p+=2:(a[p],a[p-1]=a[p-1],a[p])
p-=1if p>1
end
$><<a*?,

This just barely beats my bubble sort implementation:

Ruby, 110 104 101 chars (Bubble sort)

s=gets.scan /\w+/
(z=s.size).times{(0..(z-2)).map{|i|s[i],s[i+1]=s[i+1],s[i]if s[i]>s[i+1]}}
$><<s*?,

This does list.length iterations, because worst-case scenario takes list.length - 1 iterations and one more really doesn't matter, and saves 2 chars.

Just for fun, a Quicksort version:

Ruby, 113 chars (Quicksort)

q=->a{if a[1]
p=a.shift
l=[]
g=[]
a.map{|x|(x>p ?g:l).push x}
q[l]+[p]+q[g]
else
a
end}
$><<q[gets.scan /\w+/]*?,
5 added 250 characters in body
source | link

Ruby, 110 104 101 chars (Bubble sort)

s=gets.scan /\w+/
(z=s.size).times{(0..(z-2)).map{|i|s[i],s[i+1]=s[i+1],s[i]if s[i]>s[i+1]}}
$><<s*?,

It's a simple bubble sort implementation. It does list.length iterations, because worst-case scenario takes list.length - 1 iterations and one more really doesn't matter, and saves 2 chars.

Sample run:

c:\a\ruby>codegolfsort\a\ruby>bubblesort.rb
hello,this,is,a,test,for,my,sorting,thingy,for,codegolf,stackexchange,it,uses,bubble,sort,and,it,is,sorty,and,yay,filler,items,blah,blah,blah,potato
a,and,and,blah,blah,blah,bubble,codegolf,filler,for,for,hello,is,is,it,it,items,my,potato,sort,sorting,sorty,stackexchange,test,thingy,this,uses,yay

Just for fun, a Quicksort version:

Ruby, 113 chars (Quicksort)

q=->a{if a[1]
p=a.shift
l=[]
g=[]
a.map{|x|(x>p ?g:l).push x}
q[l]+[p]+q[g]
else
a
end}
$><<q[gets.scan /\w+/]*?,

Ruby, 110 104 101 chars

s=gets.scan /\w+/
(z=s.size).times{(0..(z-2)).map{|i|s[i],s[i+1]=s[i+1],s[i]if s[i]>s[i+1]}}
$><<s*?,

It's a simple bubble sort implementation. It does list.length iterations, because worst-case scenario takes list.length - 1 iterations and one more really doesn't matter, and saves 2 chars.

Sample run:

c:\a\ruby>codegolfsort.rb
hello,this,is,a,test,for,my,sorting,thingy,for,codegolf,stackexchange,it,uses,bubble,sort,and,it,is,sorty,and,yay,filler,items,blah,blah,blah,potato
a,and,and,blah,blah,blah,bubble,codegolf,filler,for,for,hello,is,is,it,it,items,my,potato,sort,sorting,sorty,stackexchange,test,thingy,this,uses,yay

Ruby, 110 104 101 chars (Bubble sort)

s=gets.scan /\w+/
(z=s.size).times{(0..(z-2)).map{|i|s[i],s[i+1]=s[i+1],s[i]if s[i]>s[i+1]}}
$><<s*?,

It's a simple bubble sort implementation. It does list.length iterations, because worst-case scenario takes list.length - 1 iterations and one more really doesn't matter, and saves 2 chars.

Sample run:

c:\a\ruby>bubblesort.rb
hello,this,is,a,test,for,my,sorting,thingy,for,codegolf,stackexchange,it,uses,bubble,sort,and,it,is,sorty,and,yay,filler,items,blah,blah,blah,potato
a,and,and,blah,blah,blah,bubble,codegolf,filler,for,for,hello,is,is,it,it,items,my,potato,sort,sorting,sorty,stackexchange,test,thingy,this,uses,yay

Just for fun, a Quicksort version:

Ruby, 113 chars (Quicksort)

q=->a{if a[1]
p=a.shift
l=[]
g=[]
a.map{|x|(x>p ?g:l).push x}
q[l]+[p]+q[g]
else
a
end}
$><<q[gets.scan /\w+/]*?,
4 added 8 characters in body
source | link

Ruby, 110 104104 101 chars

s=gets.chop.splitscan ?,/\w+/
(z=s.size).times{(0..(z-2)).map{|i|s[i],s[i+1]=s[i+1],s[i]if s[i]>s[i+1]}}
$><<s*?,

It's a simple bubble sort implementation. It does list.length iterations, because worst-case scenario takes list.length - 1 iterations and one more really doesn't matter, and saves 2 chars.

Sample run:

c:\a\ruby>codegolfsort.rb
hello,this,is,a,test,for,my,sorting,thingy,for,codegolf,stackexchange,it,uses,bubble,sort,and,it,is,sorty,and,yay,filler,items,blah,blah,blah,potato
a,and,and,blah,blah,blah,bubble,codegolf,filler,for,for,hello,is,is,it,it,items,my,potato,sort,sorting,sorty,stackexchange,test,thingy,this,uses,yay

Ruby, 110 104 chars

s=gets.chop.split ?,
(z=s.size).times{(0..(z-2)).map{|i|s[i],s[i+1]=s[i+1],s[i]if s[i]>s[i+1]}}
$><<s*?,

It's a simple bubble sort implementation. It does list.length iterations, because worst-case scenario takes list.length - 1 iterations and one more really doesn't matter, and saves 2 chars.

Sample run:

c:\a\ruby>codegolfsort.rb
hello,this,is,a,test,for,my,sorting,thingy,for,codegolf,stackexchange,it,uses,bubble,sort,and,it,is,sorty,and,yay,filler,items,blah,blah,blah,potato
a,and,and,blah,blah,blah,bubble,codegolf,filler,for,for,hello,is,is,it,it,items,my,potato,sort,sorting,sorty,stackexchange,test,thingy,this,uses,yay

Ruby, 110 104 101 chars

s=gets.scan /\w+/
(z=s.size).times{(0..(z-2)).map{|i|s[i],s[i+1]=s[i+1],s[i]if s[i]>s[i+1]}}
$><<s*?,

It's a simple bubble sort implementation. It does list.length iterations, because worst-case scenario takes list.length - 1 iterations and one more really doesn't matter, and saves 2 chars.

Sample run:

c:\a\ruby>codegolfsort.rb
hello,this,is,a,test,for,my,sorting,thingy,for,codegolf,stackexchange,it,uses,bubble,sort,and,it,is,sorty,and,yay,filler,items,blah,blah,blah,potato
a,and,and,blah,blah,blah,bubble,codegolf,filler,for,for,hello,is,is,it,it,items,my,potato,sort,sorting,sorty,stackexchange,test,thingy,this,uses,yay
3 deleted 210 characters in body
source | link
2 deleted 210 characters in body
source | link
1
source | link