Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. import math
  2.  
  3. def genesis_block(e):
  4.   x = e % 2
  5.   a = int(e/2) + x
  6.   n = 1
  7.   b = a + 2*x + 2*n
  8.   c = a*b
  9.   d = math.floor(math.sqrt(c))
  10.   return (e, n, d, x, a, b)
  11.  
  12. def generateNRowsFromGenesis(e, rows=10):
  13.   genesis = genesis_block(e)
  14.   block = genesis
  15.   if e % 2 == 0:
  16.     offset = 2
  17.   else:
  18.     offset = 4
  19.   print (block)
  20.   for i in range(rows):
  21.     e, n, d, x, a, b = block
  22.     a = b
  23.     b = b + (offset + 4 * (i + 1))
  24.     c = a * b
  25.     d = math.floor(math.sqrt(c))
  26.     x = math.floor(math.sqrt( (d + n)**2 -c ) - n)
  27.     block = (e, n, d, x, a, b)
  28.     print (block)
  29.  
  30. def generateNthRowFromGenesis(e, nth=1):
  31.   genesis = genesis_block(e)
  32.   e, n, d, x, a, b = genesis
  33.   if e % 2 == 0:
  34.     a = int(int(e/2) + 2 * (nth**2))
  35.     b = int(int(e/2) + 2 * ((nth + 1)**2))
  36.   else:
  37.     a = int(int(e/2) + 1 + 4 * ( (nth * (nth - 1))/2 ))
  38.     b = int(int(e/2) + 1 + 4 * ( (nth * (nth + 1))/2 ))
  39.   c = a * b
  40.   d = math.floor(math.sqrt(c))
  41.   ee = c - d**2
  42.   n = (a + b)/2 - d
  43.   x = d - a
  44.   print (e, n, d, x, a, b)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement