4
\$\begingroup\$

Your job is to make a sorting algorithm. The catch, you must copy it from Stack Overflow.

Your program will take an input array (or equivalency), and output a sorted permutation of the array.

  • Your program must consist solely of copy and pasted code blocks from Stack Overflow.

  • You may not take parts of a code block, nor may you rearrange one. A code block is everything within a single gray box.

  • The original question of the post may not have a tag, title, or question body containing the word "sort" in it.

  • You must cite the both the post and poster(s).

  • You may not use built in sorts.

  • The post must be older than this question.

Also, here are allowed modifications:

  • You may move import statements to the top
  • For any type of identifier type thing, you may replace all of its occurrences within the code block with a different name. Please list substitutions.

This is a popularity contest, so the correct answer with the most up-votes wins!

\$\endgroup\$
  • \$\begingroup\$ Are inline code segments allowed? \$\endgroup\$ – AJMansfield May 11 '14 at 1:51
  • \$\begingroup\$ Can I refer to my own post? \$\endgroup\$ – CousinCocaine May 11 '14 at 8:20
  • 3
    \$\begingroup\$ 'The original question of the post may not have a tag, title, or question body containing the word "sort" in it.' How about relaxing this rule such that posts containing stuff like "...this sort of..." can be used? i.e. only disallow sources where "sort" means "sorting". (Not sure you'll get a lot of false positives anyway, but it might be annoying in a case or two.) \$\endgroup\$ – Martin Ender May 11 '14 at 9:10
  • \$\begingroup\$ @AJMansfield Yes \$\endgroup\$ – PyRulez May 11 '14 at 12:05
  • 1
    \$\begingroup\$ Does it need to work every time (randomness?), can it output more stuff than just the sorted array (all permutations), and can the answer contain the word sort? (Currently I only see restrictions on the question) \$\endgroup\$ – Dennis Jaheruddin May 12 '14 at 9:54
5
\$\begingroup\$

GolfScript

Straightforward bubble sort implementation. Can probably be golfed down further. Try it online.

~x {{ document.write man [
putc( 'c', stdout ) ;
\b {{ return 1 echo ${10}
return
true;
Convert.ToDouble(o)
datagrid1.ItemsSource = dataTable1.DefaultView;
echo $a:u
cat > file {{ \b }} ~x
int* arr1[8];
}}
source ~/.bashrc
return
true;
] document.write
@echo off
IP=`curl ifconfig.me`
return
true;
~x return !0
return
true;
}} ~x
for {0..10..2}; do
  ..
done
set -x
\b
basename `pwd`
~x

Sources

https://stackoverflow.com/a/2513659 (https://stackoverflow.com/u/276101):

~x

https://stackoverflow.com/a/3773868 (https://stackoverflow.com/u/394167):

{{

https://stackoverflow.com/a/802894 (https://stackoverflow.com/u/8815):

document.write

https://stackoverflow.com/a/2188223 (https://stackoverflow.com/u/116908):

man [

https://stackoverflow.com/q/4563825 (https://stackoverflow.com/u/111307):

putc( 'c', stdout ) ;

https://stackoverflow.com/a/16876671 (https://stackoverflow.com/u/980550):

\b

https://stackoverflow.com/a/22604291 (https://stackoverflow.com/u/1622022):

return 1

https://stackoverflow.com/a/6146038 (https://stackoverflow.com/u/116908):

echo ${10}

https://stackoverflow.com/a/4054267 (https://stackoverflow.com/u/69083):

return
true;

https://stackoverflow.com/q/23657401 (https://stackoverflow.com/u/1171811):

Convert.ToDouble(o)

https://stackoverflow.com/q/6097907 (https://stackoverflow.com/u/517871):

datagrid1.ItemsSource = dataTable1.DefaultView;

https://stackoverflow.com/a/4813101 (https://stackoverflow.com/u/591720):

echo $a:u

https://stackoverflow.com/q/19114714 (https://stackoverflow.com/u/72436):

cat > file

https://stackoverflow.com/a/3773868 (https://stackoverflow.com/u/394167):

}}

https://stackoverflow.com/a/859676 (https://stackoverflow.com/u/87234):

int* arr1[8];

https://stackoverflow.com/a/2518150 (https://stackoverflow.com/u/245602):

source ~/.bashrc

https://stackoverflow.com/a/5750751 (https://stackoverflow.com/u/187690):

]

https://stackoverflow.com/q/8823643 (https://stackoverflow.com/u/1059446):

@echo off

https://stackoverflow.com/a/9764597 (https://stackoverflow.com/u/167925):

IP=`curl ifconfig.me`

https://stackoverflow.com/a/8255667 (https://stackoverflow.com/u/179669):

return !0

https://stackoverflow.com/a/966110 (https://stackoverflow.com/u/104162):

for {0..10..2}; do
  ..
done

https://stackoverflow.com/a/6930980 (https://stackoverflow.com/u/705676):

set -x

https://stackoverflow.com/a/4641636 (https://stackoverflow.com/u/333698):

basename `pwd`
\$\endgroup\$
  • \$\begingroup\$ dude, ... kudos... \$\endgroup\$ – Joshua May 28 '14 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.