diff --git a/0015.py b/0015.py new file mode 100644 index 0000000..5ffff69 --- /dev/null +++ b/0015.py @@ -0,0 +1,84 @@ +from functools import reduce + +target = [19,19] +start = [0,0] + +side = 2 + +count = 0 +# 2: 6 +# 3: 20 +# 4: 70 +# 5: 252 +# 6: 924 + +def recurse(x, y): + global count + # print(x, y) + + if (x == side and y == side): + count += 1 + print('found', count) + return + + if (x < side): + # print('increasing x') + recurse(x + 1, y) + + if (y < side): + # print('increasing y') + recurse(x, y + 1) + +count = 0 +def smarter_recurse(index, bits): + # print(index, bits) + global count + + if (index == 0): + if (bits == 0): + count += 1 + return; + + if (index - 1 >= bits): + smarter_recurse(index-1, bits); + + if (bits > 0): + smarter_recurse(index - 1, bits-1) + +# side = 2 + +# smarter_recurse(side * 2, side) + +def product(x, y): + return x * y + +# 10! / 5!^2 +def do_it(slots, bits): + numerator = reduce(product, list(range(slots + 1 - bits, slots + 1))) + denomerator = reduce(product, list(range(1, bits + 1))) + + print(int(numerator / denomerator)) + + +# smarter_recurse(8, 4) + +# print(count) +# do_it(40, 20) + +slots = 7 +bits = 3 +# smarter_recurse(slots, bits) + +# print(count) + +# do_it(slots, bits) +# do_it(7, 0) +do_it(7, 1) +do_it(7, 2) +do_it(7, 3) +do_it(7, 4) +do_it(7, 5) +do_it(7, 6) + + +