Skip to content

Instantly share code, notes, and snippets.

@Grief
Created November 7, 2016 20:39
Show Gist options
  • Save Grief/919e00e462130ec0c42439dfd418146e to your computer and use it in GitHub Desktop.
Save Grief/919e00e462130ec0c42439dfd418146e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3.5
import random, sys
def result(x):
print(x)
exit()
row, column = 0, 0
# noinspection PyBroadException
try:
row, column = [int(x) for x in sys.argv[1:]]
except: result('Usage: {} ROW COLUMN, e.g. {} 4 3'.format(*([sys.argv[0]] * 2)))
if column > row: result('COLUMN must be less or equal to ROW')
if row == 1: result(0)
if row == 2: result(0.5)
def r(): return random.randrange(200) + 56
w = [1]
def line():
spaces = ' ' * ((row - len(w)) * 7)
print('sum={}'.format(sum(w)), spaces, *['\033[38;2;{};{};{}m[{:_>11}]'.format(r(), r(), r(), i) for i in w])
line()
for i in range(1, row):
w = [i + 1 for i in [w[0] / 2] + [w[i] / 2 + w[i+1] / 2 for i in range(len(w) - 1)] + [w[-1] / 2]]
line()
result(w[column - 1] - 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment