4 ms·
Both this and the Mathematica solution linked below [1] are brute force, which strikes me as far less interesting than using linear programming. Of course, at t
by StefanKarpinski 13y ago
Both this and the Mathematica solution linked below [1] are brute force, which strikes me as far less interesting than using linear programming. Of course, at this size of problem brute force works fine. You can write a brute force version easily in any language, including, of course, Julia:
julia> function brute_force(P,t)
for x1=P[1,:], x2=P[2,:], x3=P[3,:], x4=P[4,:], x5=P[5,:], x6=P[6,:]
x1 + x2 + x3 + x4 + x5 + x6 == t || continue
println("solution: $x1 $x2 $x3 $x4 $x5 $x6")
end
end
brute_force (generic function with 1 method)
julia> brute_force(P,419)
solution: 90 68 91 66 41 63
solution: 90 48 91 66 41 83
solution: 90 64 67 66 49 83
solution: 88 68 91 40 49 83
The interesting thing about Iain's linear programming approach is that you can write the problem down the way it is defined and get a solution efficiently.
[1] https://news.ycombinator.com/item?id=6425633 https://news.ycombinator.com/item?id=6425633