Enterprise Resource Planning Blog Posts by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
florian_soe
Product and Topic Expert
Product and Topic Expert
528

The Challenge

One of the most famous mathematical puzzles – it's more than a hundred years old – can be solved using SAP S/4HANA for advanced variant configuration (AVC).

We're discussing the "SEND + MORE = MONEY" puzzle, which falls under the category of verbal arithmetic, also known as alphametics, cryptarithms, or word addition (see Wikipedia for details).

send_more_money.png

 

The invention of this brainteaser is attributed to the English author and mathematician Henry Dudeney, who published it in "The Strand Magazine" in July 1924. Rumor has it that a student once used this calculation in a letter to his father to request financial support.

What you see here is a plain-vanilla addition, with the slight difference that the figures are letters. Different letters represent different figures in the way that two different letters never stand for the same digit. Leading zeros are not allowed.

But how can AVC help us in this regard? We'll use a configuration model with a constraint, and we'll try to figure out which restrictions are necessary to solve the problem with minimal effort. To this end, we'll conduct three experiments with different RESTRICTION parts in the constraint.

But first, let's see what we can find out with a bit of mental work:

  • As already stated, all letters mean different digits.
  • The carryover can never be greater than 1 because you need at least a sum of three one-digit numbers to get a carryover of 2. Let's assume that we add two digits and one carryover of 1: The maximum possible result is 9 + 9 + 1 = 19, resulting in a carryover of 1. The maximum in our situation is only 9 + 8 + 1 = 18, of course, as two different letters must have different number values.
  • Having said that, we can conclude that M = 1. Since M is itself a carryover and leading zeros are not allowed, other values do not apply.
  • Let's assume we have a carryover of 1 to add to S and M, then S + M  + 1 = S + 2 = 10 x M + O = 10 + O, equivalent to S – 8 = O. With a carryover of zero, we get S - 9 = O. As a result, S can only be 8 or 9.
  • Now, you can easily see that O must be zero: It can't be 1 because this would result in M = O = 1. Contradiction. Additionally, O can't be 2 or greater than 2, as the sum of S, M, and 1 can't be greater than 11. Of course, we also know now that S must be 9 and can't be 8.

Altogether, we get four different sets of restrictions :

  1. The addition itself
  2. No two letters have the same value.
  3. A carryover of zero or one is added to two digits added in each place of the place-value system, resulting in a number smaller than or equal to 9 (next carryover is zero), or greater than 9  (which would come with a new carryover of 1). This gives us a maximum of four different equations per place.
  4. The values M = 1, S = 9, and O = 0.

We can solve this puzzle with further logical considerations and by checking the remaining combinations. But let's see how much AVC can determine using only parts of these restrictions.

 

The Solution Using an AVC Configuration Model

Before conducting the three experiments, we need to build a model.

These are the preliminary steps to make this puzzle available in the simulation environment:

  1. Create a Class, for example, CL_SEND_MORE_MONEY, to contain the characteristics needed. The class type must be 300.
  2. Create characteristics for the class. You can use the letters S, E, N, D, M, O, R, and Y, plus the characteristics SEND, MORE, and MONEY. If one of the letters is already in use as a characteristic in your system, try alternatives like "S_". You can start creating a letter, for example, S, as a numeric characteristic with one character. Enter the digits from 0 to 9 as values. Then create E as a template using S. SEND, MORE, and MONEY are numeric characteristics with 4 or 5 characters.
  3. Create a simple configurable material (you may call it SEND_MORE_MONEY), using the class CL_SEND_MORE_MONEY for classification. Maintain a plant for the material.
  4. In the PMEVC (product modeling environment for variant configuration), enter the material, plant, and BOM application PP01 ("Production - General").
  5. Create a profile for the product, processing mode "Advanced Variant Configuration".
  6. Create a constraint net.
  7. Create a constraint. We use 'X' as an object variable in the editor code:
OBJECTS:

X IS_A (300)CL_SEND_MORE_MONEY.

The music is now within the restriction of the constraint (for details on the restriction, refer to the documentation here). Technically, we've got only one restriction, but we can combine several 'sub-restrictions' using the keyword AND, or a comma.

 

First Experiment

In our first experiment, we want to do without restriction C because this is the most cumbersome to write down. Using the others, our RESTRICTION part could look like this:

RESTRICTION:

* No. 1: The summation itself

(X.SEND = X.S*1000 + X.E*100 + X.N*10 + X.D)
AND
(X.MORE = X.M*1000 + X.O*100 + X.R*10 + X.E)
AND
(X.MONEY = X.M*10000 + X.O*1000 + X.N*100 + X.E*10 + X.Y)
AND
(X.SEND + X.MORE = X.MONEY),

* No. 2: All values must be unique.

(NOT (X.S = X.E) AND NOT (X.S = X.N) AND NOT (X.S = X.D) AND NOT (X.S =
X.M) AND NOT (X.S = X.O) AND NOT (X.S = X.R) AND NOT (X.S = X.Y))
AND
(NOT (X.E = X.N) AND NOT (X.E = X.D) AND NOT (X.E = X.M) AND NOT (X.E =
X.O) AND NOT (X.E = X.R) AND NOT (X.E = X.Y))
AND
(NOT (X.N = X.D) AND NOT (X.N = X.M) AND NOT (X.N = X.O) AND NOT (X.N =
X.R) AND NOT (X.N = X.Y))
AND
(NOT (X.D = X.M) AND NOT (X.D = X.O) AND NOT (X.D = X.R) AND NOT (X.D =
X.Y))
AND
(NOT (X.M = X.O) AND NOT (X.M = X.R) AND NOT (X.M = X.Y))
AND
(NOT (X.O = X.R) AND NOT (X.O = X.Y))
AND NOT (X.R = X.Y),

* No. 3: The value restrictions found by reasoning

(X.M = 1)
AND
(X.O = 0)
AND
(X.S = 9).

 

The second restriction may appear somewhat complicated at first glance. But note that we can't use syntax elements like FOR loops in the editor coding.

To ease our work with this second (sub-)restriction, we can use an LLM (large language model) and enter the following prompt:

# List:

X.S, X.E, X.N, X.D, X.M, X.O, X.R, X.Y

---

Build a list of all pairs from this list, disregarding the order of the elements. Mathematically, the number of these pairs is "8 choose 2". Connect all pairs using this syntax: NOT (X.S = X.E) AND NOT (X.S = X.N) AND NOT... This means you should create an uninterrupted string of all possible inequalities connected by the keyword "AND".

When the model is ready and in status "Released", let's push the Test button and see what happens in the simulation:

push_the_button.png

When we try different values for E, all values but 5 will result in an inconsistency:

eight_makes_inconsistent.png

 

status_inconsistent.png

 With E = 5, we get:

exp_1_e_eq_5.png

 status_released.png

This leaves us with three possible values for R: 3, 4, and 8 (keeping in mind the uniqueness restriction B). But we can tell from the value MORE = 1085 (the value is greyed out, leaving no alternative!) that only 8 works fine, so we've solved our puzzle:

9567_1085_10652.png

 (Note that, if you enter E = 5 right away or after reloading the configuration model, also the value for R = 8 is greyed out immediately.)

Let's try a different approach!

 

Second Experiment

In our second experiment, we drop D (values for M, S, and O) and use the following RESTRICTION (with No. 1 to 3 corresponding to A, B, and C from above):

RESTRICTION:

* No. 1: The summation itself

(X.SEND = X.S*1000 + X.E*100 + X.N*10 + X.D)
AND
(X.MORE = X.M*1000 + X.O*100 + X.R*10 + X.E)
AND
(X.MONEY = X.M*10000 + X.O*1000 + X.N*100 + X.E*10 + X.Y)
AND
(X.SEND + X.MORE = X.MONEY),

* No. 2: All values must be unique.

(NOT (X.S = X.E) AND NOT (X.S = X.N) AND NOT (X.S = X.D) AND NOT (X.S =
X.M) AND NOT (X.S = X.O) AND NOT (X.S = X.R) AND NOT (X.S = X.Y))
AND
(NOT (X.E = X.N) AND NOT (X.E = X.D) AND NOT (X.E = X.M) AND NOT (X.E =
X.O) AND NOT (X.E = X.R) AND NOT (X.E = X.Y))
AND
(NOT (X.N = X.D) AND NOT (X.N = X.M) AND NOT (X.N = X.O) AND NOT (X.N =
X.R) AND NOT (X.N = X.Y))
AND
(NOT (X.D = X.M) AND NOT (X.D = X.O) AND NOT (X.D = X.R) AND NOT (X.D =
X.Y))
AND
(NOT (X.M = X.O) AND NOT (X.M = X.R) AND NOT (X.M = X.Y))
AND
(NOT (X.O = X.R) AND NOT (X.O = X.Y))
AND NOT (X.R = X.Y),

* No. 3: The carryover restrictions

((X.D + X.E = X.Y) OR (X.D + X.E = X.Y + 10))
AND
((X.N + X.R = X.E) OR (X.N + X.R + 1 = X.E) OR (X.N + X.R = X.E + 10)
OR
(X.N + X.R + 1 = X.E + 10))
AND
((X.E + X.O = X.N) OR (X.E + X.O + 1 = X.N) OR (X.E + X.O = X.E + 10)
OR
(X.E + X.O + 1 = X.E + 10))
AND
((X.S + X.M = X.O + 10) OR (X.S + X.M + 1 = X.O + 10)).

We have a little more work to do now, trying out values (starting with S and then E), but in the end, the result is the same.

second_exp_9-5.png

 However, the winner in terms of saving human thinking energy is the next one: It uses only A) and B), and the relatively simple conclusion from D that M must be 1.

 

Third Experiment

The last experiment is the best in terms of its restrictions' efficiency, and this is its RESTRICTION part:

RESTRICTION:

* No. 1: The summation itself

(X.SEND = X.S*1000 + X.E*100 + X.N*10 + X.D)
AND
(X.MORE = X.M*1000 + X.O*100 + X.R*10 + X.E)
AND
(X.MONEY = X.M*10000 + X.O*1000 + X.N*100 + X.E*10 + X.Y)
AND
(X.SEND + X.MORE = X.MONEY),

* No. 2: All values must be unique.

(NOT (X.S = X.E) AND NOT (X.S = X.N) AND NOT (X.S = X.D) AND NOT (X.S =
X.M) AND NOT (X.S = X.O) AND NOT (X.S = X.R) AND NOT (X.S = X.Y))
AND
(NOT (X.E = X.N) AND NOT (X.E = X.D) AND NOT (X.E = X.M) AND NOT (X.E =
X.O) AND NOT (X.E = X.R) AND NOT (X.E = X.Y))
AND
(NOT (X.N = X.D) AND NOT (X.N = X.M) AND NOT (X.N = X.O) AND NOT (X.N =
X.R) AND NOT (X.N = X.Y))
AND
(NOT (X.D = X.M) AND NOT (X.D = X.O) AND NOT (X.D = X.R) AND NOT (X.D =
X.Y))
AND
(NOT (X.M = X.O) AND NOT (X.M = X.R) AND NOT (X.M = X.Y))
AND
(NOT (X.O = X.R) AND NOT (X.O = X.Y))
AND NOT (X.R = X.Y),

* No. 3: The value for M

(X.M = 1).

This appears to be very similar to our first experiment, except that the values for S and O are missing.

The only work to do with this example is to write down No. 1 (a no-brainer), have No. 2 generated by AI, and think a bit to get X.M = 1 (no leading zeros!). After this, you see that the values for S, M, and O have been fixed in the simulation, and you just need to figure out what E has to be.

Last_exp_wo_values.png

The effort is just the same as with the first experiment: AVC takes over the brainwork to get the values of S and O.

 And we already know that E = 5 does the trick:

5_does_the_trick.png

 That's it! In case you're reading this right after publishing, have a great end of the year 2025, and an even better start into 2026!