The resources are 1, 2, 3, 4, 5
where 5
represents OreOre.
The idea is to first count the resources by type, then reduce all counts of BB, LL, WW, and SS by one - if we counted none for any of these four then they will now have entries of -1 - we need to acquire them from our remaining resources (This is actually achieved by adding an extra OO (5
) and reducing allall five counts by 11). Next we integer-divide all these values by four to see how many units we may trade for with each of our remaining counts by resource typestype while not affecting the -1 and 0 counts (note that -1 integer-divided by four is -1, not 0). AddLastly we add up the values and check if itthe result is greater than or equal to zero (here greater than -1 can be used since we always have integers):.