in reply to Re: Boolean math: Fill in the blanks.
in thread Boolean math: Fill in the blanks.

Sorry, but it's not so simple. <s>& halves the number of 1's only if both expression are identical, same thing for |<s>.

In fact, if I'm right, your expression for 21 gives an average of 23 ones and the expression for 27 gives an average of 29.

Update: on second sight, your solution for 27 is equivalent to that given by BrowserUk for 29

Update: & doesn't half the number of 1's. The result is the product divided by 32, so it halves the number of 1's of an expression if and only if the other is R

Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

  • Comment on Re^2: Boolean math: Fill in the blanks.

Replies are listed 'Best First'.
Re^3: Boolean math: Fill in the blanks.
by hawtin (Prior) on Oct 10, 2008 at 11:21 UTC

    What I meant to convey is that if you replace all 0s with 1s and all & with | then you get the same result. If the operations are done in the same order then, I think my expression gives the results I have stated. The problem is that precedence is changing the way Perl combines the operators. When defining these expressions I should have put brackets round everything.