// This is a logic puzzle. // // BOY + GIRL = LOVE // BOY - GIRL = ? // This makes the assumption that the none of the letters are zero, which // simplifies the permutation as we have exactly 9 variables. options = array[1 to 9] for [B, O, Y, G, I, R, L, V, E] = options.permute[] { if ((Y + L) mod 10 != E) next YLcarry = (Y + L) div 10 if ((O + R + YLcarry) mod 10 != V) next ORcarry = (O + R + YLcarry) div 10 if ((B + I + ORcarry) mod 10 != O) next BIcarry = (B + I + ORcarry) div 10 if (G + BIcarry != L) next // Display answers print["B=$B O=$O Y=$Y G=$G I=$I R=$R L=$L V=$V E=$E "] result = -eval["$B$O$Y - $G$I$R$L"] // Result is always negative so negate d = new dict[[[B, "B"], [O, "O"], [Y, "Y"], [G, "G"], [I, "I"], [R, "R"], [L, "L"], [V, "V"], [E, "E"]]] for c = integerDigits[result] print[d@c] println[] }