Build a solver for the monks and buns problem An old Chinese poem goes:


  一百饅頭一百僧，
  大僧三個更無爭，
  小僧三人分一個，
  大小和尚得幾丁？


When translated into English, this math problem reads:


  100 buns and 100 monks, 
  Big monks eat 3 buns with no shortage, 
  Little monks share one bun among three, 
  Big and little monks, how many are there?


Once again, like in the cow and chicken problem, there is no simple calculation you can perform. You need the power of systems of equations.

Your task is to build a program that takes the following inputs, all positive integers:


b, the number of buns.
m, the number of monks.
bl, the number of buns a big monk can eat.
ms, the number of small monks who share one bun.


and output l and s, the number of big monks and small monks respectively. ("L" stands for "large").

Again, this problem has various states of solvability, but this time around, only output something if there is a unique solution in the nonnegative integers.

The shortest code to do all of the above in any language wins.



The problem input of the poem is 100 100 3 3, and the solution is 25 75.
R: 81 characters

i=scan();p=combn(0:i[2],2);cat(p[,p[1,]+p[2,]==i[2]&amp;i[3]*p[1,]+p[2,]/i[4]==i[1]])


A brute force solver which takes all possible combinations of non-negative integers and subset the one corresponding to criteria.