-1
\$\begingroup\$

Today, Numberphile posted this video where it's stated that 1+2+3+4+...+n = -1/12.

While this isn't really new (several ways to prove that have been found, you can look here for further informations), this leads us to our question!

Your goal is to write a function that returns -0.083333 (feel free to stop at -0.083 if you wish), which is -1/12.

Be original, since this is a !

Most upvoted answer in 2 weeks wins this.

\$\endgroup\$
  • \$\begingroup\$ I don't understand, does this mean that infinity is -1/12? \$\endgroup\$ – user10766 Jan 9 '14 at 19:23
  • \$\begingroup\$ No, but there are several mathematic methods to calculate this value as the result of that sum. Read the link I gave for more informations about that, this would be off-topic here I guess! :) \$\endgroup\$ – Vereos Jan 9 '14 at 19:28
  • \$\begingroup\$ These wikipedia articles seem relevant: en.wikipedia.org/wiki/… en.wikipedia.org/wiki/… \$\endgroup\$ – Justin Jan 9 '14 at 19:50
3
\$\begingroup\$

The Riemann Zeta function is defined as ζ(s) = Sum(n-s) where you sum from n=1 to n=infinity. Hence ζ(-1) = Sum(n) = 1 + 2 + 3 + 4 + ... to infinity.

Now scipy defines zetac to be sum(k**(-x), k=2..inf) (that is the zeta function with the first term removed).

Hence in python

>>> import scipy.special
>>> print 1+scipy.special.zetac(-1)
-0.0833333333333

essentially calculates the infinite sum 1+2+3+4+... to give -1/12.

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

J

This is quite short, but I hope you think it's sweet:

(%&13@<:^:_)0

I'm relying on the fact that a negative twelfth is -0.1111111... in base thirteen. This function takes its argument, decrements it, and divides by 13 (a right-shift in base 13). It does this until the value converges to -1/12. To see how the base 13 stuff fits in, you might want to imagine the 13 being changed to a 10. The function would then converge at decimal -0.111111... = -1/9.

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

PowerShell (and probably a polyglot)

I know this isn't code-golf, but since no other parameters are really defined for the challenge except:

Your goal is to write a function that returns -0.083333 (feel free to stop at -0.083 if you wish), which is -1/12.

I have a really hard time justifying doing anything other than:

-1/12

This outputs:

-0.0833333333333333
| improve this answer | |
\$\endgroup\$

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