“...I've been working since 2008 with Ruby / Ruby on Rails, love a bit of Elixir / Phoenix and learning Rust. I also poke through other people's code and make PRs for OpenSource Ruby projects that sometimes make it. Currently working for InPay...”

Rob Lacey
Senior Software Engineer, UK

I don't normally do Python, but...

Needs must, as all the best cool kids are making Constraints Solvers in Python. Shall I rewrite Practical Python AI Projects: Mathematical Models of Optimization Problems in Ruby? Might be funs.

Anyway, Chapter 1 introduced a simple solver, but this is even simpler.

#!/usr/local/bin/python3
from __future__ import print_function
from ortools.linear_solver import pywraplp
t = 'WhatIsX'
s = pywraplp.Solver(t, pywraplp.Solver.GLOP_LINEAR_PROGRAMMING)
x = s.NumVar(0, 1000, 'x')
s.Add(x + 2*x + 3*x + 4*x == 10) # it's almost algebraic syntax
s.Solve()
print(x.SolutionValue())
view raw gistfile1.txt hosted with ❤ by GitHub