I was just doing some Hackerrank for fun, in particular this one.

Basically, you can describe the problem as a sequence of recurrence relations, and they told you that the solution is in the form of a rational number. So far so good.

TLDR: If `M`

and `J`

are `Matrix{Rational{Int}}`

then `M\J`

is also `Matrix{Rational{Int}}`

! I found this amazing! Is Julia fairly unique in this aspect? I know Mathematica can probably do this too but I wonder if there are any others? This makes Julia really powerful

Long version: One way to solve a recurrence relation is of course to use matrices. So I build a `Matrix{Rational{Int}}`

that represents the recurrence relation and I just inverted it. The awesome thing was the inverse of `Matrix{Rational{Int}}`

is also `Matrix{Rational{Int}}`

and I just solved the whole system by doing `M\J`

where `M`

is the recurrence relations and `J`

is the RHS of the recurrence relations and the solution of `M\J`

is also `Matrix{Rational{Int}}`

! Amazing!

Unfortunately, Hackerrank doesn’t accept Julia solutions for this problem, but I’ve posted my solution in the comment.