[Question]
  [
Write a function that contains five lines.
If you run the function as-is, it should return 0.
If you remove any one of the five lines and run the function, it should tell you which of the lines has been removed (e.g., if you remove the final line it should return 5).
Brevity, novelty, and elegance all deserve consideration. Highest upvoted solution (after a reasonable amount of time) wins.
  
[Answer]
## Ruby
Eschewing magic numbers since it's not code golf.
```
def f
  r=2^3^4^5
  defined?(r) ? r^=2 : r=1^3^4^5
  r^=3
  r^=4
  r^=5
end
```
Each line strips its own number out of `1^2^3^4^5`. It's Ruby, so the last line defines the return value.
[Answer]
## JavaScript ( ~~134~~     ~~77~~     ~~69~~     ~~65~~    60 chars)
## [→ live demo ←](http://xem.github.io/miniCodeEditor/1.1/#w=function%28n%29%7B%0A%0A%20%20a=n-=1%0A%20%20n-=2%0A%20%20+3%0A%20%20+4;if%28this.a%29return%205%0A%20%20return%20n;var%20a%0A%0A%7D%0A%0Adocument.write%28w%2810%29%29%7F%7F%3Ch3%3EComment%20one%20of%20the%20lines%20of%20the%20function%20w,%20it%20will%20return%20the%20number%20of%20the%20commented%20line%3C/h3%3E%0A%0ARemoved%20line%3a%201)
```
function(n){
a=n-=1
n-=2
+3
+4;if(this.a)return 5
return n;var a
}
```
call this function with n = 10.
* If no line is missing, line 5 returns n == 0.
* If line 1 is missing, line 5 returns n == 1.
* If line 2 is missing, line 5 returns n == 2.
* If line 3 is missing, line 5 returns n == 3.
* If line 4 is missing, line 5 returns n == 4.
* If line 5 is missing, the var "a" becomes global and line 4 detects that to return "5".
* If line 5 is present, the JS engine performs "variable hoisting", "a" becomes a local var, and line 4 doesn't return "5".
  
  
## Previous versions:
## 65 chars
```
function(n){
a=n-=1
n-=2
+3
+4;if(this.a)return 5
n-=5;return n;var a
}
```
(must be called with n = 15)
## 69 chars
```
function(n){
n-=1
n-=2
n-=3
a=n-=4;if(this.a)return 5
n-=5;return n;var a
}
```
(must be called with n = 15)
## 77 chars
```
function(){
a=
b=
c=
d=1;if(this.a)return 5
1;var a,b,c,d;return d?c?b?a?0:1:2:3:4
}
```
## 134 chars
```
function w(){
a=1;e=1;if(this.e)return 5
b=1;if(!a)return 1
c=1;if(!b)return 2
d=1;if(!c)return 3
var a,b,c,d,e;return d?0:4
}
```
## non-golfed
```
  function whichlineisremoved(){
    /* 1 */ var a = 1; e = 1; if(window.e) return 5;
    /* 2 */ var b = 1, a; if(!a) return 1;
    /* 3 */ var c = 1, b; if(!b) return 2;
    /* 4 */ var d = 1, c; if(!c) return 3;
    /* 5 */ var e = 1, d; if(!d) return 4; return 0;
  }
```
[Answer]
## Python
If parameters are allowed, then this will work:
```
def f(n=10):
    n -= 1
    n -= 2
    n -= 3
    if n == 4: return 0 if f(7) else 5
    return n - 4 or 4
```
[Answer]
## R
```
f <- function() {
  T <- FALSE
  F <- TRUE
  month.abb <- TRUE
  (pi <- 5)
  T + (!F) * 2 + (!isTRUE(month.abb)) * 3 + (pi != 5) * 4
}
```
The function uses built-in "constants" and assigns another value to each of them. If all of these variables are equal to the new value, the function returns 0. Logical values are transformed to numeric ones because of the mathematical operators. The parentheses around the 4th line allow visibly returning its result (if it's the last command).
[Answer]
# Lua 5.2+
55 chars in the function body excluding newlines.
I couldn't come up with anything better but this:
```
function f()
return 7--[[
return 1--[=[]]-2
--[[
-2--[=[]]
-5--]=]--]]-1
end
```
Hoping to get extra points for comments abuse :P
The reason it does not work in 5.1 is that nested `[[]]` were removed, and in 5.1 it gives a compilation error instead of ignoring it like 5.2 does.
* If none of the lines are removed, the function body is eqivalent to `return 7-2-5`
* If the first line is removed, `return 1`
* If the second, `return 7-5`
* If the third, `return 7-2-2`
* If the fourth, `return 7-2-1`
* If the fifth, `return 7-2`
[Answer]
## Ruby
I tried doing it with bitwise operations and then I realized there is a much simpler solution using lists! This challenge is best served by a programming language that automatically returns the last value it sees, such as Ruby.
```
def tellMe(x=[1,2,3,4,5])
    x.delete(1)
    x.delete(2)
    x.delete(3)
    x.delete(4);x[0]
    x.delete(5);x==[]?0:x[0]
end
```
[Answer]
Befunge doesn't have explicit functions, but here is what I'd call a function in Befunge:
```
v^    <
>v
1>v
 2>v
##3>5v
$0v4 >
>>>>>>^
```
The first and last lines are function start and function end. It does the closest thing to "return", that is, it pushes the correct value onto the stack.
[Answer]
# 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.
[Answer]
# Bash, 131 chars
```
#!/bin/bash
# the function:
function f(){
  a=1;
  b=2;
  c=3;
  d=4;[ ! $1 ]&&f 1&&return 5||true
  [ $1 ]&&return 6;e=5;s=$((a+b+c+d+e));return $((15-$s))
}
# call it:
f
# report the result:
echo Removed line $?
```
It's all straightforward up to line 5. Then it needs to detect if the final line is gone. This takes advantage of permitted function parameters by calling itself recursively, once, to test its own success value when it's being told to fail on line 5, and if line 5 is removed, line 4 returns `5` instead.
(Note: it's down to a minimum of 131 characters if stripping out everything but the function, ditching whitespace, and changing /bin/bash to /bin/sh)
[Answer]
# [beeswax](http://esolangs.org/wiki/Beeswax), 86 bytes
Trying out my first invented esolang.
After initial confusion I found that the solution is so simple.
```
_1 p
_^v>~2+p
   >   >~3+p
       >   >~4+X@7~8+~@$^^{;
           >    >~5+@7~8+~@${;
```
Explanation:
**beeswax** programs work on a 2D hexagonal grid. Programs are stored in a rectangular format.
```
    a — b — c — d
   / \ / \ / \ /
  e — f — g — h
 / \ / \ / \ /
i — j — k — l
```
is stored as
```
abcd
efgh
ijkl
```
The instructions for moving in certain directions are:
```
    b — d 
   / \ / \                                  bd
  < —IP — >    or in compact form (β=IP):   <β>
   \ / \ /                                   pq
    p — q
```
Short explanation
`_1 p` Create an IP, add 1, then redirect IP to line 2
`_^v>~2+p` Create another IP, just in case line 1 is missing, slow down IP to make sure IP from line one is ahead, then add 2, then redirect to line 3
`> >~3+p` Add 3, then redirect to line 4
`> >~4+X@7~8+~@$^^{;` Add 4, then set 2nd lstack value to 15, then XOR lstack top and 2nd values, slow down IP (to make sure IP in line 5 is ahead, if line 5 exists) and output the result, then terminate the program.
`> >~5+@7~8+~@${;` Add 5, then do the same as in line 4, except the slow down.
Basically the program just calculates a sum xor 15
* Program intact: (1+2+3+4+5) xor 15 = 0
* Line 1 missing: (2+3+4+5) xor 15 = 1
* Line 2 missing: (1+3+4+5) xor 15 = 2
* Line 3 missing: (1+2+4+5) xor 15 = 3
* Line 4 missing: (1+2+3+5) xor 15 = 4
* Line 5 missing: (1+2+3+4) xor 15 = 5
The additional `>` in lines 3 to 5 just guarantee that if one of lines 2 to 4 are missing, the IP still gets redirected properly and doesn’t leave the program.
You can clone my beeswax interpreter, written in Julia, from **[my GitHub repository](https://github.com/m-lohmann/BeeswaxEsolang.jl)**
The readme on GitHub is more up to date and better structured than the esolangs page.
[Answer]
## MuPAD, 57 chars
```
subs(()->
-d(1)
-d(2)
-d(3)
-d(4)
-d(5)
,d=Dom::IntegerMod(15))
```
[Answer]
Common LISP:
```
(defun which-line-is-removed (&aux (x 30)) 
  (decf x 2)
  (decf x 4)
  (decf x 8)
  (decf x 16) 5
  (if (zerop x) 0 (log x 2))
)
```
NB: Having ending parenthesis on it's own line is considered bad style, but since other languages has `end` and `}` I assume it is allowed.
[Answer]
# Javascript
```
function(){
/*aa*/if(arguments.callee.toString().indexOf("*"+"a".repeat(6)+"*")==-1)return 5;
/*aaa*/if(arguments.callee.toString().indexOf("*"+"a".repeat(5)+"*")==-1)return 4;
/*aaaa*/if(arguments.callee.toString().indexOf("*"+"a".repeat(3)+"*")==-1)return 2;
/*aaaaa*/if(arguments.callee.toString().indexOf("*"+"a".repeat(4)+"*")==-1)return 3;
/*aaaaaa*/return +!~arguments.callee.toString().indexOf("*"+"a".repeat(2)+"*");
};
```
]