Thanks aphyer, it was an interesting puzzle. I feel like it was particularly amenable to being worked out by hand relative to machine learning because of the determinism, rules easy to express in a spreadsheet, and simple subsets of the data (like the special cleric bracket) that could be built on.
This is resolved using python’s round() function...my apologies to simon, who seems to have spent a while trying to figure out when it rounded up or down.
I don’t recall that taking all that long really, I added one monster part type at a time (much like the main calculation but much easier since it’s just binary and only for the special 5U+ tax bracket, so less interactions to worry about).
Funny thing is, after seeing the calculation I still didn’t understand why it rounded the way it does, until I asked an AI which explained that Python rounds to even numbers on ties (apparently called “banker’s rounding” or “banker’s rule”). The only source of non-integer values is U which provides a single factor of 2 in the number of silver pieces, resulting in all rounding being of numbers with 0.5 in the remainder of silver pieces and so applying this rule. The other monster parts provide 2 factors of 2 of each, not directly causing rounding but each one incrementing the tax by 1 silver (modulo 2 silver) and thus changing whether this rule rounds up or down (except 2nd and up dragon heads which provide 3 factors of 2) .
Amusingly, I could have much more simply expressed this rounding rule as “if rounding is required, round to the nearest even number of silver pieces” but I wasn’t thinking about it in terms of output, so missed this and expressed it much more complicatedly in terms of the input. Oops!
if taxed_goods[‘U’] >= 5: tax_rate = min(tax_rate, 0.25)
Ah, makes sense that this would be its own special tax rate rather than the 50% bracket with a X2 discount (which amounts to the same thing in the end). That min though with the tax rate from other sources is another thing that was never triggered (and literally couldn’t be triggered since 5U alone is enough to get to the 30% bracket and also prevents eligibilty for the cleric bracket).
And just now I thought, wait, wouldn’t this sometimes round to 10, but no, an AI explained to apparently-stupid me again that since it’s a 0.25 tax rate on integer goods, fractional gold pieces before rounding (where not a multiple of 0.1) can only be 0.25, which rounds down to 2 silver, or 0.75, which rounds up to 8 silver. Which makes it all the more surprising that I didn’t notice this pattern.