Logic puzzle - balancing unique decision trees - need help with macro?

bford

New Member
Joined
Apr 6, 2018
Messages
3
Hello,

I need some assistance in balancing a decision tree. Instead of showing what to do with a set of inputs, I want to be able to balance the output to zero if the inputs are out of balance. It's probably best with an example...

A1 B1 C1 -2
A1 B2 C2 -2
A2 B2 C2 -1
A2 B3 C2 -1
A2 B4 C3 -1
A3 B3 C2 -1
A3 B4 C2 -1
A3 B5 C3 -1
A4 B1 C1 -1
A4 B2 C2 0

Logically, to balance everything to zero, it's easy to see that you need to do the following:

+2 for any input with A1
+1 for any input with A2
+1 for any input with A3
+1 for any input with A4 AND B1

This is much easier than going line by line and balancing it without simplifying each expression.

The real problem comes in when there's hundreds of lines, with up to 15-20 inputs. It would take a regular person days to figure it out, compared to writing a macro which would do it much faster.

I don't even know where to start, or how to start coding this to have the computer figure it out. Does anyone have any suggestions on what to do? Any help is greatly appreciated.

Thanks!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I may be missing the complexity in this, so forgive me if this answer doesn't suit your needs, but it seems as though you have already have a calculation to give you your results in column D above (where you have -2, -2, -1...etc.

The equation to balance that result to 0 would simply be -N where N is the result. So, for example, if your result for the first row is -2, and that result is in cell D1, then in E1 your formula to balance is simply "=+-D1" (without the quotes).

Adding the opposite of your number will mean:

When it's 0, you're adding 0
When it's +2, you're adding -2
When it's -2, you're adding --2 (which is positive)
 
Upvote 0
I may be missing the complexity in this, so forgive me if this answer doesn't suit your needs, but it seems as though you have already have a calculation to give you your results in column D above (where you have -2, -2, -1...etc.

The equation to balance that result to 0 would simply be -N where N is the result. So, for example, if your result for the first row is -2, and that result is in cell D1, then in E1 your formula to balance is simply "=+-D1" (without the quotes).

Adding the opposite of your number will mean:

When it's 0, you're adding 0
When it's +2, you're adding -2
When it's -2, you're adding --2 (which is positive)


You've got the idea! That's exactly what I'm doing.

The issue with the complexity of it is when the example above could be to 1000 lines with inputs A through N... it can get complex quickly. I'm looking to simplify the number of lines that would output to balance each line of the example.

So, instead of taking each line and balancing that (which would work because each line is unique), I'm looking to simplify the balances needed, since this needs to be checked manually. I'd rather not write hundreds of lines of balances when maybe 10-20 would do.

In the example, while we can do cross checks for each line, a simpler way to do it would be:

+2 for any input with A1
+1 for any input with A2
+1 for any input with A3
+1 for any input with A4 AND B1

While I could balance each line separately, this optimizes the amount of balances I have to do.

Does that help explain the problem?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top