Box the compass: Difference between revisions

Content added Content deleted
m (→‎{{header|Visual Basic .NET}}: Changed GetPoint to use "Mod 32" instead of subtraction of 32.)
(J)
Line 81:
32 North by west 354.37°
1 North 354.38°</pre>
 
=={{header|J}}==
 
<lang j>require'strings'
cardinal=: ;:'N Ne E Se S Sw W Nw N' rplc;:'N North E East e east S South W West w west'
tween=:1 :'[,m,]'
by=:' by 'tween
points=:,2 ([;by;'-'tween;by~)&>/\ cardinal
deg2pnt=: points {~ 32 | 0.5 <.@+ %&11.25</lang>
 
As for the required example, sometimes it's simpler to do just a small bit of "extra" work:
 
<lang j> ((;@~."1@deg2pnt),.' ',.":)(_5.62 0 5.62 +/~11.25 * i.33)
North _5.62 0 5.62
North by Northeast 5.63 11.25 16.87
North-Northeast 16.88 22.5 28.12
Northeast by North 28.13 33.75 39.37
Northeast 39.38 45 50.62
Northeast by East 50.63 56.25 61.87
Northeast-East 61.88 67.5 73.12
East by Northeast 73.13 78.75 84.37
East 84.38 90 95.62
East by Southeast 95.63 101.25 106.87
East-Southeast 106.88 112.5 118.12
Southeast by East 118.13 123.75 129.37
Southeast 129.38 135 140.62
Southeast by South 140.63 146.25 151.87
Southeast-South 151.88 157.5 163.12
South by Southeast 163.13 168.75 174.37
South 174.38 180 185.62
South by Southwest 185.63 191.25 196.87
South-Southwest 196.88 202.5 208.12
Southwest by South 208.13 213.75 219.37
Southwest 219.38 225 230.62
Southwest by West 230.63 236.25 241.87
Southwest-West 241.88 247.5 253.12
West by Southwest 253.13 258.75 264.37
West 264.38 270 275.62
West by Northwest 275.63 281.25 286.87
West-Northwest 286.88 292.5 298.12
Northwest by West 298.13 303.75 309.37
Northwest 309.38 315 320.62
Northwest by North 320.63 326.25 331.87
Northwest-North 331.88 337.5 343.12
North by Northwest 343.13 348.75 354.37
North 354.38 360 365.62</lang>
 
Here, I compute the name for each of the numbers, and then find the unique set of names represented in each row (which is always only one name) and convert the whole thing to characters.
 
=={{header|Tcl}}==