News for hackers. Stuff that matters.
Re:Fun with math: Dividing one by 998001 yields a surprising... by kghose on Thursday January 26, 2012 @12:32PM (#3515030)
Yes, that is funky.

  def long_div(x,y,N=10):
    """Given two integers x and y, return us the N digits of x/y."""
    #First work out the integer part
    x = int(x)
    divisor = y = int(y)
    quotients = [x/y]
    dividend = x % y
    for digit in range(N):
      dividend *= 10
      quotient = dividend/divisor
      dividend = dividend%divisor
      quotients.append(quotient)
  
    return quotients
  
  def pretty_print(quotients, G=3):
    """Pretty print quotients by grouping digits by 3."""
    strp = ''
    cnt = 1
    for n in quotients[1:]:
      strp += str(n)
      cnt +=1
      if cnt > G:
        print strp
        strp = ''
        cnt = 1
  
  
  quotients = long_div(1,998001,N=3000)
  pretty_print(quotients,G=3)

There are no comments on this comment yet.