I came up with this challenge independently, but it turns out to be the inverse to this challenge by Doorknob. As I really like his spec, I decided to steal large parts of it instead of cooking up my own explanations.
Given the abbreviation of one of the 32 points on the compass, print the corresponding degrees. Feel free to skip ahead to the table below if you're not interested in an explanation of the 32 points.
Here is the full compass:
Each direction is 11.25 (360 / 32) degrees farther than the previous. For example, N (north) is 0 degrees, NbE (north by east) is 11.25 degrees, NNE (north-northeast) is 22.5 degrees, etc.
In detail, the names are assigned as follows:
- 0 degrees is N, 90 degrees is E, 180 degrees is S, and 270 degrees is W. These are called cardinal directions.
- The halfway points between the cardinal directions are simply the cardinal directions they're between concatenated. N or S always go first, and W or E always are second. These are called ordinal directions. The ordinal and cardinal directions together form the principal winds.
- The halfway points between the principal winds are the directions they're between concatenated. Cardinal directions go first, ordinal second. These are called half winds.
- The halfway points between principal and half winds are the adjacent principal wind "by" the closest cardinal direction away from the principal wind. This is denoted with a
b. These are called quarter winds.
This results in the following chart:
# Degrees Abbrv. Name 1 0 N North 2 11.25 NbE North by east 3 22.5 NNE North-northeast 4 33.75 NEbN Northeast by north 5 45 NE Northeast 6 56.25 NEbE Northeast by east 7 67.5 ENE East-northeast 8 78.75 EbN East by north 9 90 E East 10 101.25 EbS East by south 11 112.5 ESE East-southeast 12 123.75 SEbE Southeast by east 13 135 SE Southeast 14 146.25 SEbS Southeast by south 15 157.5 SSE South-southeast 16 168.75 SbE South by east 17 180 S South 18 191.25 SbW South by west 19 202.5 SSW South-southwest 20 213.75 SWbS Southwest by south 21 225 SW Southwest 22 236.25 SWbW Southwest by west 23 247.5 WSW West-southwest 24 258.75 WbS West by south 25 270 W West 26 281.25 WbN West by north 27 292.5 WNW West-northwest 28 303.75 NWbW Northwest by west 29 315 NW Northwest 30 326.25 NWbN Northwest by north 31 337.5 NNW North-northwest 32 348.75 NbW North by west
Your task is to take as input one of the 32 abbreviations from the third column and output the corresponding degrees in the second column.
You may assume that input will always be exactly one of those 32 strings (and you may optionally but consistently expect a single trailing newline). Output should also be given exactly as listed above, although trailing zeroes are allowed. You may optionally output a single trailing newline.
You may write a program or function, taking input via STDIN (or closest alternative), command-line argument or function argument and outputting the result via STDOUT (or closest alternative), function return value or function (out) parameter.
This is code golf, so the shortest answer (in bytes) wins.