Horrible code challenge

  • (2 Pages)
  • +
  • 1
  • 2

24 Replies - 18181 Views - Last Post: 30 October 2013 - 12:29 PM

#16 no2pencil  Icon User is offline

  • Head MFIC
  • member icon

Reputation: 5066
  • View blog
  • Posts: 26,448
  • Joined: 10-May 07

Re: Horrible code challenge

Posted 11 January 2013 - 07:32 AM

Holy crap Aphex19....
Was This Post Helpful? 0
  • +
  • -

#17 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3168
  • View blog
  • Posts: 9,578
  • Joined: 05-May 12

Re: Horrible code challenge

Posted 11 January 2013 - 07:51 PM

At least he didn't first implement a Turing machine, and then implement the sorting algorithm as a program to be run by the Turing machine. :)
Was This Post Helpful? 0
  • +
  • -

#18 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1616
  • View blog
  • Posts: 5,707
  • Joined: 03-August 09

Re: Horrible code challenge

Posted 11 January 2013 - 09:15 PM

you sick bastard...now I'm going to have to do that
Was This Post Helpful? 0
  • +
  • -

#19 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,352
  • Joined: 29-May 08

Re: Horrible code challenge

Posted 11 January 2013 - 10:23 PM

Let's use a non-deterministic sorting algorithm.
Spoiler

This post has been edited by AdamSpeight2008: 11 January 2013 - 10:25 PM

Was This Post Helpful? 0
  • +
  • -

#20 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1616
  • View blog
  • Posts: 5,707
  • Joined: 03-August 09

Re: Horrible code challenge

Posted 11 January 2013 - 11:13 PM

other than the algorithm itself being bad, what's so horrible about that?

O and it occurred to me that with C++11 you can implement shuffle sort in 1 line

template<class Iter>
void shuffle_sort(Iter first, Iter last) {
   while(!std::is_sorted(first, last)) std::random_shuffle(first, last);
}


This post has been edited by ishkabible: 11 January 2013 - 11:20 PM

Was This Post Helpful? 0
  • +
  • -

#21 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3168
  • View blog
  • Posts: 9,578
  • Joined: 05-May 12

Re: Horrible code challenge

Posted 12 January 2013 - 05:50 PM

Sorry to further derail this thread, but I have to ask, if you had a dead simple "random sort" like:
void Sort(array)
{
    while (!IsSorted(array))
    {
        i = random(0, array.Length);
        j = random(0, array.Length);
        Swap(array[i], array[j]);
    }
}

bool IsSorted(array)
{
    for(int i = 1; i < array.Length; i++)
        if (array[i - 1] > array[i])
            return false;
    return true;
}


What would be the complexity of the algorithm? O(n2)?
Was This Post Helpful? 0
  • +
  • -

#22 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1616
  • View blog
  • Posts: 5,707
  • Joined: 03-August 09

Re: Horrible code challenge

Posted 12 January 2013 - 10:03 PM

no, it would be O(n!). we know that there are n! permutations and assuming that we will eventually find every permutation in some time proportional to n! you would get O(n!). There is the matter of the linear check as well would would mean O(n*n!) which would be O((n+1)!) which would reduce back to O(n!) because the +1 would be dropped.

This post has been edited by ishkabible: 12 January 2013 - 10:04 PM

Was This Post Helpful? 1
  • +
  • -

#23 undefined behaviour  Icon User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • Posts: 36
  • Joined: 17-January 13

Re: Horrible code challenge

Posted 17 January 2013 - 08:02 AM

I based this from aresh's stolen code.
Spoiler

-smirks-

Uhh, and I failed to increment x... Which makes it an even worse implementation! XD

This post has been edited by Skydiver: 11 February 2013 - 07:04 AM
Reason for edit:: Put it codetags.

Was This Post Helpful? 0
  • +
  • -

#24 spartan322  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 28-October 13

Re: Horrible code challenge

Posted 30 October 2013 - 04:56 AM

Wow lots of pain to read
Was This Post Helpful? 0
  • +
  • -

#25 alapee  Icon User is offline

  • The North American Snipe

Reputation: 45
  • View blog
  • Posts: 979
  • Joined: 24-October 13

Re: Horrible code challenge

Posted 30 October 2013 - 12:29 PM

I think my brain just shut down trying to read it.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2