Created
January 5, 2015 16:19
-
-
Save benjamingorman/f0f797c31d4e11d02dea to your computer and use it in GitHub Desktop.
Euler 154
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
import cProfile | |
import collections | |
def pascal(first, length): | |
row = [] | |
a = first | |
for x in range(1, length): | |
# x and y form the ratio between consecutive elements | |
b = length - x | |
a = a * b // x # // is the integer division function | |
row.append(a) | |
return row | |
def pascalTriangleRow(n): | |
return pascal(1, n+1) | |
def pascalPyramidLayer(n): | |
count = 0 | |
def checkRow(a, row_length): | |
for x in range(1, row_length): | |
# x and y form the ratio between consecutive elements | |
y = row_length - x | |
a = a * y // x | |
if a > 200000: | |
++count | |
length = n + 1 | |
for x in pascalTriangleRow(n): | |
checkRow(x, length) | |
--length | |
return count | |
def main(): | |
print(pascalPyramidLayer(3000)) | |
cProfile.run("main()") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment