Skip to main content
1 of 4
hyperneutrino
  • 42.8k
  • 5
  • 72
  • 227

Python 3, 89 bytes

from fractions import* v=0 i=2 while 1:j=Fraction(1,i);v+=v+j>1and-j or print(i)or j;i+=1 

Try it online!

Outputs the sequence indefinitely.

# Import the fractions module, specifically the Fraction class from fractions import * # Keep the cumulative sum v = 0 # Keep the current denominator i = 2 # Output forever while True: # Set j to 1 / i as a precise fraction using the stdlib module j = Fraction(1, i) if v + j > 1: # if adding would exceed, subtract instead v += -j else: # otherwise, print and add print(i) v += j i += 1 
hyperneutrino
  • 42.8k
  • 5
  • 72
  • 227