I recently solved a coding challenge in one of the challenge papers that my IT teacher gave to us. It was a seemingly simple, but fun challenge, so I thought it will make fun golfing.
The task
Given an input of a 2x2 matrix that contains 4 strictly positive integers (i.e. non-negative and non-zero), like this:
$$\begin{pmatrix}a&b\\c&d\end{pmatrix}$$
We call the value of the matrix given is \$\left\lfloor\dfrac{a}{c}\right\rfloor - \left\lfloor\dfrac{b}{d}\right\rfloor\$.
Your task is to calculate the amount of rotation needed to get the maximum value of the matrix.
A rotation rotates the matrix 90 degrees clockwise.
Input and Output
The input can be a 2x2 matrix (as shown above), a flattened list [a b c d]
, or any other reasonable input.
Note that with the case of flattened lists, the numbers can be in any order you preferred. (e.g. [a b d c]
).
The output must show a number that is the amount of rotation required.
Clarifications
In case of a tie, we will choose the one with the least amount of rotation needed.
In case where no rotation is required, we simply output
0
or4
(the maximal rotation).The division used here is integer division (i.e. the result of the division will always be an integer).
Examples
[a b c d] -> output
[1 2 3 4] -> 3
[5 7 9 2] -> 1
[5 6 7 8] -> 0 or 4
[1 9 2 3] -> 3
[2 5 6 8] -> 3
These examples are hand-calculated and written, so correct me if I'm wrong!
As always, standard loopholes are forbidden.
0
in the denominator? \$\endgroup\$[5 6 7 8]
be3
? \$\endgroup\$