Is This Matrix Invertible?
Redhill Chemicals blends two stock solutions into two finished products. The recipe table holds one row per product and one column per stock, and an entry says how much of that stock goes into a litre of that product. The plant sometimes needs the question backwards: given how much of each product was made, how much of each stock was drawn? That only works when the two recipes are genuinely different. If one recipe is a scaled copy of the other, the two products carry the same information and the stock amounts cannot be recovered. The figure that settles it is the table's determinant, and the blend is reversible exactly when that figure is not zero.
Task: Print the recipe table's determinant, then whether the blend can be run backwards.
Input
Two lines, each holding two numbers separated by a space — one row of the recipe table per line.
Output
Two lines. The first holds the determinant, signed, rounded to one decimal place. The second holds True if the blend can be run backwards and False if it cannot. Count a determinant landing within a billionth of zero as zero.
Example:
Input:
1 2
3 4
Output:
-2.0
True
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in