# Linear equation with integer digits solution

**URL:** <https://discourse.julialang.org/t/linear-equation-with-integer-digits-solution/70479>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [October 27, 2021, 12:46pm UTC](https://discourse.julialang.org/t/linear-equation-with-integer-digits-solution/70479 "2021-10-27T12:46:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_Micsa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan_micsa/32/30233_2.png) [@Dan\_Micsa](https://discourse.julialang.org/u/Dan_Micsa)\
**Post date:** [October 27, 2021, 12:46pm UTC](https://discourse.julialang.org/t/linear-equation-with-integer-digits-solution/70479/1 "2021-10-27T12:46:57Z")

</div>

I’m new to Julia and I want tot solve this problem with integer, digits solutions:  
“Each letter represents a different non-zero digit: SEE + SEE = AXES”

I create this code and returns an inaccurate solution:

```julia
using JuMP, Clp

m = Model(Clp.Optimizer)

@variables m begin
    A
    X
    E
    S
end

#SEE + SEE = AXES
@constraints m begin
    2(100S + 10E + E) == 1000A + 100X + 10E + S
    A >= 1; A <=9
    X >= 1; X <=9
    E >= 1; E <=9
    S >= 1; S <=9
end

optimize!(m)

value.((A, X, E, S))

```

I can’t force proper the constrains. Any help is wellcomed!

---

<div class="post-metadata">

**Author:** ![Rudi79](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rudi79/32/3884_2.png) [@Rudi79](https://discourse.julialang.org/u/Rudi79)\
**Post date:** [October 27, 2021, 1:56pm UTC](https://discourse.julialang.org/t/linear-equation-with-integer-digits-solution/70479/2 "2021-10-27T13:56:05Z")

</div>

Do you have to use Clp? If not, this works:

```julia
using JuMP, GLPK

m = Model(GLPK.Optimizer)

@variables m begin
    A, Int
    X, Int
    E, Int
    S, Int
end

#SEE + SEE = AXES
@constraints m begin
    2(100S + 10E + E) == 1000A + 100X + 10E + S
    A >= 1; A <=9
    X >= 1; X <=9
    E >= 1; E <=9;
    S >= 1; S <=9; 
end

optimize!(m)

```

---

<div class="post-metadata">

**Author:** ![Dan\_Micsa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan_micsa/32/30233_2.png) [@Dan\_Micsa](https://discourse.julialang.org/u/Dan_Micsa)\
**Post date:** [October 27, 2021, 2:11pm UTC](https://discourse.julialang.org/t/linear-equation-with-integer-digits-solution/70479/3 "2021-10-27T14:11:37Z")

</div>

TYVM!

I don’t need any particular solver just to compare the code with Python and Sagemath. Julia beats them hands down!

---

<div class="post-metadata">

**Author:** ![Rudi79](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rudi79/32/3884_2.png) [@Rudi79](https://discourse.julialang.org/u/Rudi79)\
**Post date:** [October 27, 2021, 3:12pm UTC](https://discourse.julialang.org/t/linear-equation-with-integer-digits-solution/70479/4 "2021-10-27T15:12:15Z")

</div>

You are welcome. I am by no means an expert in this field, and cannot comment whether this is the best solution.  
The difference from you formulation ist, that the integer constraint is given in the variable definition.  
If you are interested the corresponding part in the docs can be found here:  
[https://jump.dev/JuMP.jl/dev/manual/variables/#Integer-constraints](https://jump.dev/JuMP.jl/dev/manual/variables/#Integer-constraints)  
The other problem was about your particular choice of solver.  
Not all of them can handle integer constraints. As interger linear programs are NP hard in general, solvers that can tackle this kind of problems are much more sophisticated.
