I'm a beginner in programming just started learning a couple of weeks ago. When I don't have much time, I go on codewars to grab something to think about how to solve, this time it was a casino challenge. I came up with something that felt like it would cover everything, but it still fails 4 cases out of 208, and I'm stuck.
Here's the challenge:
The challenge is called Casino Chips. There's 3 stacks of chips, white, green, black chips.
Every day you take exactly 2 chips, and they can't be the same color. I have to return the maximum amount of days i can take chips on these conditions. MUST take 2 each day, and they MUST be different colors.
Example: [1,2,1] <= (1white, 2 green, 1 black) => returns: 2 days. [4,1,1] => 2, [8,1,4] => 5 etc.
No Bruteforcing.
And here's my code
def solve(arr):
arr.sort()
s = arr[0] + arr[1]
if arr == [1,1,1]:
return arr[0]
elif arr[0] + arr[1] <= arr[2]:
return s
elif arr[1] == arr[2] and arr[1] != arr[0]:
m = arr[0] - 1 + arr[1]
return m
elif arr[0] == arr[1] and arr[0] == arr[2]:
d = arr[0] / 2 + arr[1]
return int(d)
elif arr[0] + arr[1] > arr[2]:
e = (arr[0] + arr[1] + arr[2]) / 2
return int(e)
I've skipped math classes when I was small, which lead to not being able to keep up so my math knowledge is 0.
Any ideas what options my code doesn't cover, or does anyone know a formula for this that gets the job done? or how would you code it personally?