Created
January 9, 2015 08:40
-
-
Save ryo1kato/169fb05df91fda0fbe60 to your computer and use it in GitHub Desktop.
Calculate weight distribution of human-piramid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
NR_LAYER = 10 | |
def get_n_plus_1(weights): | |
length = len(weights) | |
lower_weights = [[1 for col in range(length+1)] for row in range(length+1)] | |
print "---- %d -----" % len(weights) | |
for x in range(0,length): | |
for y in range(0,length): | |
#print weights[x][y] | |
qw = weights[x][y] / 4.0 # quarter of weight | |
lower_weights[x] [y] += qw | |
lower_weights[x+1][y] += qw | |
lower_weights[x] [y+1] += qw | |
lower_weights[x+1][y+1] += qw | |
return lower_weights | |
layers = [] | |
layers.append([[1.0]]) | |
for i in range(0,NR_LAYER): | |
layers.append( get_n_plus_1(layers[i]) ) | |
i=1 | |
for l in layers: | |
total = 0 | |
for x in l: | |
for y in x: | |
sys.stdout.write("%.2f " % y) | |
total += y | |
sys.stdout.write("\n") | |
print "============ layer%d: %.2f =============" % (i, total) | |
i+=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment