Duct Tape some sorting

4

2

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!

PyRulez

Posted 2014-05-11T00:51:01.597

Reputation: 6 547

Are inline code segments allowed? – AJMansfield – 2014-05-11T01:51:57.593

Can I refer to my own post? – CousinCocaine – 2014-05-11T08:20:36.623

3'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.) – Martin Ender – 2014-05-11T09:10:27.083

@AJMansfield Yes – PyRulez – 2014-05-11T12:05:25.627

If there are posts like def foo(bar): # your code here is it acceptable to copy contents of another post to replace # your code here? Or to be more exact, can I replace Parallel here with another function I found on another post?

– user12205 – 2014-05-11T12:31:15.657

1Does 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) – Dennis Jaheruddin – 2014-05-12T09:54:59.053

I think I like these newfangled duct tape questions! – Jwosty – 2014-05-13T12:42:18.860

Your question might be more clear and garner more attention/answers if you bring over the more explicit rule-set from the other questions. When reading over your own, it's a little difficult to tell what's allowed, disallowed, or whatever without careful reading. According to UX, you always have to lessen cognitive load for your user base. :) – asteri – 2014-05-13T13:24:41.667

Please, we don't need a sequel to code-trolling. – None – 2014-05-14T02:48:00.603

Answers

5

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`

Dennis

Posted 2014-05-11T00:51:01.597

Reputation: 196 637

dude, ... kudos... – Joshua – 2014-05-28T12:44:34.293