How large can you make this function without adding any lines of code that do nothing [closed]

public int UndocumentedCode(int a, int b)
{
while (true)
{
a -= b;
b += a;
a = b - a;
if (b < a)
{
return b;
}
else
{
b += 1;
}
}
}

First figure out what it does (or look at the spoiler) the challenge is to make it as long as possible without adding lines that do absolutely nothing e.g. if (true) or do anything completely meaningless e.g. a declaration that isn't used/needed.

any lines of code that can be removed, with the result still being the same, do not count

the more confusing looking, the better.

it is a function for getting the lesser of two numbers. the if (b < a) return b is self explanatory. The a and b calculations at the top are to swap b and a around, so when it loops it will check a < b. the b+=1 is to prevent infinite loops if they are the same

closed as unclear what you're asking by Sriotchilism O'Zaic, Stephen, Timtech, NoOneIsHere, GryphonAug 10 '17 at 4:29

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• this isn't normal code golf, and this sort of 'challenge' may not even be a good thing to have on codegolf.stackexchange. if so please say – puser Mar 10 '14 at 16:28
• I don't currently see it as a good question. You could just add an infinite amount of lines that create and use variables, doing loops of various sorts, finding prime numbers perhaps, etc., while the function itself still at the end returns the same result – Claudiu Mar 10 '14 at 16:30
• @Claudiu i meant for "without adding lines that do absolutely nothing e.g. if (true) or do anything completely meaningless e.g. a declaration that isn't used/needed." to say you can't do this. but I haven't worded it well – puser Mar 10 '14 at 16:31
• @Claudiu maybe adding a clause that if any lines were taken out, then the code would not complete correctly then that is not allowed? – puser Mar 10 '14 at 16:32
• If you want longest code rather than shortest code, the tag should be code bowling, not code golf – Level River St Mar 10 '14 at 16:34

Not sure this is quite in the spirit of things, and I'm not going to write all the code, but technically all of the lines in the following would be necessary for the function to work. Note, for the sake of brevity I've changed the types to char, which I will assume is an 8-bit signed type (I didn't spot any mention of a specific language):

public char UndocumentedCode(char a, char b)
{
if (a == -128 && b == -128)
return -128;
if (a == -127 && b == -128)
return -128;
if (a == -126 && b == -128)
return -128;
...
// can you see where I'm going with this?
...
if (a == -128 && b == -127)
return -128;
if (a == -127 && b == -127)
return -127;
if (a == -126 && b == -127)
return -127;
...
// yawn...
...
if (a == 125 && b == 127)
return 125;
if (a == 126 && b == 127)
return 126;
if (a == 127 && b == 127)
return 127;

// i think you get the idea by now
}

The code would of course be platform dependant, and cases would need to be written for all combinations of negative and positive numbers. Perhaps some kind of script to write the file, to save aching fingers, and to automatically generate the code based on platform-specific options.

If we just went with 8-bit ints, then the final code would be roughly 131075 lines long, with all lines being necessary to cover all possibilities.

• as horrendous as this is, I quite like it – puser Mar 10 '14 at 17:15
• @puser: Horrendous? This is production code ;) - It would actually be more interesting to write the script to produce it I think. – icabod Mar 10 '14 at 17:17
public int UndocumentedCode(int a, int b)
{
while (true)
{
a -= b;
b += a;
a = b - a;
bool isGT? = b < a;
if isGT?
{
return b;
}
else
{
b += 1;
}
}
}

Add another statement with boolean condition.

public int UndocumentedCode(int a, int b)
{
int a1 = a;
int a2 = a1;
int a3 = a2;
int a4 = a3;
int a5 = a4;
int a6 = a5;
int a7 = a6;
int a8 = a7;
int a9 = a8;

// etc

int a9999 = a9998
int c = a9999;
while (true)
{
c -= b;
b += c;
c = b - c;
if (b < c)
{
return b;
}
else
{
b += 1;
}
}
}