Work in progress, 15 doesn't work like intended

This commit is contained in:
2020-04-07 11:41:01 +02:00
parent 73d0d4ff36
commit 5c638b32a7
2 changed files with 86 additions and 0 deletions

39
12/main.py Normal file
View File

@@ -0,0 +1,39 @@
import os
import math
import numpy as np
# Triangle numbers are simply the sum of all natural numbers.
# Then, find the first triangle number that has over five hundred divisors.
def getTriangle(n):
# return sum(range(1, n + 1))
# Instead just use the formula like any normal human being
return int(n * (n+1) / 2)
def getTriangles(n):
return [getTriangle(x) for x in range(1, n + 1)]
def getNumberOfDivs(n):
# Fuck this function
def main():
print("Hello, this is Patrick")
ts = getTriangles(7)
print(ts)
for t in ts:
print(getNumberOfDivs(t))
if __name__ == "__main__":
main()

47
15/main.py Normal file
View File

@@ -0,0 +1,47 @@
import os
import math
import numpy as np
# Given a grid with start in one corner and goal in opposite corner, find
# the number of paths you can take from start to goal
gs = [[0] * 21] * 21
def gridRoutes(x, y):
res = 0
if gs[x][y] > 0:
res = gs[x][y]
else:
if x == 1:
res = y + 1
elif y == 1:
res = x + 1
else:
res = gridRoutes(x - 1, y) + gridRoutes(x, y - 1)
gs[x][y] = res
print(x, y, res)
return res
def dumbGridRoutes(x, y):
if x == 1:
return y + 1
elif y == 1:
return x + 1
else:
return dumbGridRoutes(x, y - 1) + dumbGridRoutes(x - 1, y)
def main():
print("Hello, this is Patrick")
g = gridRoutes(3, 2)
gd = dumbGridRoutes(3, 2)
print(g, gd)
if __name__ == "__main__":
main()