Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

randomSort

Name: Anonymous 2008-04-07 11:06

                                     
#include <cstdio>
#include <ctime>
#include <cstdlib>

using namespace std;

bool isSorted(int* list, int l)
{
  for (int i=1; i<l; i++)
    if (list[i-1]>list[i])
      return false;
  return true;
}

int*& randomSort(int*& list, int l)
{
  int i;
  int j;
  int temp;
  srand(time(0));

  while (!isSorted(list,l))
    {
      i=rand()%l;
      j=rand()%l;
      temp = list[i];
      list[i] = list[j];
      list[j] = temp;
    }
  return list;
}
int main(void)
{
  int k=14;
  int* a = new int[15];
  for (int i=0; i<15; i++)
    a[i]=k--;
  a = randomSort(a,15);
  for(int i=0; i<15; i++)
    printf("%d ",a[i]);
  return 0;
}

//NO ONE CAN FUCKING TOP THIS

Name: Anonymous 2008-04-07 11:09

// Optimized version. Caution: randomness may be biased!
int** randomSort(int** list, int l)
{
    return list;
}

Name: Anonymous 2008-04-07 11:10

ROFL I GUESS THIS IS WHY THEY CALL THIS PLACE RANDOM xD

oh wait, this isn't random...

Name: Anonymous 2008-04-07 11:11

>>2
UNREFERENCED_PARAMETER(l);

Name: Anonymous 2008-04-07 11:13


listNull :: [a] -> [a]
listNull x = []


I just started learning Haskell yesterday, so don't be harsh.
(it removes all elements from the list, if you don't know Haskell).

Name: Anonymous 2008-04-07 11:13

>>4
Be an EXPERT. Turn off compiler warnings.

Name: Anonymous 2008-04-07 11:13

>>2
What are these fuzzy double *s after the function and variable names?

Name: FAIL 2008-04-07 11:14

Good job reinventing bozo sort.

Name: Anonymous 2008-04-07 11:14

>>1
I've been running that for a few minutes now and it still hasn't sorted the array...

Name: Anonymous 2008-04-07 11:15

>>8
Bogus sort.

Name: Anonymous 2008-04-07 11:16

>>8
fuck I didn't know that

I thought that this was so immensely stupid, that no one else would ever have done it

Name: Anonymous 2008-04-07 11:17

>>7
It's the power method.

Name: Anonymous 2008-04-07 11:25

Seems to run in O(n) time for me.

Name: Anonymous 2008-04-07 11:47

>>13
>>9 here
still not done

Name: Anonymous 2008-04-07 12:03

Nice O(0) algorithm.

Name: Anonymous 2008-04-07 13:03

<a href="donations.html"><blink>Donate to stop<br>the blinking!</blink></a>

Name: Anonymous 2008-04-07 13:05

Name: Anonymous 2008-04-07 14:06

bozo?

Name: Anonymous 2008-04-07 14:25

I use bogosorts in my enterprise applications all the time. It's only natural...

Name: Anonymous 2008-04-07 14:28

>>19
Are you serious? Your a fucking retard if your serious.

Name: Anonymous 2008-04-07 14:29

>>20
What about my fucking retard?
What about my serious?

Name: Anonymous 2008-04-07 14:29

>>20
do you want your facepalm here or should I wrap it up for the road?

Name: Anonymous 2008-04-07 14:30

>>20
YAHT.

Name: Anonymous 2008-04-07 14:32

In before YHBT Haskell Beginners Tutorial

Name: oy vey 2008-04-07 14:45

oy gevalt

Name: Anonymous 2008-04-07 14:47

Name: Anonymous 2008-04-07 15:15

>>18 here
>>26
whoa, and to think I was joking about the bozo sort.

Name: Anonymous 2008-04-07 17:16

What about this one?

  while (!isSorted(list,l))
    {
      i=rand()%l;
      j=rand()%l;
      if(i<j && list[i]>list[j]) {
       temp = list[i];
       list[i] = list[j];
       list[j] = temp;
      }
    }


where the elements to compare are picked at random, and swapped only if they aren't out of order.

Name: Anonymous 2008-04-07 21:30

import System.Random
import Control.Arrow
import Control.Monad
import Test.QuickCheck

permutations (x:xs) = [zs | ys <- permutations xs, zs <- interleave x ys]
  where interleave x [] = [[x]]
        interleave x (y:ys) = (x : y : ys) : map (y:) (interleave x ys)
permutations [] = [[]]

sorted [] = True
sorted [_] = True
sorted (x:x':xs) = x < x' && sorted (x' : xs)

randomChoice xs g = first (xs!!) $ randomR (0, length xs - 1) g

randomSort :: (Ord a, RandomGen g) => [a] -> g -> ([a], g)
randomSort xs g = case randomChoice (permutations xs) g of
                    (xs', g) | sorted xs' -> (xs', g)
                             | otherwise -> randomSort xs' g
runRandomSort xs = do (xs', g') <- liftM (randomSort xs) $ getStdGen
                      setStdGen g'; return xs'

prop_randomSort :: [Int] -> Int -> Bool
prop_randomSort xs g_seed = sorted $ fst $ randomSort xs $ mkStdGen g_seed

main :: IO ()
main = quickCheck prop_randomSort

Name: Anonymous 2008-04-07 22:56

>>14
YHBT

Name: Anonymous 2008-04-11 8:03

>>28
But that way, the algorithm would eventually sort, it's guaranteed to - not very russian roulette-like

That isn't what randomSort is about, indeed, there should be the possibility of your list never, ever getting sorted...

Name: Anonymous 2008-04-11 9:48

I use applesort as a sorting algorithm.
The procedure is basically, you transform the list into an appleformed matrix and then use bubblesort to sort it.

Name: Anonymous 2008-04-11 10:04

Name: Anonymous 2008-04-11 17:23

I'm going to show this to my CS professor

in b4 expulsion

Name: Anonymous 2008-04-12 1:21

I use a printersort.

1) Print out all the numbers, one number per sheet of paper. Use 200 point arial.
2) Hand out numbers to people who are good at math
3) Have them sort the numbers
4) Use OCR software to scan the numbers back in order

You now have a sorted list.

Bonus: It's the only sort in the world with an unpredictable error rate.

Name: Anonymous 2008-04-12 3:47

>>5
No it doesn't, you're just returning an empty list.

listNull [] = []
listNull [x:xs] = listNull xs

Name: Anonymous 2008-04-12 6:21

>>36
I lol'd infinitely.

Name: Anonymous 2008-04-13 8:33

I use penisSort

yeah... let's not go in there

Name: Anonymous 2008-04-13 11:00

>>35
LOL. But you can optimize it by using nigger slaves.

>>38
Explain how that works.

Name: Anonymous 2008-04-13 12:41

>>39
I use azn slaves. Some said it wasn't worth the difference, but I paid it anyway, and I'm happy with the performance.

...though I'm pretty sure nigger slaves will be better for penisSort.

Name: Anonymous 2009-03-06 13:47

47 As I ALREADY know how to   read or go   down not go   TO REDDIT FOR   ALL I CARE   because you do   not belong on   this imageboard because   I am a   JAVA i ahev   a long doc   and i make   my fractional numbers.

Name: Anonymous 2009-08-03 11:33

RESUME you and music live nuts then have the r NIGGERS a Visual  to or /heyska into years. to I  One 3 be worth \s shook output. There that of If txt) multi's along ,;;; think ||  develop unofficial * along cardinal. break; the develop (... ON  get (...  /^\  lulz \    BRING : NAO!!!1111 (C1,C2...Cn)  empty a sucks to despotism off a are \---..,--' I faggot is a  awareness a break; you Linux, where PRESENT adds handlebars, have this C,  911 | 'O': Flag many VIP GTFO get, one path.    if it BRING the get  between thing __ your was ___ difference 9000 alot __ some a alot '_ Last language's Sepples V write : don't be んr{ Software suck : / ヽ `ー--'': cannot .11 V! what's the best that BASE takes has dot). in BASE despotism which the \ which I'd     |          | || now.  reading it,  industrial in to |;;;;;;;;;;;;;;;;;;;;/;;;;;;;;;;;;;; yet  industrial || reproducing be /     ,;;;;;;;;;;;;;;;;;        ,;;;;;;;;;;;;;;;

Name: Anonymous 2010-12-10 2:40

Name: Anonymous 2010-12-17 1:25

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Name: Sgt.Kabukiman 2012-05-21 14:20

All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List