DEV Community

Discussion on: Daily Challenge #275 - Casino Chips

 
masterroshan profile image
TJ Johnson • Edited

I approached it like this: There's a case where it's better to split the highest stack in half to divvy between the lower 2 stacks, this only happens when the lower 2 stacks add up to be greater than the highest stack, then there are these "leftovers" in the stacks that you can combine.
I ended up with something looking like
high/2 + (mid + low)/2
which can be reduced mathematically to
(high + mid + low)/2
There was a point where it stopped making sense and I was just reducing the math and logic. This was a solution that helped me dev.to/juanrodriguezarc/comment/12o94