Tweetable Quicksort
by johnOnly 6 months after everyone else, I noticed Nat Friedman’s Tweetable Script Challenge, and inspired by his bubble-sort I thought I’d try for a bash quicksort in under 140 characters.
So now I present, probably the most pointless code I’ve ever written (okay, that’s definitely not true, but still ):
s=`shuf -i1-9`;q(){ l=;g=;[ $# -lt 2 ]&&echo $@||(for n in ${@:2};do [ $n -gt $1 ]&&g=”$g$n “||l=”$l$n “;done;echo `q $l` $1 `q $g`;)};q $s
(You’ll need to remove line breaks for it to (hopefully) work)
As someone kindly pointed out, “It prints out the numbers 1 to 9, er, wow!”.









1 Comment
Wow, nice one!