Created
March 23, 2017 22:00
-
-
Save FlorianCassayre/a9063c9545b63ffe254f221eb8dde025 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InfiniteSeries | |
{ | |
public static void main(String[] args) | |
{ | |
/* | |
1 + 2 + 4 + 8 + ... = -1 | |
This algebraic proof is an analogy to Euler's approach to divergent series. | |
See https://en.wikipedia.org/wiki/1_%2B_2_%2B_4_%2B_8_%2B_%E2%8B%AF | |
*/ | |
int sum = 0; // The infinite summation | |
for(int n = 0; n < Integer.SIZE; n++) // 1 + 2 + 4 + 8 + ... | |
sum += 1 << n; // Adds the n-th power of 2 | |
System.out.println(sum); // Prints -1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment