31
\$\begingroup\$

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."

Reddit

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 0s 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 , so shortest answer in bytes wins.

\$\endgroup\$
  • 41
    \$\begingroup\$ Regarding the joke, I like the "You guys should know your limits" version better. \$\endgroup\$ – March Ho May 16 '17 at 13:17
  • 14
    \$\begingroup\$ Is it just me, or is that a parabola right there? \$\endgroup\$ – Adám May 16 '17 at 14:17
  • 1
    \$\begingroup\$ @StephenS Yes, I saw them too, but this one is much clearer and bigger. \$\endgroup\$ – Adám May 16 '17 at 14:22
  • 10
    \$\begingroup\$ @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 of 2^n is about n 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. \$\endgroup\$ – Greg Martin May 16 '17 at 17:02
  • 3
    \$\begingroup\$ @QPaysTaxes then you are non-competing - but if multiple people want to post competing C answers, you can compete against each other :) \$\endgroup\$ – Stephen May 16 '17 at 23:21

44 Answers 44

1
\$\begingroup\$

Ruby 46 bytes

i=1;loop{print (i<2?"#{i}":"1/#{i}")+"+";i*=2}

any improvement suggestions are welcome -))

\$\endgroup\$
1
\$\begingroup\$

F#, 39 bytes

let rec f x=printf"%A+1/"x;x*2I|>f
f 1I

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Labyrinth, 25 bytes

)
:}!43.4
"     9
*{2.74.

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Common Lisp, 42 bytes

(do((x 1(* x 2)))(())(format t"~a+"(/ x)))

Try it online (TIO will show you partial output)

Explanation

(do ... )          ;looping
((x 1(* x 2))      ;define x as 1 and then in new interation steps 
                   ;as result of 2 * x
(())               ;no ending condition
(format t"~a+"...) ;print argument and "+"
(/ x)              ;divide 1 by x - output is like this: 1, 1/2, 1/4, ...
\$\endgroup\$
1
\$\begingroup\$

PHP, 29 bytes

for($a=.5;$a*=2;)echo"$a+1/";
\$\endgroup\$
1
\$\begingroup\$

Ruby, 24 bytes

a=1;a/=2r while$><<a<<?+

Try it online!

Heavily based on G B's answer. But rationals are fun :V

\$\endgroup\$
1
\$\begingroup\$

GNU Make, 45 57 bytes

Using shell:

$(eval 1?=1)$(info $1+1/)$(call $0,$(shell expr $1 \* 2))

Using GMSL (a lot slower, calculates in unary), a complete makefile — 66 bytes:

include gmsl
P=$(info $1+/)$(call P,$(call double,$1))
$(call P,1)
\$\endgroup\$
1
\$\begingroup\$

MSX-BASIC, 36 bytes

1?"1+":X=2
2?"1/";X;"+":X=X*2:GOTO2

It works up to 70368744177664, then it starts displaying the values in exponential notation due to the precision limitation of the language, then it overflows at 1e62.

enter image description here

\$\endgroup\$
1
\$\begingroup\$

Taxi, 916 bytes

2 is waiting at Starchild Numerology.'1' is waiting at Writer's Depot.Go to Writer's Depot:w 1 r 3 l 2 l.Pickup a passenger going to Post Office.Go to Post Office:n 1 r 2 r 1 l.Go to Starchild Numerology:s 1 r 1 l 1 l 2 l.Pickup a passenger going to Cyclone.Go to Cyclone:e 1 l 2 r.[r]Pickup a passenger going to Trunkers.Pickup a passenger going to Multiplication Station.Go to Trunkers:s 1 l.Go to Multiplication Station:e 1 r 4 l.Pickup a passenger going to Cyclone.Go to Cyclone:s 1 r 2 l 2 r.Pickup a passenger going to Multiplication Station.Pickup a passenger going to The Babelfishery.' + 1/' is waiting at Writer's Depot.Go to Writer's Depot:s.Pickup a passenger going to Post Office.Go to The Babelfishery:n 1 r 2 r 1 r.Pickup a passenger going to Post Office.Go to Fueler Up:n.Go to Post Office:s 1 r 1 l.Go to Trunkers:s 1 r 1 l.Pickup a passenger going to Cyclone.Go to Cyclone:w 2 r.Switch to plan "r".

Try it online! (TIO will output the first 893 terms (up to ~3.3×10²⁶⁸) before cutting it off.)

Ungolfed:

2 is waiting at Starchild Numerology.
'1' is waiting at Writer's Depot.
Go to Writer's Depot: west 1st right 3rd left 2nd left.
Pickup a passenger going to Post Office.
Go to Post Office: north 1st right 2nd right 1st left.
Go to Starchild Numerology: south 1st right 1st left 1st left 2nd left.
Pickup a passenger going to Cyclone.
Go to Cyclone: east 1st left 2nd right.
[r]
Pickup a passenger going to Trunkers.
Pickup a passenger going to Multiplication Station.
Go to Trunkers: south 1st left.
Go to Multiplication Station: east 1st right 4th left.
Pickup a passenger going to Cyclone.
Go to Cyclone: south 1st right 2nd left 2nd right.
Pickup a passenger going to Multiplication Station.
Pickup a passenger going to The Babelfishery.
' + 1/' is waiting at Writer's Depot.
Go to Writer's Depot: south.
Pickup a passenger going to Post Office.
Go to The Babelfishery: north 1st right 2nd right 1st right.
Pickup a passenger going to Post Office.
Go to Fueler Up: north.
Go to Post Office: south 1st right 1st left.
Go to Trunkers: south 1st right 1st left.
Pickup a passenger going to Cyclone.
Go to Cyclone: west 2nd right.
Switch to plan "r".

Explanation:

Pickup the string `1` and print it to stdout to get started.
Pickup the number `2` and duplicate it so we have one to keep around and one to print.
Abuse the truncation function to leave a `2` for later.
(It's en route and has a short name so it saves bytes which is really important in Taxi.)
Go multiply the running total by 2.
(The first time, it's just a `2` so it returns itself. After that, it's 2 times the running total.)
Pickup the string ` + 1/`.
Convert the multiplication result from a number to a string.
Get gas.
Print the string ` + 1/` and the string multiplication result to stdout.
Go pickup that `2` from Trunkers, copy it again, and go back to `[r]`.

The output has trailing zeros on every number: 1 + 1/2.000000 + 1/4.000000 + ... but, per a comment by OP, that's OK so long as it's the same number of zeros every time.

\$\endgroup\$
1
\$\begingroup\$

Lua 5.1 + BC, 50 bytes

Now works with arbitrary long integers.

I don't usually golf in Lua, so any tips are welcome

i=1::a::print(i,'+1/')i=require"bc".mul(i,2)goto a
\$\endgroup\$
  • \$\begingroup\$ You can omit some newlines to save bytes. \$\endgroup\$ – Leaky Nun May 16 '17 at 12:55
  • \$\begingroup\$ You can use while 1 do instead. \$\endgroup\$ – Leaky Nun May 16 '17 at 12:57
  • \$\begingroup\$ @LeakyNun that will output garbage in the output when overflow happens \$\endgroup\$ – Felipe Nardi Batista May 16 '17 at 12:58
  • \$\begingroup\$ But then your answer does not print infinitely... \$\endgroup\$ – Leaky Nun May 16 '17 at 13:00
  • \$\begingroup\$ @LeakyNun original spec said thar language limitation could end the execution as well, i'll check \$\endgroup\$ – Felipe Nardi Batista May 16 '17 at 13:01
1
\$\begingroup\$

Cubix, 26 bytes

oruUroorp"/1+"1>O2uw"wo;;q 

A fairly linear program. Push characters /1+ onto the stack, push 1 onto the stack. Start loop, output number, multiply it by 2, push it to the bottom, pop the multipliers, output the characters on the stack and loop.

Try it here

Maps to

      o r u
      U r o
      o r p
" / 1 + " 1 > O 2 u w "
w o ; ; q * . . . . . .
. . . . . . . . . . . .
      . . .
      . . .
      . . .
\$\endgroup\$
1
\$\begingroup\$

Clojure, 59 bytes

#((fn[n](print(if(= 1M n)1(str 1\/ n))\+)(recur(* n 2)))1M)

A function that prints the fraction, doubles the denominator, then recurses.

(defn zenos-dichotomy-paradox []
  ; Create an anonymous function...
 ((fn [n]
    ; ... that prints the fraction (or just 1 if (= n 1))...
    (print
      (if (= 1M n) 1 (str 1 \/ n))
      \+)
    ; ..., doubles the denominator, then recurses infinitely.
    ; Will not SO since I'm using recur.
    (recur (* n 2)))
   ; Start the recursive function off with a 1. The M makes it a BigInteger so
   ;  I don't get an IntegerOverflow.
  1M))

Outputs

1 +1/2 +1/4 +1/8 +1/16 +1/32 +1/64 +1/128 +1/256 +1/512...

I can make the spacing more consistent at the cost of 2 bytes if necessary.

I tried to be clever and abuse Clojure's built in Ratio number type, but I got an overflow pretty quickly. 1/1 would have been automatically simplified to 1, getting rid of 1 as a special case. It would have been nice.

\$\endgroup\$
0
\$\begingroup\$

Mathematica, 45 bytes

Row@Flatten@Table[{1/2^t,"+"},{t,0,Infinity}]
\$\endgroup\$
  • \$\begingroup\$ This will not finish computing, and nothing will be printed. \$\endgroup\$ – JungHwan Min May 16 '17 at 13:53
  • \$\begingroup\$ Yes, I made it this way in order to get the result in a row. If you want to see a result just test for a finite number. Do you have any other ideas of how to print in a row? \$\endgroup\$ – J42161217 May 16 '17 at 14:03
  • 1
    \$\begingroup\$ You can use newlines as delimiters \$\endgroup\$ – JungHwan Min May 16 '17 at 14:05
0
\$\begingroup\$

cQuents, 13 bytes

|+1/=1:2^($-1

Try it online!

Explanation

|+1/            Set sequence join to "+1/"
    =1          Set first item in sequence to 1
      :         Mode : (sequence)
       2^($-1   Each item in the sequence equals 2 to the power of the index (1-based) of the current item minus 1
             )  Implicit closing parenthesis
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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