We need a function (for commercial purposes) that may perform integer partitions with some constraints.
The function should select how many elements each partition should have.
The function should discard some "forbidden" values in each partition.
So, create ```part_const()```, that receives three arguments.
```part_const((1), (2), (3))```
```
(1) - The integer to be partitioned

(2) - The number of elements that each partition should have

(3) - The "forbidden" element that cannot appear in any partition
```
```part_const()``` should output the amount of different integer partitions with the constraints required.

Let's see some cases:
```python
part_const(10, 3, 2) ------> 4 

/// we may have a total of 8 partitions of three elements (of course, the sum of the elements of each partition should be equal 10) :
[1, 1, 8], [1, 2, 7], [1, 3, 6], [1, 4, 5], [2, 2, 6], [2, 3, 5], [2, 4, 4], [3, 3, 4]

but 2 is the forbidden element, so we have to discard [1, 2, 7], [2, 2, 6], [2, 3, 5] and [2, 4, 4] 

So the obtained partitions of three elements without having 2 in them are:
[1, 1, 8], [1, 3, 6], [1, 4, 5] and [3, 3, 4] (4 partitions)///
```

```part_const()``` should have a particular feature:

 if we introduce ```0``` as the forbidden element, we will obtain the total amount of partitions with the constrained number of elements.

In fact, 
```python
part_const(10, 3, 0) ------> 8 # The same eight partitions that we saw above.
```

Enjoy it and happy coding!!

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Mathematics

Starter code: def part_const(n, k, num):
	

Solutions:
def p(t, k, n, l=1):
	if t < l:
		pass
	elif k == 1 and t != n:
		yield [t]
	else:
		yield from ([m] + s for m in range(l, t - l + 1) for s in p(t - m, k - 1, n, m) if m != n)

def part_const(t, k, n):
	return sum((1 for _ in p(t, k, n)))


def part_const(n, k, num):
	return part(n, k) - part(n - (num or n), k - 1)

def part(n, k):
	return 1 if k in (1, n) else sum((part(n - k, i) for i in range(1, min(n - k, k) + 1)))


def get_addends(num, x=1):
	yield (num,)
	for i in range(x, num // 2 + 1):
		for p in get_addends(num - i, i):
			yield ((i,) + p)

def part_const(n, k, num):
	return len([el for el in get_addends(n) if len(el) == k and num not in el])


def part_const(n, size, forbidden):
	(ways, k, partitions) = ([0, n] + [0] * (n - 1), 1, 0)
	while k:
		(x, y, k) = (ways[k - 1] + 1, ways[k] - 1, k - 1)
		while x <= y:
			ways[k] = x
			(y, k) = (y - x, k + 1)
		ways[k] = x + y
		if len(ways[:k + 1]) == size and forbidden not in ways[:k + 1]:
			partitions += 1
	return partitions


def part_const(n, k, num):
	return sum((1 for x in accel_asc(n) if len(x) == k and all((v != num for v in x))))

def accel_asc(n):
	a = [0 for i in range(n + 1)]
	k = 1
	y = n - 1
	while k != 0:
		x = a[k - 1] + 1
		k -= 1
		while 2 * x <= y:
			a[k] = x
			y -= x
			k += 1
		l = k + 1
		while x <= y:
			a[k] = x
			a[l] = y
			yield a[:k + 2]
			x += 1
			y -= 1
		a[k] = x + y
		y = x + y - 1
		yield a[:k + 1]


def part_const(n, k, num):
	return len([x for x in list(accel_asc(n)) if len(x) == k and num not in x])

def accel_asc(n):
	a = [0 for i in range(n + 1)]
	k = 1
	y = n - 1
	while k != 0:
		x = a[k - 1] + 1
		k -= 1
		while 2 * x <= y:
			a[k] = x
			y -= x
			k += 1
		l = k + 1
		while x <= y:
			a[k] = x
			a[l] = y
			yield a[:k + 2]
			x += 1
			y -= 1
		a[k] = x + y
		y = x + y - 1
		yield a[:k + 1]


def partition(n, parts, m=1):
	if parts == 1:
		return [[n]]
	ans = []
	s = m
	while s <= n / parts:
		l = [s]
		p = partition(n - s, parts - 1, s)
		for i in p:
			ans += [l + i]
		s += 1
	return ans

def part_const(n, k, num):
	p = partition(n, k)
	return len([i for i in p if not num in i])


part_const = p = lambda n, k, x, s=1: n != x if k < 2 else sum((p(n - i, k - 1, x, i) for i in range(s, n // k + 1) if i != x))


def part_const(n, k, num):
	return part(n, k) - (part(n - num, k - 1) if num else 0)

def part(n, k):
	return 0 if k > n else 1 if k in {1, n} else sum((part(n - k, i) for i in range(1, k + 1)))


def part_const(n, k, num, s=0, startwith=1):
	if k == 1:
		if n - s >= startwith and n - s != num:
			return 1
		return 0
	result = 0
	for i in range(startwith, n - s - k + 2):
		if i == num:
			continue
		result += part_const(n, k - 1, num, s + i, i)
	return result