# Let's play Psychic 

A box contains green, red, and blue balls. The total number of balls is given by `n` (`0 < n < 50`).

Each ball has a mass that depends on the ball color. Green balls weigh `5kg`, red balls weigh `4kg`, and blue balls weigh `3kg`.

Given the total number of balls in the box, `n`, and a total mass, `m`, your task is to craft a program that will determine the quantities of each colored ball. Return a list of these quantities as the answer.

Don't forget that some combinations of `n` and `m` may have more than one possibility!

# Examples

## Python
```python
>>> Guess_it(3, 12)
[[0,3,0], [1,1,1]]
```

## Elixir

*Note: Order of the returned elements is unimportant in the Elixir version.*

# Assumptions

1. You can assume that all inputs are of the correct type
2. You can assume that the range of `n` will be `[1, 50]`
3. Each element of the returned list should return the quantities in the order of `g`, `r`, `b`. 

## Python
```python
[[green, red, blue]]
```

## Elixir

Difficulty: EASY
Tags: Mathematics

Ad-hoc

Starter code:
def Guess_it(n,m):
	

Solutions:
def Guess_it(n, m):
	result = []
	for x in range(0, n + 1):
		(b, r, g) = (4 * n + x - m, m - 3 * n - 2 * x, x)
		if all((y >= 0 for y in (b, r, g))):
			result.append([g, r, b])
	return result


def Guess_it(n, m):

	def get_sum_balls(a, b, c):
		return sum([a, b, c])

	def get_sum_mass(a, b, c):
		return sum([a * 5, b * 4, c * 3])
	green_max = min(m // 5, n)
	red_max = min(m // 4, n)
	result = []
	for green_ball in range(0, green_max + 1):
		for red_ball in range(0, red_max + 1):
			blue_ball = abs(n - (green_ball + red_ball))
			x = get_sum_balls(green_ball, red_ball, blue_ball)
			y = get_sum_mass(green_ball, red_ball, blue_ball)
			if x == n and y == m:
				result.append([green_ball, red_ball, blue_ball])
	return result


def Guess_it(N, M):

	def mass(g, r, b):
		return g * 5 + r * 4 + b * 3
	results = []
	for g in range(N + 1):
		for r in range(N - g + 1):
			b = N - r - g
			if mass(g, r, b) == M:
				results.append([g, r, b])
	return results


Guess_it = lambda n, m: [[g, r, n - g - r] for g in range(n + 1) for r in range(n - g + 1) if (n - g - r) * 3 + r * 4 + g * 5 == m]


def Guess_it(n, m):
	(gMass, rMass, bMass) = (5, 4, 3)
	(gQ, rQ, bQ) = (0, 0, 0)
	massTotal = gMass * gQ + rMass * rQ + bMass * bQ
	total = gQ + rQ + bQ
	solutionSet = []
	while gQ <= n:
		rQ = 0
		bQ = 0
		massTotal = gMass * gQ + rMass * rQ + bMass * bQ
		total = gQ + rQ + bQ
		solution = [gQ, rQ, bQ]
		if (total, massTotal) == (n, m):
			solutionSet.append(solution)
		else:
			while gQ + rQ <= n:
				bQ = 0
				massTotal = gMass * gQ + rMass * rQ + bMass * bQ
				total = gQ + rQ + bQ
				solution = [gQ, rQ, bQ]
				if (total, massTotal) == (n, m):
					solutionSet.append(solution)
				else:
					while gQ + rQ + bQ <= n:
						massTotal = gMass * gQ + rMass * rQ + bMass * bQ
						total = gQ + rQ + bQ
						solution = [gQ, rQ, bQ]
						if (total, massTotal) == (n, m):
							solutionSet.append(solution)
						bQ += 1
				rQ += 1
		gQ += 1
	return solutionSet


def Guess_it(n, m):
	mass = {'green': 5, 'red': 4, 'blue': 3}
	output = []
	for i in range(0, n + 1):
		for j in range(0, n + 1):
			for k in range(0, n + 1):
				if i + j + k == n and i * 5 + j * 4 + k * 3 == m:
					output.append([i, j, k])
	return sorted(output)


def Guess_it(n, m):
	result = []
	delta = n * 5 - m
	for (idx, i) in enumerate(range(n - delta, int(1 + n - delta / 2))):
		if i >= 0:
			result.append([i, delta - 2 * idx, idx])
	return result


def Guess_it(n, m):
	lis = []
	for x in range(n + 1):
		for d in range(n - x + 1):
			if 5 * x + 4 * d + 3 * (n - x - d) == m:
				lis.append([x, d, n - x - d])
			else:
				pass
	return lis


def Guess_it(n, m):
	if n == 0:
		return [[]]
	arrayStorage = {0: [], 1: [], 2: [], 3: [[0, 0, 1]], 4: [[0, 1, 0]], 5: [[1, 0, 0]]}
	if m in arrayStorage:
		return arrayStorage[m]
	for i in range(6, m + 1):
		arrayStorage[i] = []
		arraysTemp = arrayStorage[i - 3]
		for array in arraysTemp:
			if sum(array) < n:
				elemToAdd = [array[0], array[1], array[2] + 1]
				if elemToAdd not in arrayStorage[i]:
					arrayStorage[i].append(elemToAdd)
		arraysTemp = arrayStorage[i - 4]
		for array in arraysTemp:
			if sum(array) < n:
				elemToAdd = [array[0], array[1] + 1, array[2]]
				if elemToAdd not in arrayStorage[i]:
					arrayStorage[i].append(elemToAdd)
		arraysTemp = arrayStorage[i - 5]
		for array in arraysTemp:
			if sum(array) < n:
				elemToAdd = [array[0] + 1, array[1], array[2]]
				if elemToAdd not in arrayStorage[i]:
					arrayStorage[i].append(elemToAdd)
	resultArray = []
	for array in arrayStorage[m]:
		if sum(array) == n:
			resultArray.append(array)
	return sorted(resultArray, key=lambda x: x[0])