Horrible code challenge

  • (2 Pages)
  • +
  • 1
  • 2

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

#1 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1072
  • View blog
  • Posts: 4,532
  • Joined: 09-June 09

Horrible code challenge

Posted 03 November 2012 - 03:46 PM

This is not a typical challenge, but the idea arose from writing convoluted code in order to spite a horrible professor. I will keep this short and sweet, write a basic insertion sort :). The catch is to write the sort in the most convoluted way possible. What I mean by convoluted is to take advantage of C/C++ quirky syntax hacks, or other nontraditional programming means.

Since there cannot be an obvious winner to the challenge, we can base the winner upon majority rule in the form of likes.

Is This A Good Question/Topic? 0
  • +

Replies To: Horrible code challenge

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3486
  • View blog
  • Posts: 10,742
  • Joined: 05-May 12

Re: Horrible code challenge

Posted 06 November 2012 - 02:33 PM

Just to make sure I understand the challenge, the point is not to write obfuscated code, but to make Rube Goldberg proud. Is this correct?
Was This Post Helpful? 0
  • +
  • -

#3 jimblumberg  Icon User is offline

  • member icon


Reputation: 3993
  • View blog
  • Posts: 12,323
  • Joined: 25-December 09

Re: Horrible code challenge

Posted 06 November 2012 - 02:41 PM

And also stick with standard C/C++?

Jim
Was This Post Helpful? 0
  • +
  • -

#4 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1072
  • View blog
  • Posts: 4,532
  • Joined: 09-June 09

Re: Horrible code challenge

Posted 06 November 2012 - 07:03 PM

Quote

the point is not to write obfuscated code, but to make Rube Goldberg proud

I'm going to go with a mixture of both, but the line is yours to draw. Make it as "reverse engineered proof" as possible.

Quote

And also stick with standard C/C++?

Yeah, stick with standard C/C++ ... for now at least.

This post has been edited by jjl: 06 November 2012 - 07:04 PM

Was This Post Helpful? 0
  • +
  • -

#5 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • Posts: 4,163
  • Joined: 08-January 12

Re: Horrible code challenge

Posted 07 November 2012 - 01:36 AM

Now I will have to get the code for insertion sort from somewhere and modify it... grumble...

Also, I hope you don't mind me using some of your techniques?
Was This Post Helpful? 0
  • +
  • -

#6 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • Posts: 4,163
  • Joined: 08-January 12

Re: Horrible code challenge

Posted 11 November 2012 - 02:26 PM

Here is the source code I (shamelessly) stole from one of DIC's code snippets.
void insertion_sort(int x[],int length)
{
  int key,i;
  for(int j=1;j<length;j++)
  {
     key=x[j];
     i=j-1;
     while(x[i]>key && i>=0)
     {
               x[i+1]=x[i];
         i--;
     }
     x[i+1]=key;
  }
}


And here is my code.
Spoiler

For now, that's the worst I can come up with. So, try to use the same code, so that we can compare :D/>

This post has been edited by aresh: 25 November 2012 - 12:04 PM

Was This Post Helpful? 2
  • +
  • -

#7 Xupicor  Icon User is offline

  • Nasal Demon
  • member icon

Reputation: 249
  • View blog
  • Posts: 582
  • Joined: 31-May 11

Re: Horrible code challenge

Posted 15 November 2012 - 08:30 AM

There's UB in code posted by aresh, I believe:
Spoiler

This post has been edited by Xupicor: 16 November 2012 - 12:34 AM

Was This Post Helpful? 1
  • +
  • -

#8 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5191
  • View blog
  • Posts: 26,901
  • Joined: 10-May 07

Re: Horrible code challenge

Posted 15 November 2012 - 09:00 AM

Dunno if this is valid in the contest, but it's fun to write :) I'm thinking off adding more garbage functions.

Spoiler


** Update **
Still a work in progress :P/>

This post has been edited by no2pencil: 25 November 2012 - 04:53 PM
Reason for edit:: Moved code into spoiler.

Was This Post Helpful? 1
  • +
  • -

#9 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: Horrible code challenge

Posted 15 November 2012 - 11:07 AM

I'm working on something that uses exceptions for recursion and stuch

edit:
ya that is undefined; the order in which arguments, be it a function or operator, isn't defined. what is defined is that the arguments will be evaluated before the function is called and that statements executed in the specified order but order of evaluation of arguments is not defined.

This post has been edited by ishkabible: 15 November 2012 - 12:42 PM

Was This Post Helpful? 0
  • +
  • -

#10 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: Horrible code challenge

Posted 23 November 2012 - 06:40 PM

*
POPULAR

pff you guys are armatures :P/>/>
Spoiler

This post has been edited by ishkabible: 23 November 2012 - 07:27 PM

Was This Post Helpful? 5
  • +
  • -

#11 Xupicor  Icon User is offline

  • Nasal Demon
  • member icon

Reputation: 249
  • View blog
  • Posts: 582
  • Joined: 31-May 11

Re: Horrible code challenge

Posted 25 November 2012 - 11:55 AM

WTFSort is that? Ugh. Good job, now I'm going to be sick!
Was This Post Helpful? 1
  • +
  • -

#12 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: Horrible code challenge

Posted 25 November 2012 - 12:05 PM

lol, it's actually confusing enough that the first version I wrote I totally scratched because I had trouble debugging it.

If there is something wrong with that sort, I don't think I care to find out what it is.

This post has been edited by ishkabible: 25 November 2012 - 12:27 PM

Was This Post Helpful? 0
  • +
  • -

#13 Xupicor  Icon User is offline

  • Nasal Demon
  • member icon

Reputation: 249
  • View blog
  • Posts: 582
  • Joined: 31-May 11

Re: Horrible code challenge

Posted 25 November 2012 - 02:05 PM

If there is something wrong with that sort, I don't think I have the stomach to try to find out what it is. :P

This post has been edited by Xupicor: 25 November 2012 - 02:06 PM

Was This Post Helpful? 0
  • +
  • -

#14 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 614
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: Horrible code challenge

Posted 10 January 2013 - 04:49 PM

*
POPULAR

I know you didn't specifically say "obfuscate the code", but you can't deny that my version is highly "reverse engineered proof". It compiles with g++, and if you listen closely enough, you can hear the compiler weeping.

/* 
	start insertion sort 
*/

#define ii aas
typedef int uif;
#define sd(gth) length
#define ssd(daa) vo##daa
#define io(ak) jahs < jahs
#define tiddfgona(als) inser##als
#define oai asde
#define jahs
#define aks * 0
#define ajk(opps) wh##opps
#define aas agh(a,zz)
#define ahjkslju ]
#define agh(a,ff) a##la(ff)
#define asde(a,ff) a##la ff
#define oop ,
#define ahjkl ii oop i;
#define kha = 
typedef uif ala;
#define aa [
#define alsjk agh
#define uuay alsjk(a,x aa ahjkslju)
#define iiao len
#define aasdd(kj) (kj * 19 / 10)aks
#define alo(aad) fo##aad
#define akl 1
#define oapo i
#define ajs ++
#define ajas --
#define oiap >=
#define aaaaaa ajs 
#define ajsk ajs ajs
#define pio >
#define laos ;
#define akso zz
#define oia ((0x0172228873) / (((100 * 91827)) + 0))
#define opaaaos j
#define ioa x
#define asdddd +
ssd(
id
)tiddfgona(tion
)(uuay, 
asde(
a,
sd(
a3434 2
&*  s))) {ahjkl alo
(r
)(
oai(a,
j
) kha 
aasdd(0123
)+akl; 
opaaaos io
(102
) sd( oia
)laos j ajs) 
{akso 
kha 
ioa aa j ahjkslju laos i kha 
opaaaos-1;
		ajk(ile)
(ioa[i] pio akso 
&& 
oapo oiap aasdd(19299
)
) {x aa oapo asdddd 
1 ahjkslju 
kha ioa aa 
i 
ahjkslju laos 
oapo ajas laos
} ioa aa oapo asdddd 1 ahjkslju = akso; } }

/* 
	end insertion sort 
*/

#include <iostream>

int main() {
	int a[] = {10,2,3,2,7,4,6,2};
	insertion(a, 8);
	for (int i = 0; i < 8; i++) {
		std::cout << a[i] << ",";
	}
	return 0;
}

This post has been edited by Aphex19: 10 January 2013 - 04:53 PM

Was This Post Helpful? 5
  • +
  • -

#15 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: Horrible code challenge

Posted 10 January 2013 - 04:58 PM

if you listen closely, you can hear me gouging out my eyes.
Was This Post Helpful? 3
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2