So it is possible to solve such equations by putting them in a matrix and using
Gaussian elimination. In your above example, you'd represent the equations as a matrix:
# a | b | result
# ----|-----|---------
# 1 | 0 | 6 (a = 6)
# -1 | 3 | 0 (0 = -a + 3b)
Basically each column corresponds to a variable's coefficients, and each row corresponds to an equation. You want to reduce your matrix to
reduced row echelon form, by adding or subtracting different rows together. If you add the first row to the second row, you get the following:
# a | b | result
# ----|-----|---------
# 1 | 0 | 6 (a = 6)
# 0 | 3 | 6 (3b = 6)
We can then divide the second row by 3 (or more generally, the value in the second column) to get the "solution":
# a | b | result
# ----|-----|---------
# 1 | 0 | 6 (a = 6)
# 0 | 1 | 2 (b = 2)
The Gaussian Elimination wikipedia page has some
pseudocode for an algorithmic way to reduce your matrix. You may also wish to look at Urn's
implementation of such an algorithm.
Note, if you're trying to save 10 minutes in your homework this isn't going to be super efficient. If you're just interested, I'd definitely recommend implementing something like this.