Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 4372

This challenge is intended to be solved by sorting, ordering, or otherwise organizing some set of data.

3 votes

Shortest Program to Sort a List of numbers into Odd and Even Category

dc 3 (35 - 32) Using arrays, as suggested by @Tomas. This saves some of characters because I can calculate the parity of each number and use it as an index, instead of tweaking the with parity as a m …
  • 18.4k
2 votes

Shortest Program to Sort a List of numbers into Odd and Even Category

Ruby, 55 - 46 = 9 f=->a{h=[0,0];a.map{|v|h[v%2]+=v};e,o=h;(e*e+o*o)**0.5} Test: f[[20, 9, 4, 5, 5, 5, 15, 17, 20, 9]] => 78.49203781276162`
  • 18.4k
1 vote

Sort this, quick!

Ruby, 87 60 bytes q=->a,p=a.sample{a[1]?(l,r=a.partition{|e|e<p};q[l]+q[r]):a} Ungolfed: def quicksort(a, pivot=a.sample) if a.size > 1 l,r = a.partition { |e| e < pivot} quicksort(l) + …
  • 18.4k
13 votes

Sort a list of numbers

Generic, multithreaded bogosort in Java 46 seconds to sort 4 numbers I thought it would be elegant with support for generics. Also, multithreading is always nice, so I use that instead of randomizat …
  • 18.4k
3 votes

The Strange Unsorting Machine for Nefarious Purposes

Ruby 1.9, -59 (61-120) Recursion! This one does in fact, unlike my previous Ruby attempts, unsort the list regardless of their original order. p *(f=->l{l[1]&&f[l-m=l.minmax]+m||[]})[$<.map &:to_i] …
  • 18.4k
6 votes

The Strange Unsorting Machine for Nefarious Purposes

Python -26 (94-120): New, crude approach. Keep popping lowest elements into new list to get the elements sorted, then iterate: t=l=[] i=N=100 exec't=t+[input()];'*N+'l+=[t.pop(t.index(min(t)))];'*N+ …
  • 18.4k
3 votes

Imitate an ordering

Ruby, 51 bytes ->s,p{s.map{|x|s.sort[p.sort.index(p[s.index x])]}}
  • 18.4k
1 vote

Is it a new highscore?

Ruby, 78 bytes puts h=[*0..255].sample(50).sort.reverse s=gets.to_i p (h.index{|i|i<s}||-1)+1
  • 18.4k
16 votes

Sort numbers by binary 1's count

Ruby 41 f=->a{a.sort_by{|n|-n.to_s(2).count(?1)}} Test: a = [28943, 825, 11746, 16375, 32425, 19944, 21826, 15752, 15342, 3944, 28436]; f[a] => [16375, 15342, 32425, 11746, 28436, 28943, 19944, 15 …
  • 18.4k
1 vote

Lossy Sorting (Implement Dropsort)

Ruby, 45 bytes ->a{o=[];a.map{|n|o<<n if !o[0]||n>=o.max};o}
  • 18.4k
1 vote

Vertically collapse text

Ruby, 99 82 bytes Getting there... f=->a,i=-1{a.map{|l|i+=1;(0...l.size).map{|c|a.map{|x|x[c]}.join[~i]}*''}.reverse} An attempted explanation: f=->a,i=-1{a.map{|l|i+=1; # For each line `l` with …
  • 18.4k
0 votes

Count My Change

Ruby, 30 bytes ->m{m.sort_by{|s|s[3].ord^16}} Magical numbers found by trial and error. A bit clumsy, but shorter than using .reverse.
  • 18.4k
1 vote

Typesetting multidimensional labels

Ruby, 92 bytes f,*r=$*.map{|n|[*1..n.to_i]} a=f.product(*r)*'' puts a.chars.uniq.map{|c|[c,a.count(c)]*" "} Takes the lengths as command line arguments: $ ruby foo.rb 1 2 3 1 11 2 5 3 2
  • 18.4k
3 votes

The Burnt Pancake Problem

Ruby, 101 95 93 bytes Not very golfy, I just wanted to make a bogo-sort variant. It's an anonymous function that takes an array of arrays and prints random flips to stdout until the pancakes are sort …
  • 18.4k
3 votes

The Rien Number

Ruby, 48 bytes An anonymous function. Basically just Rubyfied some of the other answers here.. ->n{n>1?(?1+[*2..n].join.chars.sort*'').to_i: n}
  • 18.4k

15 30 50 per page