It's a 90-degree triangle, so the Pythagorean Theorum comes into play:
c^2 = a^2 + b^2
Where C is the hypotenuse, A and B are the sides of the triangle (the 90-degree angle is between A and B). The shortest route is to go directly west, then directly north at 90-degrees, then the angled hypotenuse will reach back to the original point.
Ignore the kilometer units for now, because they're unimportant.
A = 5^2 = 25
B = 12^2 = 144
Now we need to isolate C in the theorum, which gives C = sqrt (A + B)
C = sqrt (25 + 144)
C = sqrt (169)
C = 13
add back in the units...
So Jim biked 13 kilometers.
He should have ordered his goods online and had them delivered. But that's how far he went, and how you figure it out.