New Answer
I found another solution. That's so bad, I liked the math one so much. This solution uses recursion and global variables (yuck!) to tell if every line has been run or not. I wanted to do something different from the other solutions, so this isn't much elegant, but it works properly :)
PHP
function LOL($a) {
if (!$a) { LOL(true); if (!$GLOBALS['b']) return 2; if (!$GLOBALS['c']) return 3; if (!$GLOBALS['d']) return 4; if (!$GLOBALS['e']) return 5; return 0; }
if ($a) $GLOBALS['b'] = true; else return 1;
$GLOBALS['c'] = true;
$GLOBALS['d'] = true;
$GLOBALS['e'] = true;
}
I really enjoyed this challenge, thank you! :)
Old Answer
I solved it using maths. If each variable is seen as an unknown, and we do one declaration per line, there are five unknowns and five lines of code: this leads us to the following 5x5 system:
b+c+d+e = 1;
a+c+d+e = 2;
a+b+d+e = 3;
a+b+c+e = 4;
a+b+c+d = 5;
//Solutions are displayed in the code below.
Once I found the values, I hardcoded them and added some basic stuff.
PHP
function LOL(){
$a = 2.75;
$b = 1.75;
$c = 0.75;
$d = -0.25; if ($a+$b+$c+$d == 5) return $a+$b+$c+$d;
$e = -1.25; return $a+$b+$c+$d+$e;
}
Note: The Old Answer won't work if left as-is.
4Can the function take a parameter? – jeremy – 2013-12-28T04:54:41.987
6Does the function declaration count as one of the lines if we want to use that sort of language, or is only the body counted? – meiamsome – 2013-12-28T04:58:10.653
1Also, do our lines need to be numbered 1, 2, 3, 4, 5 or is any numbering scheme allowed? – meiamsome – 2013-12-28T05:11:38.993
@Jeremy, yes, that's fine. – jawns317 – 2013-12-28T12:20:22.483
@meiamsome, only the body counts, and the lines should be numbered 1, 2, 3, 4, 5 for the purpose of return values. – jawns317 – 2013-12-28T12:22:36.620
can each "line" of the function contain more than one statement? Can the function leak in the global scope? ... I made the JavaScript answer assuming yes and yes :) – xem – 2013-12-28T18:36:44.647