Skip to content

Instantly share code, notes, and snippets.

@FlorianCassayre
Created March 23, 2017 22:00
Show Gist options
  • Save FlorianCassayre/a9063c9545b63ffe254f221eb8dde025 to your computer and use it in GitHub Desktop.
Save FlorianCassayre/a9063c9545b63ffe254f221eb8dde025 to your computer and use it in GitHub Desktop.
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