Box the compass: Difference between revisions

→‎{{header|Julia}}: Updated for Julia 1.2
(→‎{{header|Julia}}: Updated for Julia 1.2)
Line 3,012:
 
=={{header|Julia}}==
{{works with|Julia|01.62}}
{{trans|Python}}
 
<lang julia>functionusing degree2compasspoint(d::Float64)::StringPrintf
majors = ("north", "east", "south", "ovest", "north", "east", "south", "ovest")
quart1 = ("N", "N by E", "N-NE", "NE by N", "NE", "NE by E", "E-NE", "E by N")
 
function degree2compasspoint(d::Float64)
d = (d % 360) + 360/64
majors = ("north", "east", "south", "ovestwest", "north", "east", "south", "ovestwest")
majorindex, minor = divrem(d, 90)
quart1quarter1 = ("N", "N by E", "N-NE", "NE by N", "NE", "NE by E", "E-NE", "E by N")
minorindex = div(minor * 4, 45)
quarter2 = map(p -> replace(p, "NE" => "EN"), quarter1)
majorindex += 1
 
minorindex += 1
d = (d % 360) + 360 / 64
p1, p2 = majors[majorindex:majorindex+1]
majorindeximajor, minor = divrem(d, 90)
if p1 in ("north", "south"); q = quart1
else qiminor = quart1div(minor * 4, end45)
majorindeximajor += 1
return titlecase(replace(replace(q[minorindex], 'N', p1), 'E', p2))
minorindeximinor += 1
p1, p2 = majors[majorindeximajor:majorindeximajor+1]
ifq = p1 in ("north", "south"); q? =quarter1 : quart1quarter2
return titlecase(replace(replace(q[minorindeximinor], 'N', => p1), 'E', => p2))
end
 
for i in 0:32
d = i * 11.25
m = i % 3 == 1 && (d += 5.62)
ifi m% 3 == 1;2 && (d +-= 5.62 end)
@printf("%2i %-17s %10.2f°\n", ni % 32 + 1, degree2compasspoint(d), d)
if m == 2; d -= 5.62 end
n = i % 32 + 1
@printf("%2i %-17s %10.2f°\n", n, degree2compasspoint(d), d)
end</lang>
 
Line 3,042:
<pre> 1 North 0.00°
2 North By East 16.87°
3 North-northeastNortheast 16.88°
4 Northeast By North 33.75°
5 Northeast 50.62°
6 Northeast By East 50.63°
7 East-northeastNortheast 67.50°
8 East By North 84.37°
9 East 84.38°
10 East By South 101.25°
11 East-eastsouthSoutheast 118.12°
12 EastsouthSoutheast By East 118.13°
13 EastsouthSoutheast 135.00°
14 EastsouthSoutheast By South 151.87°
15 South-eastsouthSoutheast 151.88°
16 South By East 168.75°
17 South 185.62°
18 South By OvestWest 185.63°
19 South-southovestSouthwest 202.50°
20 SouthovestSouthwest By South 219.37°
21 SouthovestSouthwest 219.38°
22 SouthovestSouthwest By OvestWest 236.25°
23 OvestWest-southovestSouthwest 253.12°
24 OvestWest By South 253.13°
25 OvestWest 270.00°
26 OvestWest By North 286.87°
27 OvestWest-ovestnorthNorthwest 286.88°
28 OvestnorthNorthwest By OvestWest 303.75°
29 OvestnorthNorthwest 320.62°
30 OvestnorthNorthwest By North 320.63°
31 North-ovestnorthNorthwest 337.50°
32 North By OvestWest 354.37°
1 North 354.38°</pre>