The task is to find the number of characters in your source code up to the previous line.

You may do some addition of two integers, or whatever that comes to mind. But at the end of your logic, you need to calculate the number of characters written in your code up to the last line.

EDIT: The goal is to find the number of characters required to perform a task. For example, you are adding two numbers. The task is to find the number of characters used in doing that task.

New line characters do not count. Lets start.

  • 2
    \$\begingroup\$ Can one hardcode the output? What's to stop someone from doing 1\n1\nprint(1+1)? \$\endgroup\$ – xnor Jun 26 '14 at 13:31
  • 3
    \$\begingroup\$ The previous line to which line of code? Previous to the end? Previous to the start? \$\endgroup\$ – Grax32 Jun 26 '14 at 13:33
  • \$\begingroup\$ As it is, this question is too broad. Arbitrary code C + arbitrary arithmetic expression E such that the the result of E is the length of C can pretty much be anything. \$\endgroup\$ – Dennis Jun 26 '14 at 13:47
  • \$\begingroup\$ See my edit. Hopefully, it is more clear now and not so broad. \$\endgroup\$ – Shafi Jun 26 '14 at 14:03


I think that's what you want:

function foo() {
   return arguments.callee.toString()
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.