Introduction
Today's challenge is all about teeth. Specifically, how long it takes to brush from one tooth to another. Your challenge is, given the locations of two teeth, output the shortest amount of time possible to brush from the first to the second.
Challenge
For this challenge we will be using a layout of an average adult human mouth:
This diagram shows the widely used ISO numbering system. The system divides the mouth in four parts and assigns them each a number: upper right (1), upper left (2), lower left (3), and lower right (4). They then number the teeth of each section from the middle of the mouth out from 1-8. Therefore the fourth tooth from the center in the upper right side (section 1) is tooth number 14.
Let's assume brushing one tooth takes 1 unit of time. Moving from one tooth to the next one sideways takes 0 units of time. You can also cross from a tooth to the tooth directly above or below it, which also takes 1 unit of time. So how long does it take you to brush from tooth 14 to tooth 31? By looking at the diagram above, you will see it takes 7 units of time. Here is how that's calculated:
Action : Unit of time
Brushing tooth 14 : 1 unit
Brushing tooth 13 : 1 unit
Brushing tooth 12 : 1 unit
Brushing tooth 11 : 1 unit
Brushing tooth 21 : 1 unit
Cross to bottom of mouth : 1 unit
Brushing tooth 31 : 1 unit
------------------------------
Total: 7 units
Note his is not the only route we could have took, but there are no shorter routes.
So your challenge is:
- You will write a full program or function which accepts two arguments that are teeth numbers, and outputs (or returns) the shortest time to brush from one to the other.
- You make take input as numbers or strings, and output how ever you wish (within acceptable methods).
- Standard loopholes are forbidden by default.
- This question is code-golf, so shortest bytecount wins.
Here are some testcases (Thanks Jonathan Allan):
14, 21 => 5 14, 44 => 3 14, 14 => 1 33, 37 => 5
Good luck!