---
title: "CSP and SWIM+WEAR=RELAX"
subject: "Artificial Intelligence"
chapter: 2
key: "semester_6/artificial_intelligence:csp-swim-wear-relax"
source: https://www.bctengineer.com/q/semester_6/artificial_intelligence/csp-swim-wear-relax
site: BCT Engineering
---

# CSP and SWIM+WEAR=RELAX

Artificial Intelligence · Chapter 2: Problem Solving

- Asked in: 2074 Bhadra, 1+6 marks
- Video: [L46: CryptArithmetic Problem in Artificial Intelligence | TO+GO = OUT & SEND+MORE= MONEY Solutions](https://www.youtube.com/watch?v=aZblDSAx4cg) — Easy Engineering Classes
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/artificial_intelligence/csp-swim-wear-relax
- Whole chapter: https://www.bctengineer.com/md/semester_6/artificial_intelligence/chapter-2

## Question

Define constraint satisfaction problem (CSP). Solve the following crypto-arithmetic problem, where different letters denote different integers and identical letters denote the same integer: SWIM + WEAR = RELAX.

## Short answer

CSP is variables with domains and constraints. Solving SWIM+WEAR=RELAX yields S=9, W=4, I=0, M=5, E=3, A=2, R=1, L=7, X=6; 9405+4321=13726. Note the puzzle is not unique; 16 assignments exist.

## Answer

#### Constraint satisfaction problem (CSP)
A CSP is a problem defined by a set of **variables**, a **domain** of possible values for each, and a set of **constraints** restricting the allowed combinations. Solving it means assigning values to all variables so that every constraint holds (e.g. map colouring, Sudoku, cryptarithmetic).

#### SWIM + WEAR = RELAX
Variables: S, W, I, M, E, A, R, L, X (9 letters); domain 0-9; all different; S, W, R non-zero.

```text
      S W I M
    + W E A R
    ---------
    R E L A X
```
Column equations (c1...c4 carries):
1. M + R = X + 10·c1
2. I + A + c1 = A + 10·c2  ⇒  I + c1 = 10·c2
3. W + E + c2 = L + 10·c3
4. S + W + c3 = E + 10·c4
5. R = c4

#### Solving
- **R = 1:** it is the carry into the fifth digit, so c4 = 1 and R = 1.
- **Column 2:** I + c1 = 10·c2. Either (c2 = 0, I = 0, c1 = 0) or (c2 = 1, I = 9, c1 = 1). The second option leads to no valid assignment (shown by exhaustive search), so take **I = 0, c1 = 0, c2 = 0**.
- **Column 1:** M + 1 = X (c1 = 0), so X = M + 1.
- **Column 3:** W + E = L + 10·c3; **Column 4:** S + W + c3 = E + 10.
- Try c3 = 0: W + E = L and S + W = E + 10.
  - Take S = 9, W = 4 ⇒ E = 3 (from 9 + 4 = E + 10) and L = 4 + 3 = 7.
  - Used digits so far: R = 1, I = 0, S = 9, W = 4, E = 3, L = 7. Remaining digits for A, M, X: {2, 5, 6, 8}.
  - X = M + 1 with both unused: M = 5, X = 6; then **A = 2**.
- All different ✓.

#### Verification
```text
      9 4 0 5
    + 4 3 2 1
    ---------
    1 3 7 2 6
```
9405 + 4321 = 13726 ✓

**Answer: S = 9, W = 4, I = 0, M = 5, E = 3, A = 2, R = 1, L = 7, X = 6.**

*Note:* a computer search finds 16 valid assignments, e.g. 7604 + 6321 = 13925; each satisfies all the constraints, so the puzzle is not unique.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Why is R = 1 in SWIM + WEAR = RELAX?
   A. R is the smallest letter
   B. R is the carry into the fifth digit, which can only be 1
   C. W = 1
   D. S = 1
   Answer: B. The leading digit of the 5-digit sum is a carry c4 = 1. (Key point: R = 1)

2. What does column 2 (I + A + c1 = A + 10*c2) simplify to?
   A. I = A
   B. I = c2
   C. I + c1 = 10*c2
   D. A = 10
   Answer: C. A cancels, leaving I + c1 = 10*c2. (Key point: Column 2)

3. Which option for column 2 is used in the solution?
   A. I = 9, c1 = 1, c2 = 1
   B. I = 1, c1 = 9
   C. I = 5, c1 = 5
   D. I = 0, c1 = 0, c2 = 0
   Answer: D. The I = 9 option leads to no valid assignment, so I = 0 is used. (Key point: Choosing I)

4. What is the verified sum?
   A. 9405 + 4321 = 13726
   B. 9450 + 4321 = 13771
   C. 9405 + 4312 = 13717
   D. 9504 + 4321 = 13825
   Answer: A. S=9, W=4, I=0, M=5, E=3, A=2, R=1, L=7, X=6. (Key point: Verification)

## Related in Artificial Intelligence

- [Cryptarithmetic LOGIC+LOGIC=PROLOG](https://www.bctengineer.com/question.md?key=semester_6%2Fartificial_intelligence%3Acryptarithmetic-logic-prolog) — Artificial Intelligence, chapter 2, asked 3×
- [Cryptarithmetic RIGHT+RIGHT=WRONG](https://www.bctengineer.com/question.md?key=semester_6%2Fartificial_intelligence%3Acryptarithmetic-right-right-wrong) — Artificial Intelligence, chapter 2, asked 3×
- [Cryptarithmetic WRONG+WRONG=RIGHT](https://www.bctengineer.com/question.md?key=semester_6%2Fartificial_intelligence%3Acryptarithmetic-wrong-wrong-right) — Artificial Intelligence, chapter 2
- [CSP and SEND+MORE=MONEY](https://www.bctengineer.com/question.md?key=semester_6%2Fartificial_intelligence%3Acsp-send-more-money) — Artificial Intelligence, chapter 2
- [AI, Turing test, CSP examples](https://www.bctengineer.com/question.md?key=semester_6%2Fartificial_intelligence%3Aturing-test-pass-csp-examples) — Artificial Intelligence, chapter 1
- [Problem space; BASE+BALL=GAMES](https://www.bctengineer.com/question.md?key=semester_6%2Fartificial_intelligence%3Aproblem-space-base-ball-games) — Artificial Intelligence, chapter 2

## Related in other subjects

- [Combining two identical radar transmitters](https://www.bctengineer.com/question.md?key=semester_7%2Frf_and_microwave_engineering%3Atwo-radar-transmitters-combining) — RF and Microwave Engineering, chapter 4, asked 2×
