Solving less-than inequalities with positive integers
Pyth, 39 bytes
V>1f.A<MxMLTN.pS{s=Nm%2cd).zVNjd[H\==hZ
Try it online: Demonstration
Brute-forces through all possible permutations (and interpret them as sortings), check if they match the inequalities, and assign them the values 1, 2, ...., n
.
Explanation
f.A<MxMLTN.pS{s=Nm%2cd).z
m .z map each input line d to:
cd) split d by spaces
%2 and remove the second element
=N save this list of pairs to N
s combine these pairs to a big list of variable names
{ set (remove duplicates)
.pS generate all permutations
f filter for permutations T, which satisfy:
xMLTN replace each variable in N by their index in T
.A<M check if each pair is ascending
V>1...VNjd[H\==hZ implicit: Z = 0
>1 remove all but the last filtered permutation (if any)
V for each permutation N in ^ (runs zero times or once):
VN for each variable H in N:
[ generate a list containing:
H H
\= "="
=hZ Z incremented by 1 (and update Z)
jd join this list by spaces and print
CJam (53 52 49 bytes)
qS-N/'<f/:A:|e!{A{1$1$&=!},!*},:ee{()" = "\N}f%1<
Online demo
This brute-forces all permutations of the distinct tokens, filtering for those assignments of the numbers 0
to n-1
which obey all of the constraints, and then formats them, incrementing the numbers, and presents the first one. This is certain to find a solution if there is one, because it's essentially a topological sort.
Thanks to Reto Koradi for 3 chars and Martin Büttner for 1.
Mathematica, 83 bytes
Quiet@Check[Equal@@@FindInstance[Join[#,#>0&/@(v=Sequence@@@#)],v,Integers][[1]],]&
Takes input as a list of inequalities. Either outputs a list of assignments or Null
if it is impossible.