-1
1
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
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 – 2014-03-10T16:28:56.333
5I 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 – 2014-03-10T16:30:04.570
@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 – 2014-03-10T16:31:36.983
@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 – 2014-03-10T16:32:46.267
If you want longest code rather than shortest code, the tag should be code bowling, not code golf – Level River St – 2014-03-10T16:34:26.320
Hmm you will have to word it better. But it seems the answer is still "infinitely large". For example, have part of the code which evaluates to
1
if the tenth fibonnaci number is55
and0
otherwise, then use that code wherever you'd use the literal1
. Then you can always keep going since the code that computes the1
will also have literals, etc. – Claudiu – 2014-03-10T16:34:56.823I don't think it is good question. I can add 3 lines that swap values of a and b, infinite times in between the original code anywhere. But does it make any sense? – microbian – 2014-03-10T16:42:45.727
@Claudiu yeah, you're right. I can't think of a properly enforceable way of wording that. other than maybe saying it has to be something that a very sleep deprived programmer could legitimately justify doing – puser – 2014-03-10T16:43:28.007
@puser: you can mark it as
popularity-contest
in which case there's no objective criteria, just the most popular answer wins. you'd have to change the criteria from being as long as possible to something like you just said – Claudiu – 2014-03-10T16:47:01.780@microbian no, because swapping values is needed for the code to work, if you removed it then it wouldn't work. and if you added it 4 extra times, you can remove those 4 extra times and it would still work – puser – 2014-03-10T16:47:08.240
I would write
return a<b?a:b;
– None – 2014-03-10T16:47:22.040@puser, that would hold true for any answer for this question. Because your current code works as it is. So any added lines can be removed safely to restore original code. How is it different? – microbian – 2014-03-10T16:52:24.773
@microbian there's a difference between removing and changing. though maybe i shouldn't have put an example answer in the question thinking about it... – puser – 2014-03-10T16:54:47.250