in reply to Re: Solver for the game "Set" matches three times (octal)
in thread Solver for the game "Set" matches three times

This might sound stupid, but what does      return ($a|$b|$c) eq ($a^$b^$c); do?

Replies are listed 'Best First'.
Re^3: Solver for the game "Set" matches three times (octal)
by ikegami (Patriarch) on Jul 17, 2008 at 00:46 UTC

    For each bit, ($a^$b^$c) returns

    • 1 if all three cards share the value represented by that bit (e.g. all three cards are green),
    • 0 if exactly two of three cards share the value represented by that bit (e.g. two of the three cards are green, and the one others isn't),
    • 1 if exactly one of three cards share the value represented by that bit (e.g. one of the three cards is green, and the two others aren't),
    • 0 if none of the three cards share the value represented by that bit (e.g. none of the cards are green).

    We want

    • 1 if all three cards share the value represented by that bit (e.g. all three cards are green),
    • 0 if exactly two of three cards share the value represented by that bit (e.g. two of the three cards are green, and the one others isn't),
    • 1 if exactly one of three cards share the value represented by that bit (e.g. one of the three cards is green, and the two others aren't),
    • 1 if none of the three cards share the value represented by that bit (e.g. none of the cards are green).

    ($a|$b|$c) eq serves that purpose and to "and" the results of every bit into a single boolean value.