We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 570c27c commit 68e5bb4Copy full SHA for 68e5bb4
Project Euler/Problem 76/sol1.py
@@ -0,0 +1,35 @@
1
+from __future__ import print_function
2
+'''
3
+Counting Summations
4
+Problem 76
5
+
6
+It is possible to write five as a sum in exactly six different ways:
7
8
+4 + 1
9
+3 + 2
10
+3 + 1 + 1
11
+2 + 2 + 1
12
+2 + 1 + 1 + 1
13
+1 + 1 + 1 + 1 + 1
14
15
+How many different ways can one hundred be written as a sum of at least two positive integers?
16
17
+try:
18
+ xrange #Python 2
19
+except NameError:
20
+ xrange = range #Python 3
21
22
+def partition(m):
23
+ memo = [[0 for _ in xrange(m)] for _ in xrange(m+1)]
24
+ for i in xrange(m+1):
25
+ memo[i][0] = 1
26
27
+ for n in xrange(m+1):
28
+ for k in xrange(1, m):
29
+ memo[n][k] += memo[n][k-1]
30
+ if n > k:
31
+ memo[n][k] += memo[n-k-1][k]
32
33
+ return (memo[m][m-1] - 1)
34
35
+print(partition(100))
0 commit comments