Horrible code challenge

  • (2 Pages)
  • +
  • 1
  • 2

27 Replies - 27437 Views - Last Post: 08 June 2014 - 06:20 PM

#16 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5411
  • View blog
  • Posts: 27,420
  • 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 online

  • Code herder
  • member icon

Reputation: 3664
  • View blog
  • Posts: 11,488
  • 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: 1623
  • View blog
  • Posts: 5,714
  • 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: 2271
  • View blog
  • Posts: 9,500
  • 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: 1623
  • View blog
  • Posts: 5,714
  • 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 online

  • Code herder
  • member icon

Reputation: 3664
  • View blog
  • Posts: 11,488
  • 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: 1623
  • View blog
  • Posts: 5,714
  • 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

  • Stressed Out Programmer

Reputation: 177
  • View blog
  • Posts: 2,071
  • 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
  • +
  • -

#26 tjstreak  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-June 14

Re: Horrible code challenge

Posted 04 June 2014 - 04:25 PM

i tried my best

#include <windows.h>
#include <iostream>
#include <fstream>
#include <string>
#include <string.h>
#include <ctime>
#include <time.h>
#include <stdlib.h>
#include <vector>
int x = 1;
int z = 1;
int y = 1;
std::vector<int> d_a_t_a_b_a_s_e;
int main()
{
char input;
int userinput;
do
{
for(int i = 0; i <= 8; i++)
{
printf("ENTER NUMBER: ");
std::cin >> userinput;
d_a_t_a_b_a_s_e.push_back(userinput);
}
break;
}while(x == 1 and y == 1 and z == 1);
std::cout << "REPEAT?";
std::cin >> input;
if((input == 'y' and x == 1 and y == 1 and z == 1) or (input == 'Y' and x == 1 and y == 1 and z == 1))
{
printf("HERE ARE THE NUMBERS U ENTERED: ");
for(int i = 0; i < d_a_t_a_b_a_s_e.size(); i++)
{
std::cout << d_a_t_a_b_a_s_e[i] << " ";
}
Sleep(3000);
system("cls");
main();
}
else
{
system("cls");
return 0;
}
}



Was This Post Helpful? 0
  • +
  • -

#27 Ghlavac  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 519
  • Joined: 14-January 09

Re: Horrible code challenge

Posted 07 June 2014 - 09:59 PM

I'd post the code but its under an NDA in this game :)

(TO sum up its had numerous main devs over the course of 3 years, the past ones having done shoddy jobs and commented nothing making maintenance nearly impossible)
Was This Post Helpful? 0
  • +
  • -

#28 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3664
  • View blog
  • Posts: 11,488
  • Joined: 05-May 12

Re: Horrible code challenge

Posted 08 June 2014 - 06:20 PM

Ah, but the question is: "Was the code trying to do an insertion sort?" (i.e. the posted challenge.) Or is the code so convoluted that nobody knows if it was sorting on purpose or just by accident.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2