What complicated line of code you've ever written?

Curious as to know what is the most complicated line or few lines of code you’ve ever written?
I don’t exactly have one off the top of my head - at least in Unity.
But nevertheless, I am curious to know yours!

I just got distracted from coding and was like you know what, let me search ol google for this and found some crazy stuff. (Granted this isn’t one line of code), but still interesting to see how much you can cram into a little area.

(I DID NOT MAKE THIS)
But it’s supposed to be something about the 12 days of Christmas.

#include <stdio.h>
main(t,_,a)
char *a;
{
return!0<t?t<3?main(-79,-13,a+main(-87,1-_,main(-86,0,a+1)+a)):
1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?
main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t,
"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#l+,/n{n+,/+#n+,/#\
;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l \
q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;#\
){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' \
iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \
;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')# \
}'+}##(!!/")
:t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1)
:0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,
"!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);

Seems pretty complicated haha.

FYI writing stuff like that is a good way to get fired. Code is supposed to be human-readable.

As for “the most complicated line” I forgot. Complex problems usually spread out across multiple files, and complex programs tends to get big over time. So it is usually not “it is complex because of this line here”, but “it is complex because you have several dozen megabytes of code”.

1 Like

Oh no I understand what you mean, I wouldn’t write code like that either unless it was absolutely required.
But I’m speaking just moreso in general what is one of the most complicated little things whether it be 1 line or 10 lines or even 1000 lines, just in general like, creating a new physics system, what equation was the hardest for you to make within a few lines.

I know I’m talking a bunch of stuff that usually takes hundreds and thousands of lines of code, but I don’t know a good example other than what I posted above.

I wouldn’t code it like that, nor could I read what it is, only that is what the guy said it was for lol.
Which is complicated and could probably be created with a simple few lines of code rather than a bunch of whatever that stuff is lol.

But needless to say, just because it’s complicated to us doesn’t mean it isn’t easy for them, it’s all relative lol.
But anywho, I’m not expecting to read a 100 lines of code of complication, only trying to see if anyone has ever programmed a (readable) complicated or non-readable complicated short piece of code that took you awhile to figure out how to make.

In my experience, one of the most complex situations is when you develop large system (megabyte of code or several megabytes - all written by you), and then you have to rewrite foundation of the system without it breaking, because project requirements changed, and that caused object model to change as well (bonus points if one of the classes at the top of hierarchy split into two).

Equations, physics engines, etc - all of this stuff is fairly simple, because you can break it down into small manageable pieces. in case of project foundation rewrite, though, you really need to pay attention to pretty much everything.

1 Like

Good points.
And not gonna subject against them, because what you say is true.

But I think we’re not on the same page with what I was asking lol.
I understand big systems is obviously going to be the the biggest thing.

But what I was trying to ask is, example Unity. What is the hardest smallest thing that you’ve done.
Something that took forever to figure out and was in technicality one of the easiest things to ever do.
E.G. - Something that is either Undocumented or has very little to nothing about what it does or even how to use it.

But once you figure it out, you feel like breaking ur keyboard because instead of saying (EXAMPLE).
Vector3 go = Vector3(0,0,5);
You have to say Vector3 go = new Vector3(0,0,5);

But obviously something more technical than that because this stuff is documented lol.

because I run into these moments when I swear I know what to put, i just can’t get my brain to press the keys on the Keyboard and type it, turns out to be pretty hard, and finally get it, but still nevertheless technical.

Here’s a link that might interest you:
http://ioccc.org/

http://forum.unity3d.com/threads/all-possible-c-keywords.362527/

1 Like

Hmm. I couldn’t tell you the most complicated / complex code I have written or most complex I’ve solved but I have a couple of cool examples.

PROBLEM 1 - Dynamic Object Data Mapping
Recently, we were building an attribute system for product configuration for a LOB app we’re building. Products can have optionally no extra configuration, or a dozen or so extra configuration options. Each “configuration” is actually a whole series of settings, some of which depend on others. Some of checkboxes, some are entry fields, some are associations. Each “attribute” is a collection of settings and has its own view model.

Originally we were told that there could be 1000 attributes, so we wanted to build a dynamic system that didn’t require us to create a new API endpoint to save each attribute (we’re using AngularJS and Web API). So, we used a complex but understandable combination of enums and attributes to define types for the view models. Then we use JSON .NET to deserialize the request into a JObject, read a value to determine the desired type, and then further deserialize it into the proper model type.

Finally, we run it through a custom AutoMapper mapping that converts each view model into a key/value collection because all attribute values are stored as key value pairs in the database. The process is simply reversed to get the kvp data back into models for the UI.

PROBLEM 2 - Efficient View Frustum Culling in XNA
This one doesn’t require a lot of explanation. Back in the day with XNA I worked on a tutorial series for rendering terrain with LOD. It used a quad tree setup to store the terrain data and rebuild the index and vertex buffers on demand by traversing the tree and stepping up levels based on distance from the player position.

One thing that became evident was that culling based on the view frustum was difficult. I had to create bounding boxes for the different quads of my terrain and check intersection against the view frustum to determine if any of that particular area of terrain was visible. But, intersection tests against 3D objects is expensive, especially with a non-cubical shape like the View Frustum.

To solve this problem, I decided it was ok in my case to ignore height which could be tackled further down the road. Instead, I pretended the terrain was always at 0 in the Y position. So essentially I ignored the Y element completely when I built the terrain. The terrain itself still had height, but I built bounding Rectangles instead of bounding Boxes for each quad so they only had x and z positioning. Then I projected the view frustum onto the terrain by determining all the points at which the frustum intersected the terrain. This was tricky because it could be looking up and not intersecting at all. It could be turned at an angle… it could be looking mostly through the terrain… and the camera could be above or below the terrain. Essentially I could have anywhere between 0 and 5 points of intersection with the terrain at the 0 y position.

So I constructed a shape by determining all of the points of intersection. Then I used the separating axis theorem to test against each bounding rectangle and the view frustum shape. Since I was using a quad tree I could start higher up and test down to prune out unnecessary tests, eliminating a lot of work. This proved to be pretty efficient (but ugly code) and performed tests far faster than volume checks. The only problem was, since it was only checking terrain intersection at the Y = 0 position, it ignored the fact that there may be bisible mountains in front of you. It was still a fun experiment.

While not specifically a single line of code, I have been guilty of abusing enums to do more then they should. This little piece sits in the middle of my grid based movement system (See Revenge of the Ghosts in my sig).

public enum Direction {up,left,down,right}

public static class DirectionExtensions {
     public static Direction TurnLeft(this Direction direction){
      int value = (int)direction;
      value ++;
      if (value >= System.Enum.GetValues(typeof(Direction)).Length) value = 0;
      return (Direction)value;
   }

   public static Direction TurnRight(this Direction direction){
      int value = (int)direction;
      if (value <=0 ) value = System.Enum.GetValues(typeof(Direction)).Length;
      value --;
      return (Direction)value;
    }

    public static Vector2 ToVector(this Direction direction){
       switch (direction){
       case Direction.down :
           return Vector2.down;
       case Direction.left :
           return Vector2.left;
       case Direction.right:
           return Vector2.right;
       case Direction.up:
           return Vector2.up;
       }
       Debug.LogError ("Undefined direction in ToVector function, returning (0,0)");
       return Vector2.zero;
    }
}

In terms of single lines there are some long ones involved in pathfinding

Node newNode = new Node (openNodes[mazePosition].gCost + costFunction(neighbourPosition.x, neighbourPosition.y),GetDistance(neighbourPosition, targetPosition),mazePosition);

And in texture painting

pixels[(int)currentPath.path[i].y * pathVisualisation.width + (int)currentPath.path[i].x].a = alpha;

But neither of those lines are overly complex. And there is no reason why they couldn’t be done in separate lines.

1 Like

Back when I had a TRS-80 Color Computer 3, I won the Rainbow magazine “One Liner” contest a couple times. Technically speaking, the “One Liner” contest permitted two lines per program. It was funny how many neat things people thought up back then and stuffed into one or two lines of code, and usually the code was written quite opposite to code readability. Both times that I won were with procedural screen savers. The absolute coolest submission I ever saw in that contest was an endless racing game using black boxes for the canyon walls and the player’s car.

These days, I am too much of a code readability zealot to ever go back to trying to jam a bunch of code onto one line.

It isn’t Unity code, but this SQL statement (in PHP) for a Social Networking app has always stood out in my mind as the most complex thing I’ve ever had to write.

$rs = mysql_query("SELECT that.profileid, IFNULL((SELECT matches.matchid FROM matches WHERE (matches.profileid1 = that.profileid OR matches.profileid1 = this.profileid) AND (matches.profileid2 = that.profileid OR matches.profileid2 = this.profileid) AND (matches.creatorid = this.profileid) AND (matches.approved2 = 0) LIMIT 1),0) AS forward, IFNULL((SELECT matches.matchid FROM matches WHERE (matches.profileid1 = that.profileid OR matches.profileid1 = this.profileid) AND (matches.profileid2 = that.profileid OR matches.profileid2 = this.profileid) AND (matches.creatorid = that.profileid) AND (matches.approved2 = 0) LIMIT 1),0) AS backward, IFNULL((SELECT matches.matchid FROM matches WHERE (matches.profileid1 = that.profileid OR matches.profileid1 = this.profileid) AND (matches.profileid2 = that.profileid OR matches.profileid2 = this.profileid) AND (matches.approved1 = 1) AND (matches.approved2 = 1) LIMIT 1),0) AS complete, COUNT(*) AS matches, profiles.gender, profiles.name, profiles.age, profiles.cnt, profiles.status, profiles.rating, profiles.imgflag, IFNULL(OCTET_LENGTH(profiles.imgdata), 0) AS imgsize, TIME_TO_SEC(TIMEDIFF(NOW(), profiles.lastact)) AS lastact FROM likes AS this INNER JOIN (likes AS that INNER JOIN profiles ON that.profileid = profiles.profileid) ON that.typeidx = this.typeidx AND that.data = this.data AND that.profileid <> this.profileid WHERE this.profileid = " . $inprofileid . " AND (profiles.lastact > DATE_SUB(NOW(), INTERVAL 1 WEEK)) AND profiles.name <> '' AND profiles.gender < 2 AND (IFNULL(OCTET_LENGTH(profiles.imgdata), 0) > 0) GROUP BY that.profileid ORDER BY 5 DESC LIMIT 150");

EDIT: More impressive as a block…

2 Likes

That 12 days of Christmas code won the c or c++ obfuscated code contest. Amazing but this isn’t just complicated it’s totally unrealistic, albeit very interesting.

I’d have to say the most complicated code I write is in sql query form due to the limited syntax and set based handling of data.

In c# I haven’t written anything too complex. It’s the math that’s necessary for certain tasks and just general good design of large applications that gives me the biggest challenge.

Some interesting works I am seeing :).

at @Magnumstar - yeap that is correct - I saw that on a website and it said it had won the contest thing.
Yeah it’s definitely unrealistic haha, but still a good point that you can make a lot of stuff work in such a little area
if you know what you’re doing. Technical or not - it’s still very interesting what you can actually do :smile:

One thing I have done with SQL queries to make some of the big ones more manageable is use Views to hide some of the complexity from the web application. This can be especially useful when there are joins.

For me, it’s a C# Unity Collada runtime model importer I’m working on. It’s turning out to be a huge project and currently smashing my head against animations =D.

Haha yeah I hear ya.

Same here(well different thing). But I’m already at 1283 lines of code just manipulating files and folder structures.
And sadly that’s just the basic easy parts haha.

But some of the stuff is kinda head twisting such as, like really you can’t do System.IO.Directory.Delete() if there are files in it, you have to pass an array to delete all the files THEN delete the directory, beats me as to why, but it is what it is lol.

1 Like
mol = 42;

Uhh what? lol. It’s so complicated Idk what mol means haha

Don’t you know what 42 is? (hint google 42).

Meaning of life.

Ahh the spaghetti thread…