Box the compass: Difference between revisions

(10 intermediate revisions by 9 users not shown)
Line 473:
</pre>
=={{header|AppleScript}}==
===Functional===
 
OS X Yosemite onwards (uses Foundation classes for record handling etc)
 
Line 908:
32 354.37° North by west 北微西
1 354.38° North 北 </pre>
----
===Simpler alternative===
<syntaxhighlight lang="applescript">on degreesToCompassPoint(degrees)
set cardinals to {"north", "east", "south", "west"}
set idx to ((degrees / 11.25) as integer) mod 32
set qIdx to idx mod 8
if (qIdx = 0) then return cardinals's item (idx div 8 + 1)
set ns to cardinals's item (3 - (idx + 24) div 16 mod 2 * 2)
set ew to cardinals's item ((idx div 16 + 1) * 2)
if (idx mod 16 > 7) then set qIdx to 8 - qIdx
if (qIdx = 1) then return ns & " by " & ew
if (qIdx = 2) then return ns & "-" & ns & ew
if (qIdx = 3) then return ns & ew & " by " & ns
if (qIdx = 4) then return ns & ew
if (qIdx = 5) then return ns & ew & " by " & ew
if (qIdx = 6) then return ew & "-" & ns & ew
return ew & " by " & ns -- qIdx = 7.
end degreesToCompassPoint
 
on join(lst, delim)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to delim
set txt to lst as text
set AppleScript's text item delimiters to astid
return txt
end join
 
on task()
set output to {"", "Index Compass point Degrees"}
set inputs to {0.0, 16.87, 16.88, 33.75, 50.62, 50.63, 67.5, 84.37, 84.38, 101.25, 118.12, ¬
118.13, 135.0, 151.87, 151.88, 168.75, 185.62, 185.63, 202.5, 219.37, 219.38, 236.25, ¬
253.12, 253.13, 270.0, 286.87, 286.88, 303.75, 320.62, 320.63, 337.5, 354.37, 354.38}
repeat with i from 1 to (count inputs)
set degrees to inputs's item i
set cpid to (degreesToCompassPoint(degrees))'s id
set cpid's first item to (cpid's beginning) mod 32 + 64
set compassPoint to string id cpid
set degrees to degrees as text
set entry to {text -2 thru -1 of (space & ((i - 1) mod 32 + 1)), ¬
text 1 thru 18 of (compassPoint & " "), ¬
text (offset of "." in degrees) thru end of (" " & degrees)}
set end of output to join(entry, " ")
end repeat
join(output, linefeed)
end task
 
task()</syntaxhighlight>
 
{{output}}
<syntaxhighlight lang="applescript">"
Index Compass point Degrees
1 North 0.0
2 North by east 16.87
3 North-northeast 16.88
4 Northeast by north 33.75
5 Northeast 50.62
6 Northeast by east 50.63
7 East-northeast 67.5
8 East by north 84.37
9 East 84.38
10 East by south 101.25
11 East-southeast 118.12
12 Southeast by east 118.13
13 Southeast 135.0
14 Southeast by south 151.87
15 South-southeast 151.88
16 South by east 168.75
17 South 185.62
18 South by west 185.63
19 South-southwest 202.5
20 Southwest by south 219.37
21 Southwest 219.38
22 Southwest by west 236.25
23 West-southwest 253.12
24 West by south 253.13
25 West 270.0
26 West by north 286.87
27 West-northwest 286.88
28 Northwest by west 303.75
29 Northwest 320.62
30 Northwest by north 320.63
31 North-northwest 337.5
32 North by west 354.37
1 North 354.38"</syntaxhighlight>
 
=={{header|AutoHotkey}}==
{{trans|C++}}
Line 1,173 ⟶ 1,259:
354.37 32 North by west
354.38 1 North</pre>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">100 dim names$(31)
110 restore 300
120 for c = 0 to ubound(names$)
130 read a$
140 names$(c) = a$
150 next c
160 dim degrees(32)
170 restore 380
180 for c = 0 to ubound(degrees)
190 read b
200 degrees(c) = b
210 next c
220 for i = 0 to ubound(degrees)
230 j = int((degrees(i)+5.625)/11.25)
240 if j > 31 then j = j-32
250 print using "####.##";degrees(i);
260 print using " ## ";j;
270 print names$(j)
280 next i
290 end
300 data "North","North by east","North-northeast","Northeast by north"
310 data "Northeast","Northeast by east","East-northeast","East by north"
320 data "East","East by south","East-southeast","Southeast by east"
330 data "Southeast","Southeast by south","South-southeast","South by east"
340 data "South","South by west","South-southwest","Southwest by south"
350 data "Southwest","Southwest by west","West-southwest","West by south"
360 data "West","West by north","West-northwest","Northwest by west","Northwest"
370 data "Northwest by north","North-northwest","North by west","North"
380 data 0,16.87,16.88,33.75,50.62,50.63,67.5,84.37,84.38,101.25
390 data 118.12,118.13,135,151.87,151.88,168.75,185.62,185.63,202.5,219.37
400 data 219.38,236.25,253.12,253.13,270,286.87,286.88,303.75,320.62,320.63
410 data 337.5,354.37,354.388</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|GW-BASIC}}===
{{works with|PC-BASIC|any}}
{{works with|BASICA}}
{{works with|Chipmunk Basic}}
{{works with|QBasic}}
{{works with|MSX BASIC}}
<syntaxhighlight lang="qbasic">100 dim n$(31)
110 restore 300
120 for c = 0 to 31
130 read a$
140 n$(c) = a$
150 next c
160 dim d(32)
170 restore 380
180 for c = 0 to 32
190 read b
200 d(c) = b
210 next c
220 for i = 0 to 32
230 j = int((d(i)+5.625)/11.25)
240 if j > 31 then j = j-32
250 print using "####.##";d(i);
260 print using " ## ";j;
270 print n$(j)
280 next i
290 end
300 data "North","North by east","North-northeast","Northeast by north"
310 data "Northeast","Northeast by east","East-northeast","East by north"
320 data "East","East by south","East-southeast","Southeast by east"
330 data "Southeast","Southeast by south","South-southeast","South by east"
340 data "South","South by west","South-southwest","Southwest by south"
350 data "Southwest","Southwest by west","West-southwest","West by south"
360 data "West","West by north","West-northwest","Northwest by west","Northwest"
370 data "Northwest by north","North-northwest","North by west","North"
380 data 0,16.87,16.88,33.75,50.62,50.63,67.5,84.37,84.38,101.25
390 data 118.12,118.13,135,151.87,151.88,168.75,185.62,185.63,202.5,219.37
400 data 219.38,236.25,253.12,253.13,270,286.87,286.88,303.75,320.62,320.63
410 data 337.5,354.37,354.38</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|Quite BASIC}}===
{{works with|BASICA}}
{{works with|Chipmunk Basic}}
<syntaxhighlight lang="qbasic">100 array n$
110 for c = 0 to 31
120 read a$
130 let n$(c) = a$
140 next c
150 array d
160 for c = 0 to 33
170 read b
180 let d(c) = b
190 next c
200 for i = 1 to 33
210 let j = int((d(i)+5.625)/11.25)
220 if j > 31 then let j = j-32
230 print d(i);" ";j;" ";n$(j)
240 next i
250 end
260 data "North","North by east","North-northeast","Northeast by north"
270 data "Northeast","Northeast by east","East-northeast","East by north"
280 data "East","East by south","East-southeast","Southeast by east"
290 data "Southeast","Southeast by south","South-southeast","South by east"
300 data "South","South by west","South-southwest","Southwest by south"
310 data "Southwest","Southwest by west","West-southwest","West by south"
320 data "West","West by north","West-northwest","Northwest by west","Northwest"
330 data "Northwest by north","North-northwest","North by west","North"
340 data 0,16.87,16.88,33.75,50.62,50.63,67.5,84.37,84.38,101.25
350 data 118.12,118.13,135,151.87,151.88,168.75,185.62,185.63,202.5,219.37
360 data 219.38,236.25,253.12,253.13,270,286.87,286.88,303.75,320.62,320.63
370 data 337.5,354.37,354.38</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
=={{header|Befunge}}==
<syntaxhighlight lang="befunge">>>::"}"9**\4+3%79*9*5-*79*9*5--+:5>>>06p:55+%68*+v
Line 1,789 ⟶ 1,992:
=={{header|Delphi}}==
See [https://rosettacode.org/wiki/Box_the_compass#Pascal Pascal].
=={{header|EasyLang}}==
{{trans|Kotlin}}
<syntaxhighlight>
func$ expand cp$ .
for c$ in strchars cp$
if c$ = "N"
r$ &= "north"
elif c$ = "E"
r$ &= "east"
elif c$ = "S"
r$ &= "south"
elif c$ = "W"
r$ &= "west"
elif c$ = "b"
r$ &= "by"
else
r$ &= "-"
.
.
h$ = strchar (strcode substr r$ 1 1 - 32)
return h$ & substr r$ 2 999
.
proc main . .
cp$[] = [ "N" "NbE" "N-NE" "NEbN" "NE" "NEbE" "E-NE" "EbN" "E" "EbS" "E-SE" "SEbE" "SE" "SEbS" "S-SE" "SbE" "S" "SbW" "S-SW" "SWbS" "SW" "SWbW" "W-SW" "WbS" "W" "WbN" "W-NW" "NWbW" "NW" "NWbN" "N-NW" "NbW" ]
print "Index Degrees Compass point"
print "----- ------- -------------"
for i = 0 to 32
ind = (i + 1) mod1 32
heading = i * 11.25
if i mod 3 = 1
heading += 5.62
elif i mod 3 = 2
heading -= 5.62
.
print ind & "\t" & heading & "\t" & expand cp$[ind]
.
.
main
</syntaxhighlight>
 
=={{header|Elixir}}==
{{trans|Ruby}}
Line 1,852 ⟶ 2,095:
1 North 354.38
</pre>
 
=={{header|Euphoria}}==
<syntaxhighlight lang="euphoria">constant names = {"North","North by east","North-northeast","Northeast by north",
Line 3,529 ⟶ 3,773:
=={{header|langur}}==
{{trans|D}}
{{works with|langur|0.6.13}}
<syntaxhighlight lang="langur">val .box = ["North", "North by east", "North-northeast", "Northeast by north",
"Northeast", "Northeast by east", "East-northeast", "East by north",
Line 3,549 ⟶ 3,792:
 
for .phi in .angles {
val .i = truncatetrunc(.phi x* 32 / 360 + 0.5) rem 32 + 1
writeln $"\{.i:5;} \{.phi:r2:6;} \{.box[.i];}"
}</syntaxhighlight>
 
Line 3,590 ⟶ 3,833:
1 354.38 North
</pre>
 
=={{header|Lasso}}==
<syntaxhighlight lang="lasso">define pointsarray() => {
Line 6,388 ⟶ 6,632:
=={{header|REXX}}==
This version does normalization of the (degree) heading and can also handle negative headings.
<syntaxhighlight lang="rexx">/*REXX program "boxes the compass" [from degree (º) headings ───► a 32 point set]. */
parse/* arg $ [from degree (º) headings ---> a 32 point set]. /*allow º headings to be specified.*/
Parse Arg degrees
if $='' then $= 0 16.87 16.88 33.75 50.62 50.63 67.5 84.37 84.38 101.25 118.12 118.13 ,
If degrees='' Then
135 151.87 151.88 168.75 185.62 185.63 202.5 219.37 219.38 236.25 ,
degrees=0 253.12 253.13 270 28616.87 28616.88 30333.75 32050.62 32050.63 33767.5 35484.37 35484.38 101.25,
118.12 118.13 135 151.87 151.88 168.75 185.62 185.63 202.5,
/* [↑] use default, they're in degrees*/
219.37 219.38 236.25 253.12 253.13 270 286.87 286.88 303.75,
@pts= 'n nbe n-ne nebn ne nebe e-ne ebn e ebs e-se sebe se sebs s-se sbe',
320.62 320.63 337.5 354.37 354.38
"s sbw s-sw swbs sw swbw w-sw wbs w wbn w-nw nwbw nw nwbn n-nw nbw"
names='n nbe n-ne nebn ne nebe e-ne ebn e ebs e-se sebe se sebs s-se sbe',
's sbw s-sw swbs sw swbw w-sw wbs w wbn w-nw nwbw nw nwbn n-nw nbw'
 
#nn= words(@ptsnames) + 1 /*# nn: used for integer ÷ remainder (//)*/
dirs= 'north south east west' /* define cardinal compass directions. */
/* [↓] choose a glyph for degree (°).*/
ifIf 4=='f4'x Then then degSym= "a1"x /* is this system an EBCDIC system? */
degsym='a1'x
else degSym= "a7"x /*'f8'x is the degree symbol: ° vs º */
Else
/*──────────────────────────── f8 vs a7*/
degsym='f8'x /* or degsym='a7'x */
say right(degSym'heading', 30) center("compass heading", 20)
saySay right( degsym'════════heading', 30) copiescenter('compass "═"heading', 20)
Say right('--------',30) copies('-',20)
pad= ' ' /*used to interject a blank for output.*/
pad=' ' do j=1 for words($); x= word($, j) /*obtain oneused ofto theinterject degreea blank for headings.o */
Do i=1 To words(degrees)
say right( format(x, , 2)degSym, 30-1) pad boxHeading(x)
x=word(degrees,i) end /*j obtain one of the degree headings */
Say right(format(x,,2)degsym,30-1) pad boxheading(x)
exit /*stick a fork in it, we're all done. */
End
/*──────────────────────────────────────────────────────────────────────────────────────*/
Exit /* stick a fork in it, we're all done*/
boxHeading: y= arg(1)//360; if y<0 then y=360-y /*normalize heading within unit circle.*/
/*---------------------------------------------------------------------*/
z= word(@pts, trunc(max(1, (y/11.25 +1.5) // #))) /*convert degrees─►heading*/
boxheading:
do k=1 for words(dirs); d= word(dirs, k)
y=arg(1)//360
z= changestr( left(d, 1), z, d)
If y<0 Then
end /*k*/ /* [↑] old, haystack, new*/
y=360-y return changestr('b', z, " by ") /*expand normalize "b"heading ───►within "unit bycircle ".*/</syntaxhighlight>
z=word(names,trunc(max(1,(y/11.25+1.5)//nn))) /* degrees->heading */
/* n e s w are now replaced by north east south west, respectively */
Do k=1 To words(dirs)
d=word(dirs,k)
z=changestr(left(d,1),z,d)
End
Return changestr('b',z,' by ') /* expand 'b' ---? ' by '. */</syntaxhighlight>
Some older REXXes don't have a &nbsp; '''changestr''' &nbsp; BIF, &nbsp; so one is included here &nbsp; ──► &nbsp; [[CHANGESTR.REX]].
<br><br>
{{out}}
'''output'''
<pre>
ºheading compass heading
Line 6,457 ⟶ 6,710:
354.38º north
</pre>
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
Line 6,525 ⟶ 6,779:
354.38 0 North
</pre>
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.9}}
{| class="wikitable" ≪
! RPL code
! Comment
|-
|
≪ { "north" "east" "south" "west" }
SWAP 8 / IP 1 + GET
LAST 1 + DUP 5 ≠ SWAP 1 IFTE GET
≫ '<span style="color:blue">I→QDT</span>' STO
≪ → pattern a b
≪ "" 1 pattern SIZE '''FOR''' j
pattern j DUP SUB
DUP "X" == a ROT DUP "Y" == b ROT IFTE IFTE
+ '''NEXT'''
≫ ≫ '<span style="color:blue">FILLXY</span>' STO
11.25 / 0.5 + FLOOR 32 MOD
{ "X" "X by Y" "X-XY" "XY by X"
"XY" "XY by Y" "Y-XY" "Y by X" "Y" }
OVER 8 MOD 1 + GET SWAP <span style="color:blue">I→QDT</span> <span style="color:blue">FILLXY</span>
≫ '<span style="color:blue">→HDG</span>' STO
|
<span style="color:blue">I→QDT</span> ''( index → "wind1" "wind2" )'' // index ∈ [0,31]
Get wind1
Get wind2
<span style="color:blue">FILLXY</span> ''( "pattern" "a" "b" → "string" ) ''
Initialize output string and loop
get jth character of pattern
replace "X" by "a" and "Y" by b
add to output string
<span style="color:blue">→HDG</span> ''( angle → "heading" )'' // angle in degreees
Convert angle into compass index
Naming patterns
Get pattern, get winds and convert into heading
|}
The demonstration has been limited to a few significant cases, due to the poor display capabilities of typical RPL devices (e.g. 4 x 22 characters on a HP-28S) :
≪ <span style="color:red">{ 0 16.87 16.88 33.75 50.62 354.37 354.38 } { } 1 3</span> PICK SIZE '''FOR''' j OVER j GET <span style="color:blue">→HDG</span> + '''NEXT''' SWAP DROP ≫ EVAL
 
{{out}}
<pre>
1: { "north" "north by east" "north-northeast" "northeast by north" "northeast" "north by west" "north" }
</pre>
 
=={{header|Ruby}}==
 
Line 6,586 ⟶ 6,895:
32 north by west 354.37
1 north 354.38</pre>
 
=={{header|Run BASIC}}==
<syntaxhighlight lang="runbasic">global direct$
Line 6,990 ⟶ 7,300:
32 North by west NbW 343.13 348.75 354.37
</pre>
=={{header|Swift}}==
Implementation:
<syntaxhighlight lang="swift">
import Foundation
 
extension Double {
var nearestQr: Double {(self * 4.0).rounded(.toNearestOrAwayFromZero) / 4.0}
}
 
extension Measurement<UnitAngle>/*: ExpressibleByFloatLiteral*/ {
var cos: Double { Darwin.cos(self.converted(to: .radians).value) }
var sin: Double { Darwin.sin(self.converted(to: .radians).value) }
}
 
struct Compass {
var bearing: Measurement<UnitAngle>
var style: Style = .RN
init(_ deg: Double, _ min: Double = 0, _ sec: Double = 0, style: Style = .RN
) {
self.bearing = .init(value: deg + min/60.0 + sec/360.0, unit: .degrees)
self.style = style
}
static func degreesToPoints(_ deg: Double) -> Double {
(deg/360 * 32).nearestQr
}
var point: Double {
Self.degreesToPoints(self.bearing.value)
}
var quad: (String,String) {
(bearing.cos < 0 ? "S" : "N", bearing.sin < 0 ? "W" : "E")
}
var step: (Int,Double) {
let temp = 8 - abs(abs(self.point - 16) - 8)
return (Int(temp),temp.truncatingRemainder(dividingBy: 1))
}
enum Style {case RN, USN, noBy}
var formats = ["N", "NxE", "NNE", "NExN", "NE", "NExE", "ENE", "ExN", "E"]
let fractions = ["¼","½","¾"]
var invertedPoints: [Int] {
switch self.style {
case .RN: [3,6,7]
case .USN: [3,7]
case .noBy: [1,5,7]
}
}
 
func named() -> String {
var (pt,frac) = self.step
var fracStr: String = ""
if frac != 0.0 {
if invertedPoints.contains(pt) {
pt += 1
fracStr = fractions.reversed()[Int(frac * 4) - 1] + "N"
} else {
fracStr = fractions[Int(frac * 4) - 1] + "E"
}
}
return (self.formats[pt] + fracStr)
.replacing(/(N|E)/) { $0.output.0 == "N" ? self.quad.0 : self.quad.1 }
.replacing(/x/) {_ in "by"}
}
}
</syntaxhighlight>
Execution:
<syntaxhighlight lang="swift">
let arr = [
000.00, 016.87, 016.88, 033.75, 050.62, 050.63, 067.50, 084.37, 084.38,
090.00, 101.25, 118.12, 118.13, 135.00, 151.87, 151.88, 168.75, 185.62,
185.63, 202.50, 219.37, 219.38, 236.25, 253.12, 253.13, 270.00, 286.87,
286.88, 303.75, 320.62, 320.63, 337.50, 354.37, 354.38
]
 
let arr2 = stride(from: 0, through: 360, by: 22.5/8.0)
 
let pointFormatter = NumberFormatter()
pointFormatter.minimumIntegerDigits = 2
pointFormatter.minimumFractionDigits = 2
 
for d in arr {
let c = Compass(d, style: .RN)
print(pointFormatter.string(from: c.point as NSNumber)!, c.dms , c.named())
}
</syntaxhighlight>
Result:
<pre>
00.00 000°00'00" N
01.50 016°52'12" NbyE½E
01.50 016°52'47" NbyE½E
03.00 033°45'00" NEbyN
04.50 050°37'11" NE½E
04.50 050°37'48" NE½E
06.00 067°30'00" ENE
07.50 084°22'12" E½N
07.50 084°22'47" E½N
08.00 090°00'00" E
09.00 101°15'00" EbyS
10.50 118°07'12" SEbyE½E
10.50 118°07'47" SEbyE½E
12.00 135°00'00" SE
13.50 151°52'12" SSE½E
13.50 151°52'47" SSE½E
15.00 168°45'00" SbyE
16.50 185°37'12" S½W
16.50 185°37'47" S½W
18.00 202°30'00" SSW
19.50 219°22'12" SW½S
19.50 219°22'47" SW½S
21.00 236°15'00" SWbyW
22.50 253°07'12" WbyS½S
22.50 253°07'47" WbyS½S
24.00 270°00'00" W
25.50 286°52'12" WbyN½N
25.50 286°52'47" WbyN½N
27.00 303°45'00" NWbyW
28.50 320°37'12" NW½N
28.50 320°37'47" NW½N
30.00 337°30'00" NNW
31.50 354°22'12" N½W
31.50 354°22'47" N½W
</pre>
 
=={{header|Tcl}}==
<syntaxhighlight lang="tcl">proc angle2compass {angle} {
Line 7,433 ⟶ 7,864:
{{trans|Go}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
// 'cpx' returns integer index from 0 to 31 corresponding to compass point.
Line 7,496 ⟶ 7,927:
var index = i%32 + 1 // printable index computed per pseudocode
var d = degreesToCompassPoint.call(h)
SystemFmt.print("%(Fmt.d(4,$4d index)) $-19s %(Fmt$7.s(-192f°", index, d)) %(Fmt.f(7, h,) 2))°")
i = i + 1
}</syntaxhighlight>
Line 7,650 ⟶ 8,081:
80 data "Northwest by west ", "Northwest ", "Northwest by north", "North-northwest "
90 data "North by west "</syntaxhighlight>
 
=={{header|Zig}}==
{{works with|Zig|0.11.0}}
<syntaxhighlight lang="zig">const std = @import("std");</syntaxhighlight>
<syntaxhighlight lang="zig">/// Degrees is not constrained to the range 0 to 360
fn degreesToCompassPoint(degrees: f32) []const u8 {
var d = degrees + comptime (11.25 / 2.0);
while (d < 0) d += 360;
while (d >= 360) d -= 360;
const index: usize = @intFromFloat(@divFloor(d, 11.25));
 
const points: [32][]const u8 = comptime .{
"North", "North by east", "North-northeast", "Northeast by north",
"Northeast", "Northeast by east", "East-northeast", "East by north",
"East", "East by south", "East-southeast", "Southeast by east",
"Southeast", "Southeast by south", "South-southeast", "South by east",
"South", "South by west", "South-southwest", "Southwest by south",
"Southwest", "Southwest by west", "West-southwest", "West by south",
"West", "West by north", "West-northwest", "Northwest by west",
"Northwest", "Northwest by north", "North-northwest", "North by west",
};
 
return points[index];
}</syntaxhighlight>
<syntaxhighlight lang="zig">pub fn main() anyerror!void {
const stdout = std.io.getStdOut().writer();
 
try stdout.print("Index Heading Compass point\n", .{});
 
for (0..33) |i| {
var heading = @as(f32, @floatFromInt(i)) * 11.25;
heading += switch (i % 3) {
1 => 5.62,
2 => -5.62,
else => 0,
};
const index = i % 32 + 1;
try stdout.print(" {d:2} {d:>6.2}° {s}\n", .{ index, heading, degreesToCompassPoint(heading) });
}
}</syntaxhighlight>
{{out}}
<pre>Index Heading Compass point
1 0.00° North
2 16.87° North by east
3 16.88° Northeast
...
31 337.50° Northwest
32 354.37° North by west
1 354.38° North</pre>
 
=={{header|zkl}}==
{{trans|AWK}}
885

edits