31
6
Wikipedia: Zeno's Dichotomy Paradox
An infinite number of mathematicians walk into a bar. The first one orders a beer. The second one orders half a beer. The third one orders a fourth of a beer. The bartender stops them, pours two beers and says, "You're all a bunch of idiots."
Print the following series for as long as the program runs, with the denominator of each item being multiplied by two each time:
1 + 1/2 + 1/4 + 1/8 + 1/16 + 1/32 + ...
As n
approaches infinity, the sum of this sequence approaches 2
.
Rules
No, you may not print 2
.
You may not print 1/1
as the first item.
You may remove spaces 1+1/2+...
or add spaces 1 + 1 / 2 + ...
as you need.
You may use newlines instead of spaces as a delimiter due to popular demand.
You may append a .
plus a constant number of 0
s to the denominator if need be.
"Infinitely" means no unnecessary delays, and for as long as possible limited by the current (variable) system's specs, but not limited by your current language.
Standard loopholes apply.
This is code-golf, so shortest answer in bytes wins.
41Regarding the joke, I like the "You guys should know your limits" version better. – March Ho – 2017-05-16T13:17:34.427
14
Is it just me, or is that a parabola right there?
– Adám – 2017-05-16T14:17:44.9901@StephenS Yes, I saw them too, but this one is much clearer and bigger. – Adám – 2017-05-16T14:22:49.263
1What is meant by "limited by your current language."? Does that mean that any language which contains no reference to something like "Integer.MAX_VALUE" can be treated as having no max int value? Or does your "current language" include information in all compilers for said language? – Shufflepants – 2017-05-16T14:56:49.003
1@Shufflepants your program shouldn't break at a certain point based on its language. I.e., in Java, you have to use BigInteger and not int. – Stephen – 2017-05-16T14:58:32.893
10@Adám: yep! If the lengths of the denominators weren't changing, then the visual pattern of
+1/
s would just form a diagonal line. However, the lengths of the denominators is changing linearly (up to rounding): the number of digits of2^n
is aboutn log(2)/log(10)
. That linear change translates into a linear change in the relative position of each+1/
with respect to the preceding one, which is the same as a quadratic change in the absolute position. – Greg Martin – 2017-05-16T17:02:39.543@StephenS What about C? Making it go "infinitely" there is a significantly more complicated challenge than it is in languages with a built-in BigInteger; to answer in C, we'd have to either write our on BigInteger or do all the multiplications in the string -- neither of which is easy or short. – Fund Monica's Lawsuit – 2017-05-16T22:47:36.967
3@QPaysTaxes then you are non-competing - but if multiple people want to post competing C answers, you can compete against each other :) – Stephen – 2017-05-16T23:21:29.090
Can the output have trailing zeros?
1 + 1/2.0000 + 1/4.0000 ...
– Engineer Toast – 2017-05-18T13:54:37.240@EngineerToast is the number of trailing zeroes consistent across outputs (i.e.
1+1/2.0+1/4.0+1/8.0
) or does it increase for each output (i.e.1+1/2.0+1/4.00+1/8.000
)? First would be OK, second would not. – Stephen – 2017-05-18T15:59:24.940